Opened 16 years ago

Closed 16 years ago

#575 closed defect (fixed)

Unregistering from Windows IOCompletionPort (IOCP) ioqueue does not close the socket handle (thanks Gang Liu for the report)

Reported by: bennylp Owned by: bennylp
Priority: major Milestone: release-1.0-rc1
Component: pjlib Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported:

Description (last modified by bennylp)

The IOCP documentation says that application needs to call CloseHandle() to unregister the socket from the IOCP, and PJLIB does this in ioqueue_winnt.c.

We assumed that a call to CloseHandle() should close the socket (just like closesocket()), since a socket should just be another handle in Windows NT.

But 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.

Checking at MSDN documentation about CloseHandle() (see http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx), actually it does suggest application to call both for socket, i.e. always follow closesocket() call with CloseHandle(). This is what it says:

After closing a socket using the closesocket function, ensure that you release the socket by calling CloseHandle. For more information, see Socket Closure.

But alas! From experimentation, turns out that calling CloseHandle() after closesocket() will raise "Invalid handle" exception in debug mode. This was tested on WinXP SP2.

Change History (1)

comment:1 Changed 16 years ago by bennylp

  • Description modified (diff)
  • Priority changed from normal to major
  • Resolution set to fixed
  • Status changed from new to closed

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

Tested on WinXP SP2.

Note: See TracTickets for help on using tickets.