*/ DEVICE_CMD Close_Socket(REBREQ *sock) /* ** Close a socket. ** ** Returns 0 on success. ** On failure, error code is OS local. ** ***********************************************************************/ { sock->error = 0; if (GET_FLAG(sock->state, RSM_OPEN)) { sock->state = 0; // clear: RSM_OPEN, RSM_CONNECT // If DNS pending, abort it: if (sock->net.host_info) { // indicates DNS phase active #ifdef HAS_ASYNC_DNS if (sock->handle) WSACancelAsyncRequest(sock->handle); #endif OS_Free(sock->net.host_info); sock->socket = sock->length; // Restore TCP socket (see Lookup) } if (CLOSE_SOCKET(sock->socket)) { sock->error = GET_ERROR; return DR_ERROR; } } return DR_DONE; }
~SServerDNSRequest() { if (m_hDNSTask) WSACancelAsyncRequest(m_hDNSTask); delete m_pServer; POSITION pos = m_aPackets.GetHeadPosition(); while (pos) delete m_aPackets.GetNext(pos); }
/* * This routine is called to cancel a blocking hook call within * the Kerberos library. The need for this routine arises due * to bugs which exist in existing WINSOCK implementations. We * blocking gethostbyname with WSAASyncGetHostByName. In order * to cancel such an operation, this routine must be called. * Applications may call this routine in addition to calls to * WSACancelBlockingCall to get any sucy Async calls canceled. * Return values are as they would be for WSACancelAsyncRequest. */ int krb_cancel_blocking_call(void) { if (htaskasync == NULL) return 0; iscompleted = TRUE; return WSACancelAsyncRequest(htask); }
// ソケットを強制的に閉じる // ポストされたメッセージが残る可能性があるのでなるべくShutdown()を使う void CAsyncSocket::Close() { if (hGethost_) { WSACancelAsyncRequest(hGethost_); hGethost_ = NULL; } if (soc_ != INVALID_SOCKET) { closesocket(soc_); soc_ = INVALID_SOCKET; } bReady_ = false; bShutdown_ = false; }
CTCPClientSocketImpl::~CTCPClientSocketImpl ( void ) { assert ( m_iRefCount == 0 ); // Free our socket if ( m_Socket ) { closesocket ( m_Socket ); m_Socket = 0; } // Cancel active host resolving if ( m_bIsResolvingHost ) { WSACancelAsyncRequest ( m_pAsyncHostResolving ); m_bIsResolvingHost = false; } }
void CSock::Close() { if( IsValid() ) { shutdown(m_Sock, SD_BOTH); closesocket(m_Sock); // PostMessage(m_MsgWnd,WM_SOCKET_REMOVE,WPARAM(m_Sock),LPARAM(this)); m_Sock = INVALID_SOCKET; if( m_GetHostBuf ) delete []m_GetHostBuf; if( m_GetHostTask != INVALID_HANDLE_VALUE) { WSACancelAsyncRequest(m_GetHostTask); m_GetHostTask = INVALID_HANDLE_VALUE; } } }
*/ DEVICE_CMD Close_DNS(REBREQ *sock) /* ** Note: valid even if not open. ** ***********************************************************************/ { // Terminate a pending request: #ifdef HAS_ASYNC_DNS if (GET_FLAG(sock->flags, RRF_PENDING)) { CLR_FLAG(sock->flags, RRF_PENDING); if (sock->handle) WSACancelAsyncRequest(sock->handle); } #endif if (sock->net.host_info) OS_Free(sock->net.host_info); sock->net.host_info = 0; sock->handle = 0; SET_CLOSED(sock); return DR_DONE; // Removes it from device's pending list (if needed) }
/*--------------------------------------------------- close a socket ---------------------------------------------------*/ void SocketClose(HWND hwnd, const char *msgbuf) { // cancel task handle of WSAAsyncGetHostByName() if(g_hGetHost != NULL) WSACancelAsyncRequest(g_hGetHost); g_hGetHost = NULL; // free memory if(g_pGetHost) free(g_pGetHost); g_pGetHost = NULL; if(g_socket != -1) { // cancel request of notification WSAAsyncSelect(g_socket, hwnd, 0, 0); // close socket closesocket(g_socket); } g_socket = (SOCKET)-1; bSendingData = FALSE; if(msgbuf) Log(msgbuf); }
void NetworkStream_Win32::Cancel() { m_Mutex.Lock(); // Mark cancellation. m_State = STATE_CANCELLED; // If resolving, abort the resolve. if( m_hResolve != NULL ) { /* When we cancel the request, no message at all will be sent to the window, * so we need to do it ourself to inform it that it was cancelled. Be sure * to only do this on successful cancel. */ if( WSACancelAsyncRequest(m_hResolve) == 0 ) PostMessage( m_hResolveHwnd, WM_USER+1, 0, 0 ); } // Break out if we're waiting in WaitForCompletionOrCancellation(). SetEvent( m_hCompletionEvent ); m_Mutex.Unlock(); }
bool CTCPClientSocketImpl::Connect ( const char* szHost, unsigned short usPort ) { // Save the port m_usPort = usPort; // If we're already connected, disconnect if ( m_bIsConnected ) { Disconnect (); } // If we have active host resolving, cancel it if ( m_bIsResolvingHost ) { WSACancelAsyncRequest ( m_pAsyncHostResolving ); } // Got a socket? if ( !m_Socket ) { // No socket strcpy ( m_szLastError, "No socket initialized" ); return false; } // Start async resolving it m_pAsyncHostResolving = WSAAsyncGetHostByName ( CCore::GetSingleton ().GetHookedWindow (), WM_ASYNCTRAP + m_uiID + 256, szHost, m_pHostInfo, MAXGETHOSTSTRUCT ); if ( !m_pAsyncHostResolving ) { // Failed strcpy ( m_szLastError, "Unable to start resolving" ); return false; } m_bIsResolvingHost = true; return true; }
/*--------------------------------------------------- close the socket ---------------------------------------------------*/ void SocketClose(HWND hwndSNTP, const char *msgbuf) { if(!hwndSNTP) return; KillTimer(hwndSNTP, IDTIMER_MAIN); // cancel task handle of WSAAsyncGetHostByName() if(m_hGetHost != NULL) WSACancelAsyncRequest(m_hGetHost); m_hGetHost = NULL; // free memory if(m_pGetHost) free(m_pGetHost); m_pGetHost = NULL; if(m_socket != INVALID_SOCKET) { // cancel request of notification WSAAsyncSelect(m_socket, hwndSNTP, 0, 0); // close socket closesocket(m_socket); m_socket = INVALID_SOCKET; } if(msgbuf) Log(hwndSNTP, msgbuf); }
BOOL LLAsyncHostByName::cancelPendingRequest() { if( mCallback ) { mCallback( FALSE, mDomainName, 0, mUserdata ); } mUserdata = NULL; mCallback = NULL; if( mRequestHandle ) { S32 ret = WSACancelAsyncRequest( mRequestHandle ); if( SOCKET_ERROR == ret ) { llwarns << "LLAsyncHostByName::cancelPendingRequest() failed: " << WSAGetLastError() << llendl; return FALSE; } memset(mOutputBuffer, 0, sizeof( mOutputBuffer ) ); mRequestHandle = 0; return TRUE; } return FALSE; }
void CNetwork::Disconnect() { CSingleLock pLock( &m_pSection, TRUE ); if ( ! m_bEnabled ) return; theApp.Message( MSG_DEFAULT, _T("") ); theApp.Message( MSG_SYSTEM, IDS_NETWORK_DISCONNECTING ); m_bEnabled = FALSE; m_bAutoConnect = FALSE; m_tStartedConnecting = 0; Neighbours.Close(); pLock.Unlock(); if ( m_hThread != NULL ) { m_pWakeup.SetEvent(); int nAttempt = 10; for ( ; nAttempt > 0 ; nAttempt-- ) { DWORD nCode; if ( ! GetExitCodeThread( m_hThread, &nCode ) ) break; if ( nCode != STILL_ACTIVE ) break; Sleep( 100 ); } if ( nAttempt == 0 ) { TerminateThread( m_hThread, 0 ); theApp.Message( MSG_DEBUG, _T("WARNING: Terminating CNetwork thread.") ); Sleep( 100 ); } m_hThread = NULL; } Handshakes.Disconnect(); pLock.Lock(); Neighbours.Close(); Datagrams.Disconnect(); NodeRoute->Clear(); QueryRoute->Clear(); if ( TRUE ) { for ( POSITION pos = m_pLookups.GetStartPosition() ; pos ; ) { LPBYTE pAsync, pBuffer; m_pLookups.GetNextAssoc( pos, (VOID*&)pAsync, (VOID*&)pBuffer ); WSACancelAsyncRequest( (HANDLE)pAsync ); delete *(CString**)pBuffer; free( pBuffer ); } m_pLookups.RemoveAll(); } pLock.Unlock(); DiscoveryServices.Stop(); theApp.Message( MSG_SYSTEM, IDS_NETWORK_DISCONNECTED ); theApp.Message( MSG_DEFAULT, _T("") ); }
void delete_resolver_queries(const struct DNSQuery *query) { WSACancelAsyncRequest(query->handle); dlinkDelete(&query->node, &dns_queries); }
CMUSHclientDoc::~CMUSHclientDoc() { int i; // stop sounds playing, release sound buffers for (i = 0; i < MAX_SOUND_BUFFERS; i++) if (m_pDirectSoundSecondaryBuffer [i]) { DWORD iStatus; if (SUCCEEDED (m_pDirectSoundSecondaryBuffer [i]->GetStatus (&iStatus)) && (iStatus & DSBSTATUS_PLAYING)) m_pDirectSoundSecondaryBuffer [i]->Stop (); m_pDirectSoundSecondaryBuffer [i]->Release (); } if (m_pTimerWnd) { m_pTimerWnd->DestroyWindow(); delete m_pTimerWnd; m_pTimerWnd = NULL; } for (i = 0; i < 8; i++) delete m_font [i]; delete m_input_font; if (m_hNameLookup) WSACancelAsyncRequest (m_hNameLookup); // cancel host name lookup in progress delete [] m_pGetHostStruct; // delete buffer used by host name lookup delete m_MapFailureRegexp; // delete regexp structure for mapping failures if (m_pSocket) { ShutDownSocket (*m_pSocket); delete m_pSocket; m_pSocket = NULL; } if (m_pChatListenSocket) { ShutDownSocket (*m_pChatListenSocket); delete m_pChatListenSocket; m_pChatListenSocket = NULL; } // UDP listening sockets for (map<int, UDPsocket *>::iterator udpSocketIterator = m_UDPsocketMap.begin (); udpSocketIterator != m_UDPsocketMap.end (); udpSocketIterator++) delete udpSocketIterator->second; // delete chat sessions DELETE_LIST (m_ChatList); // delete plugins // we have to do it this way, because otherwise if a plugin attempts to access the // plugin list (eg. BroadcastPlugin, Trace) during the delete operation, then it // may call a plugin that was deleted a moment ago, but is still in the list. for (PluginListIterator pit = m_PluginList.begin (); pit != m_PluginList.end (); pit = m_PluginList.erase (pit)) // erase from list and get next one delete *pit; // delete *this* one CloseLog (); // this writes out the log file postamble as well // delete triggers DELETE_MAP (m_TriggerMap, CTrigger); // delete aliass DELETE_MAP (m_AliasMap, CAlias); // delete lines list DELETE_LIST (m_LineList); // delete timer map DELETE_MAP (m_TimerMap, CTimer); // delete variables map DELETE_MAP (m_VariableMap, CVariable); // delete Element map DELETE_MAP (m_CustomElementMap, CElement); // delete active tags list DELETE_LIST (m_ActiveTagList); // delete actions list DELETE_LIST (m_ActionList); // get rid of our positions array delete [] m_pLinePositions; // one less document gdoccount--; // update activity window App.m_bUpdateActivity = TRUE; // ****************** release scripting stuff DisableScripting (); if (!bWine) AfxOleUnlockApp(); // not needed? // free compression stuff if (m_CompressOutput) free (m_CompressOutput); if (m_CompressInput) free (m_CompressInput); // don't wrap up if not initialised if (m_bCompressInitOK) inflateEnd (&m_zCompress); // don't need to know what the configuration was any more DeleteConfigurationArrays (); // delete our arrays for (tStringMapOfMaps::iterator it = m_Arrays.begin (); it != m_Arrays.end (); it++) { tStringToStringMap * m = it->second; m->clear (); delete m; } // destroy accelerator table, if we had one if (m_accelerator) DestroyAcceleratorTable (m_accelerator); // if they loaded a special font, get rid of it RemoveSpecialFonts (); #ifdef PANE // get rid of owned panes safe_for_each (m_PaneMap.begin (), m_PaneMap.end (), closepane); #endif // PANE // delete MiniWindow map for (MiniWindowMapIterator mwit = m_MiniWindows.begin (); mwit != m_MiniWindows.end (); mwit++) delete mwit->second; m_MiniWindowsOrder.clear (); // delete databases for (tDatabaseMapIterator dbit = m_Databases.begin (); dbit != m_Databases.end (); dbit++) { if (dbit->second->pStmt) // finalize any outstanding statement sqlite3_finalize(dbit->second->pStmt); if (dbit->second->db) // and close the database sqlite3_close(dbit->second->db); delete dbit->second; // now delete memory used by it } } // end of CMUSHclientDoc::~CMUSHclientDoc