From 63ba5ff8c3c834b685b4e5f41833f77737008193 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 18 Jul 2008 10:33:09 +0000 Subject: Ticket #575: Unregistering from Windows IOCompletionPort (IOCP) ioqueue does not close the socket handle (thanks Gang Liu for the report) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2155 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/ioqueue_winnt.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'pjlib/src/pj/ioqueue_winnt.c') diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c index 82dcc057..a5618e36 100644 --- a/pjlib/src/pj/ioqueue_winnt.c +++ b/pjlib/src/pj/ioqueue_winnt.c @@ -786,7 +786,21 @@ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) * We also need to close handle to make sure that no further events * will come to the handle. */ - CloseHandle(key->hnd); + /* Update 2008/07/18 (http://trac.pjsip.org/repos/ticket/575): + * - It seems that CloseHandle() in itself does not actually close + * the socket (i.e. it will still appear in "netstat" output). Also + * if we only use CloseHandle(), an "Invalid Handle" exception will + * be raised in WSACleanup(). + * - MSDN documentation says that CloseHandle() must be called after + * closesocket() call (see + * http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx). + * But turns out that this will raise "Invalid Handle" exception + * in debug mode. + * So because of this, we replaced CloseHandle() with closesocket() + * instead. These was tested on WinXP SP2. + */ + //CloseHandle(key->hnd); + pj_sock_close((pj_sock_t)key->hnd); /* Reset callbacks */ key->cb.on_accept_complete = NULL; -- cgit v1.2.3