Problem closing connections on Windows and proposed solution

Jose found that the solution described in [1] for detecting closed sockets
on Windows has a problem. Has other people detected this and should we
apply this patch proposed by Jose?

Thanks,

Henrik

[1] http://lists.w3.org/Archives/Public/www-lib/1998AprJun/0045.html

***

Jose writes:

As you know, under Windows you need to register explicitly a close
event on the sockets to get it. You do so in HTHost.c:HTHost_register
as follows:

===================
#ifdef WWW_WIN_ASYNC
            event =  *(host->events+HTEvent_INDEX(HTEvent_CLOSE));
            HTEvent_register(HTChannel_socket(host->channel),
HTEvent_CLOSE, eve
nt);
#endif /* WWW_WIN_ASYNC */

=============

and then in HTEvtLst.c:AsyncWindowProc you have:
=======================
    switch (event) {
    case FD_READ: type = HTEvent_READ; break;
    case FD_WRITE: type = HTEvent_WRITE; break;
    case FD_ACCEPT: type = HTEvent_ACCEPT; break;
    case FD_CONNECT: type = HTEvent_CONNECT; break;
    case FD_OOB: type = HTEvent_OOB; break;
    case FD_CLOSE: type = HTEvent_CLOSE; break; 
    default: HTDebugBreak(__FILE__, __LINE__, "Unknown event %d\n", event);
    }
=============================

At least under Amaya, this doesn't seem to work. The FD_CLOSE event
should be tied to the FD_READ event to be able to detect those nice
HTTP connections where the server doesn't send the Content-Length. Try
it and you'll see you can't access sites such as www.netscape.com.

The solution I use for amaya is as follows (all in HTEvtLst.c):

In HTEventList_register, I always force the FD_CLOSE flag:

============================
ifdef WWW_WIN_ASYNC
        {
     /* JK: we always have to register FD_CLOSE under windows */
    long events = HTEvent_BITS (newset) | FD_CLOSE;
    if (WSAAsyncSelect(s, HTSocketWin, HTwinMsg, events) < 0) {
        if (THD_TRACE) HTTrace("Event....... WSAAsyncSelect returned error!");
        return HT_ERROR;
    }
        }
#else /* WWW_WIN_ASYNC */
==============================

And in AsyncWindowProc, I join FD_CLOSE and FD_READ:

=======================
    switch (event) {
    case FD_CLOSE:
    case FD_READ: type = HTEvent_READ; break;
    case FD_WRITE: type = HTEvent_WRITE; break;
    case FD_ACCEPT: type = HTEvent_ACCEPT; break;
    case FD_CONNECT: type = HTEvent_CONNECT; break;
    case FD_OOB: type = HTEvent_OOB; break;
    default: HTDebugBreak(__FILE__, __LINE__, "Unknown event %d\n", event);
    }
=============================

And finally, I removed the FD_CLOSE registration in HTHost.c

Received on Monday, 21 September 1998 11:11:54 UTC