SmartPtr< CSocket > CServerSocket::Accept( structAddr& addr ) { SOCKET s; SmartPtr< CSocket > sock; sockaddr_in sAddr; int len = sizeof(sAddr); hostent* hn; memset( &sAddr, 0, sizeof( sAddr ) ); SetConnected( true ); if( INVALID_SOCKET == ( s = ::accept( m_Socket, (sockaddr*)&sAddr, (socklen_t*)&len ) ) ) { SetConnected( false ); int iLastErr; if( WSAEINTR == ( iLastErr = WSAGetLastError() ) ) return sock; throw SocketErr( WSAGetLastError() ); }else { addr.iPort = ntohs( sAddr.sin_port ); addr.strAddr = ::inet_ntoa( sAddr.sin_addr ); if( NULL != ( hn = ::gethostbyaddr( (const char*)&sAddr.sin_addr.s_addr, sizeof( sAddr.sin_addr.s_addr ), m_iType ) ) ) { addr.strName = hn->h_name; } sock = SmartPtr< CSocket >( new CSocket( s, m_bBlocking, true ) ); } SetConnected( false ); return sock; }
void nsIMAPGenericParser::AdvanceToNextLine() { PR_FREEIF( fCurrentLine ); PR_FREEIF( fStartOfLineOfTokens); bool ok = GetNextLineForParser(&fCurrentLine); if (!ok) { SetConnected(false); fStartOfLineOfTokens = nsnull; fLineOfTokens = nsnull; fCurrentTokenPlaceHolder = nsnull; fAtEndOfLine = true; fNextToken = CRLF; } else if (!fCurrentLine) { HandleMemoryFailure(); } else { fNextToken = nsnull; // determine if there are any tokens (without calling AdvanceToNextToken); // otherwise we are already at end of line NS_ASSERTION(strlen(WHITESPACE) == 3, "assume 3 chars of whitespace"); char *firstToken = fCurrentLine; while (*firstToken && (*firstToken == WHITESPACE[0] || *firstToken == WHITESPACE[1] || *firstToken == WHITESPACE[2])) firstToken++; fAtEndOfLine = (*firstToken == '\0'); } }
BOOL CTcpClient::HandleConnect(SHORT events) { ASSERT(events & POLLOUT); int code = ::SSO_GetError(m_soClient); if(!IS_NO_ERROR(code) || (events & _POLL_ERROR_EVENTS)) { m_ccContext.Reset(TRUE, SO_CONNECT, code); return FALSE; } if(events & _POLL_HUNGUP_EVENTS) { m_ccContext.Reset(TRUE, SO_CONNECT, NO_ERROR); return FALSE; } SetConnected(); if(TRIGGER(FireConnect()) == HR_ERROR) { m_ccContext.Reset(FALSE); return FALSE; } return TRUE; }
int P4ClientAPI::ConnectOrReconnect() { if( IsTrackMode() ) client.SetProtocol( "track", "" ); Error e; ResetFlags(); client.Init( &e ); if ( e.Test() && exceptionLevel ) { return Except( "P4:connect()", &e ); } if ( e.Test() ) return 0; // If an iterator is defined, reset the break functionality // for the KeepAlive function if( ui.GetHandler() != LUA_NOREF ) { client.SetBreak( &ui ); } SetConnected(); lua_pushboolean( L, true ); return 1; }
bool CNetworkManager::Disconnect ( ) { // Check connection state. if ( IsConnected ( ) ) { // Disconnect from host. m_pRakPeer->CloseConnection(m_ServerAddress, true); //Usuwamy menad¿er pakietów. m_pPacketManager->Uninstall(); // Wywalamy zarz¹dzanie pakietemi. m_pRakPeer->DetachPlugin(m_pRPC4); // Shoutdown RakPeer m_pRakPeer->Shutdown(0); //Usuwamy interfejsy RakNet::RPC4::DestroyInstance(m_pRPC4); RakNet::RakPeerInterface::DestroyInstance(m_pRakPeer); // Ustalanie stanu po³¹czenia. SetConnected(false); return true; } return false; }
TCPClientSocket::TCPClientSocket(IPAddress &cServAddr, int iServPort) : TCPSocket((cServAddr.GetAddressFamily() == AF_INET6)) { Connect(cServAddr, iServPort); SetLocal(); SetConnected(); }
// Calls that CLIENT can make. bool wxTCPConnection::Disconnect () { if ( !GetConnected() ) return true; // Send the the disconnect message to the peer. m_codeco->Write8(IPC_DISCONNECT); m_sock->Notify(false); m_sock->Close(); SetConnected(false); return true; }
void CNetworkManager::ConnectionSuccess(RakNet::Packet *pPacket) { // Dodanie wiadomoœci o po³¹czeniu do czatu. g_pClient->GetChatbox()->AddDebugMessage("Po³¹czono pomyœlnie!"); // Ustalenie aktualnego adresu serwera SetServerAddress(pPacket->systemAddress); //Ustawianie informacji o stanie po³¹czenia. SetConnected(true); // Wys³anie pakietu z podstawowymi informacjami o graczu. RakNet::BitStream bitStream; bitStream.Write(m_pPlayerManager->GetLocalPlayer()->GetName().Get(), MAX_PLAYER_NAME); Call("Player_Connect", &bitStream, HIGH_PRIORITY, RELIABLE, 0, true); }
void ClientNet::Clear() { m_strIP.clear(); m_Sock = 0; m_bNagle = true; m_nPort = 0; SetConnected(false); SetTerminateConnect(false); SetTerminateSend(false); SetTerminateReceive(false); memset(m_szHostName, 0, sizeof(m_szHostName)); //bzero(m_szHostName, sizeof(m_szHostName)); }
void ClientNet::Destroy() { SetTerminateConnect(true); SetTerminateSend(true); SetTerminateReceive(true); pthread_join(m_hConnect, NULL); pthread_join(m_hSend, NULL); pthread_join(m_hReceive, NULL); if(IsConnected()) { GracefulCloseSocket(m_Sock, 20); } else { shutdown(m_Sock, 1); close(m_Sock); m_Sock = 0; } SetConnected(false); while (!m_pSendMsgQueue.empty()) { tagMsgData* pMsg = m_pSendMsgQueue.front(); free(pMsg->pBuff); delete pMsg; m_pSendMsgQueue.pop(); } while (!m_pRecvMsgQueue.empty()) { tagMsgData* pMsg = m_pRecvMsgQueue.front(); free(pMsg->pBuff); delete pMsg; m_pRecvMsgQueue.pop(); } pthread_mutex_destroy(&m_ConnectedMutex); pthread_mutex_destroy(&m_TerminateConnectMutex); pthread_mutex_destroy(&m_TerminateReceiveMutex); pthread_mutex_destroy(&m_TerminateSendMutex); }
bool UdpSocket::Open(SocketAddress& ad) { if (GetSocket() == INVALID_SOCKET) { Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp")); } if (GetSocket() != INVALID_SOCKET) { SetNonblocking(true); if (connect(GetSocket(), ad, ad) == -1) { Handler().LogError(this, "connect", Errno, StrError(Errno), LOG_LEVEL_FATAL); SetCloseAndDelete(); return false; } SetConnected(); return true; } return false; }
static void server_action(int action, struct socket_info *sinfo) { if (action == NET_READ) { if (getline(sinfo) == 1) parse_server(sinfo); return; } if (action == NET_WRITE) { if (IsConnecting(sinfo)) { NotConnecting(sinfo); SetConnected(sinfo); NotWriteable(sinfo); register_to_server(sinfo); } return; } }
BOOL CTcpClient::Stop() { if(!CheckStoping()) return FALSE; SetConnected(FALSE); WaitForWorkerThreadEnd(); if(m_ccContext.bFireOnClose) FireClose(m_ccContext.enOperation, m_ccContext.iErrorCode); if(m_soClient != INVALID_SOCKET) { shutdown(m_soClient, SHUT_WR); closesocket(m_soClient); m_soClient = INVALID_SOCKET; } Reset(); return TRUE; }
BOOL CTcpClient::ConnectToServer(const HP_SOCKADDR& addrRemote, BOOL bAsyncConnect) { BOOL isOK = FALSE; if(bAsyncConnect) { VERIFY(::fcntl_SETFL(m_soClient, O_NOATIME | O_NONBLOCK | O_CLOEXEC)); int rc = ::connect(m_soClient, addrRemote.Addr(), addrRemote.AddrSize()); if(IS_NO_ERROR(rc) || IS_IO_PENDING_ERROR()) { m_nEvents = POLLOUT; isOK = TRUE; } } else { if(::connect(m_soClient, addrRemote.Addr(), addrRemote.AddrSize()) != SOCKET_ERROR) { VERIFY(::fcntl_SETFL(m_soClient, O_NOATIME | O_NONBLOCK | O_CLOEXEC)); SetConnected(); if(TRIGGER(FireConnect()) == HR_ERROR) ::WSASetLastError(ENSURE_ERROR_CANCELLED); else { m_nEvents = (SHORT)((m_lsSend.IsEmpty() ? 0 : POLLOUT) | (m_bPaused ? 0 : POLLIN) | POLLRDHUP); isOK = TRUE; } } } return isOK; }
void nsIMAPGenericParser::HandleMemoryFailure() { SetConnected(false); }
void Stream::SetConnected() { return SetConnected(NULL); }