Changes between Initial Version and Version 1 of Ticket #575

Jul 18, 2008 10:46:54 AM (12 years ago)

Fixed in r2155. Now we just use closesocket() to replace CloseHandle() to unregister socket from IOCP.

Tested on WinXP SP2.


  • Ticket #575

    • Property Priority changed from normal to major
    • Property Status changed from new to closed
    • Property Resolution changed from to fixed
  • Ticket #575 – Description

    initial v1  
    1 In Windows, the {{{pj_ioqueue_unregister()}}} in IOCP ioqueue backend does not close the socket, causing it to still appear in "netstat" and further it causes assertion about invalid handle in WSACleanup(). 
     1The IOCP documentation says that application needs to call {{{CloseHandle()}}} to unregister the socket from the IOCP, and PJLIB does this in {{{ioqueue_winnt.c}}}.  
     3We assumed that a call to {{{CloseHandle()}}} should close the socket (just like {{{closesocket()}}}), since a socket should just be another handle in Windows NT. 
     5But turns out this is not the case. A call to {{{CloseHandle()}}} doesn't seem to close the socket, as the socket still appears in "netstat" output. Also further down it will cause "Invalid handle" exception to be raised in debug mode when {{{WSACleanup()}}} is called. 
     7Checking at MSDN documentation about {{{CloseHandle()}}} (see, actually it does suggest application to call both for socket, i.e. always follow {{{closesocket()}}} call with {{{CloseHandle()}}}. This is what it says: 
     9 ''After closing a socket using the closesocket function, ensure that you release the socket by calling !CloseHandle. For more information, see [ Socket Closure].'' 
     11But alas! From experimentation, turns out that calling {{{CloseHandle()}}} after {{{closesocket()}}} will raise "Invalid handle" exception in debug mode. This was tested on WinXP SP2.