bool ClientSession::PostSend() { if ( !IsConnected() ) { return false; } FastSpinlockGuard criticalSection(mBufferLock); if ( 0 == mBuffer.GetContiguiousBytes() ) { return true; } OverlappedSendContext* sendContext = new OverlappedSendContext(this); DWORD sendbytes = 0; DWORD flags = 0; sendContext->mWsaBuf.len = (ULONG) mBuffer.GetContiguiousBytes(); sendContext->mWsaBuf.buf = mBuffer.GetBufferStart(); /// start async send if (SOCKET_ERROR == WSASend(mSocket, &sendContext->mWsaBuf, 1, &sendbytes, flags, (LPWSAOVERLAPPED)sendContext, NULL)) { if (WSAGetLastError() != WSA_IO_PENDING) { DeleteIoContext(sendContext); printf_s("ClientSession::PostSend Error : %d\n", GetLastError()); return false; } } return true; }
int CFileZillaApi::MakeDir(const CServerPath &path) { //Check if call allowed if (!m_bInitialized) return FZ_REPLY_NOTINITIALIZED; if (IsConnected()==FZ_REPLY_NOTCONNECTED) return FZ_REPLY_NOTCONNECTED; if (IsBusy()==FZ_REPLY_BUSY) return FZ_REPLY_BUSY; if (path.IsEmpty() || !path.HasParent()) return FZ_REPLY_INVALIDPARAM; t_command command; command.id=FZ_COMMAND_MAKEDIR; command.path=path; m_pMainThread->Command(command); if (m_hOwnerWnd) return FZ_REPLY_WOULDBLOCK; else return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR; return FZ_REPLY_ERROR; }
void CNetworkModule::Pulse( void ) { // Is the game not loaded? if( !pCore->IsGameLoaded() ) return; // Are we disconnected from the network? if( GetNetworkState() == NETSTATE_DISCONNECTED ) return; // Process the network UpdateNetwork (); // Are we connected? if( IsConnected() ) { // Pulse the player manager pCore->GetPlayerManager()->Pulse (); // Pulse the vehicle manager pCore->GetVehicleManager()->Pulse (); } }
int CFileZillaApi::Chmod(int nValue, CString FileName, const CServerPath &path /*=CServerPath()*/ ) { //Check if call allowed if (!m_bInitialized) return FZ_REPLY_NOTINITIALIZED; if (IsConnected()==FZ_REPLY_NOTCONNECTED) return FZ_REPLY_NOTCONNECTED; if (IsBusy()==FZ_REPLY_BUSY) return FZ_REPLY_BUSY; if (FileName==_MPT("")) return FZ_REPLY_INVALIDPARAM; t_command command; command.id=FZ_COMMAND_CHMOD; command.param1=FileName; command.param4=nValue; command.path=path; m_pMainThread->Command(command); if (m_hOwnerWnd) return FZ_REPLY_WOULDBLOCK; else return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR; }
void CNeighbour::Disconnect() { if ( ! IsConnected() ) return; m_bConnected = FALSE; StopThread(); DisconnectNamedPipe( m_hPipe ); m_hPipe = INVALID_HANDLE_VALUE; for ( POSITION pos = m_pList.GetStartPosition(); pos; ) { CString xUserId; CCircuitry* pChannel; m_pList.GetNextAssoc( pos, xUserId, (void*&)pChannel ); if ( pChannel ) pChannel->Release(); } m_pList.RemoveAll(); }
int P4ClientAPI::Disconnect() { if ( P4LUADEBUG_COMMANDS ) fprintf( stderr, "[P4] Disconnect\n" ); if ( ! IsConnected() ) { // rb_warn( "P4:disconnect - not connected" ); return 0; } Error e; client.Final( &e ); ResetFlags(); // Clear the specdef cache. specMgr.Reset(); // Clear out any results from the last command ui.Reset(); return 0; }
bool MySQLInterface::Connect(const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag) { if (IsConnected()) return false; _host=host; _user=user; _passwd=passwd; _db=db; _port=port; _unix_socket=unix_socket; _clientflag=clientflag; mySqlConnection = mysql_init(0); return mysql_real_connect (mySqlConnection, host, user, passwd, db, port, unix_socket, clientflag) != 0; }
bool BeNetWindow::QuitRequested(void) { // Save the preferences Preferences::Instance()->Save(); // Go offline if (TClient::Instance()->IsOnline()) GoOffline(); if (IsConnected()) Disconnect(); // Delete the recorder (pretend that it's recording) if (m_pRecorder != NULL) { // OliverESP: we have to look out the pointer! m_pRecorder->StopRecording(); delete m_pRecorder; m_pRecorder = NULL; } be_app_messenger.SendMessage(B_QUIT_REQUESTED); return true; }
ByteArray ConnectorMySQL::Select(const ByteArray &command, ErrorCode &error_code) { if (IsConnected()) { mysql_real_query(&mysql_, command.data(), command.size()); int error = mysql_errno(&mysql_); if (error != 0) { error_code.SetError(error, mysql_error(&mysql_)); return ByteArray(); } ByteArray bytes; MYSQL_RES *sql_result = mysql_store_result(&mysql_); mysql_stuff::Serialize(sql_result, &bytes); mysql_free_result(sql_result); return bytes; } else { throw NotConnected(); } }
/** * Initiates asynchronous query for available task databases * * @param InServerName Server host name * @param InServerPort Server port * @param InLoginUserName User name * @param InLoginPassword Password * * @return True if async requested was kicked off successfully */ bool QueryAvailableDatabases_Async( const FString& InServerName, const uint32 InServerPort, const FString& InLoginUserName, const FString& InLoginPassword ) { if( IsConnected() ) { TDLOG( TEXT( "Async request failed because we're already connected to a server" ) ); return false; } // Build a server URL string (e.g. "http://myservername:80") FString ServerURL = FString( TEXT( "http://" ) ) + InServerName + FString( TEXT( ":" ) ) + FString( FString::FromInt( InServerPort ) ); FTaskDatabaseRequest_QueryAvailableDatabases* Request = new FTaskDatabaseRequest_QueryAvailableDatabases(); Request->RequestType = ETaskDatabaseRequestType::QueryAvailableDatabases; Request->ServerURL = ServerURL; Request->LoginUserName = InLoginUserName; Request->LoginPassword = InLoginPassword; return StartAsyncRequest( Request ); }
Server::~Server(){ printf("Closing Server.\n"); lock(); network_task->should_die = true; if(IsConnected()) Thread::RemoveSocketFromTaskGroup(state.socket, Thread::GetShortThreadPool()); while(!task_died){ unlock(); lock(); } unlock(); // Not particularly concerned with whether this fails or not. // There's not a lot we can do if it fails. Disconnect_Socket(state.socket); Destroy_Socket(state.socket); }
bool MemCacheClient::Server::Connect( int a_nTimeout ) { // already connected? do nothing if (IsConnected()) { return true; } // only try to re-connect to a broken server occasionally time_t nNow; #ifdef WIN32 nNow = GetTickCount(); if (nNow - mLastConnect < MEMCACHECLIENT_RECONNECT_SEC * 1000) return false; #else time(&nNow); if (nNow - mLastConnect < MEMCACHECLIENT_RECONNECT_SEC) return false; #endif mLastConnect = nNow; return ServerSocket::Connect(mIp, mPort, a_nTimeout); }
bool Postgres::TableExists(const wxString& sTableName) { if(!IsConnected()) throw wx::Exception(wxT("Postgres::TableExists() Database not connected.")); wxString sqryTableExists = wxT(" \ SELECT \ cl.relname \ FROM \ pg_class cl \ INNER JOIN \ pg_namespace ns \ ON \ cl.relnamespace = ns.oid \ WHERE \ ns.nspname = 'public' \ AND \ cl.reltype <> 0 \ AND \ cl.relkind = 'r' \ AND \ cl.relname = $1; \ "); ArrayRecord arParams; arParams.push_back(wxVariant(sTableName)); ArrayRecordArray ara; stc.CacheExecute ( wxT("Postgres::TableExists"), sqryTableExists, arParams, ara ); return (ara.size() != 0)? true : false;; }
wxArrayString Postgres::GetTables() { if(!IsConnected()) throw wx::Exception(wxT("Postgres::GetTables() Database not connected.")); wxString sqryTables = wxT(" \ SELECT \ relname \ FROM \ pg_class cl \ INNER JOIN \ pg_namespace ns \ ON \ cl.relnamespace = ns.oid \ WHERE \ ns.nspname = 'public' \ AND \ cl.reltype <> 0 \ AND \ cl.relkind = 'r'; \ "); ArrayRecordArray ara; stc.CacheExecute ( wxT("Postgres::GetTables"), sqryTables, ArrayRecord(), ara ); ArrayRecord ar; for(ArrayRecordArray::iterator it = ara.begin(); it != ara.end(); it++) ar.push_back(it->at(0)); return ar.GetArrayString(); }
OUTPACKET_RESULT WorldServerSocket::_OutPacket(uint16 opcode, size_t len, const void* data) { bool rv; if(!IsConnected()) return OUTPACKET_RESULT_NOT_CONNECTED; BurstBegin(); //if((m_writeByteCount + len + 4) >= m_writeBufferSize) if( GetWriteBuffer().GetSpace() < (len+4) ) { BurstEnd(); return OUTPACKET_RESULT_NO_ROOM_IN_BUFFER; } // Packet logger :) sWorldLog.LogPacket((uint32)len, opcode, (const uint8*)data, 1); // Encrypt the packet // First, create the header. ServerPktHeader Header; Header.cmd = opcode; Header.size = ntohs((uint16)len + 2); _crypt.EncryptFourSend((uint8*)&Header); // Pass the header to our send buffer rv = BurstSend((const uint8*)&Header, 4); // Pass the rest of the packet to our send buffer (if there is any) if(len > 0 && rv) { rv = BurstSend((const uint8*)data, (uint32)len); } if(rv) BurstPush(); BurstEnd(); return rv ? OUTPACKET_RESULT_SUCCESS : OUTPACKET_RESULT_SOCKET_ERROR; }
uint32_t NamedPipeInfo::Peek(void* aBuffer, int32_t aSize) { MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread); MOZ_ASSERT(mReadBegin <= mReadEnd); if (!IsConnected()) { // pipe unconnected PR_SetError(PR_NOT_CONNECTED_ERROR, 0); return -1; } /** * If there's nothing in the read buffer, try to trigger internal read * operation by calling |GetPollFlags|. This is required for callers that * use blocking I/O because they don't call |GetPollFlags| to read data, * but this also works for non-blocking I/O. */ if (!Available()) { int16_t outFlag; GetPollFlags(PR_POLL_READ, &outFlag); if (!(outFlag & PR_POLL_READ)) { PR_SetError(IsNonblocking() ? PR_WOULD_BLOCK_ERROR : PR_IO_PENDING_ERROR, 0); return -1; } } // Available() can't return more than what fits to the buffer at the read offset. int32_t bytesRead = std::min<int32_t>(aSize, Available()); MOZ_ASSERT(bytesRead >= 0); MOZ_ASSERT(mReadBegin + bytesRead <= mReadEnd); memcpy(aBuffer, &mReadBuffer[mReadBegin], bytesRead); return bytesRead; }
bool IrcBot::SendData(MessageType type, char const* data) { std::stringstream ss; switch(type) { case USER: ss << "USER " << IRC_USER_NICK << " 0 * :" << data; break; case NICK: ss << "NICK " << data; break; case IDENTIFY: ss << "PRIVMSG NickServ :IDENTIFY " << data; break; case JOIN: ss << "JOIN " << data; break; case PRIVMSG: ss << "PRIVMSG " << IRC_CHANNEL << " :" << data; break; default: ss << data; break; } if (IsConnected()) { std::string temp = ss.str(); temp += "\r\n"; char const* message = temp.c_str(); if (send(_socket, message, strlen(message), 0) == -1) return false; } return true; }
PierSide ScopeINDI::SideOfPier(void) { PierSide pierSide = PIER_SIDE_UNKNOWN; try { if (!IsConnected()) { throw ERROR_INFO("INDI Scope: cannot get side of pier when not connected"); } if (pierside_prop == NULL) { throw THROW_INFO("INDI Scope: not capable of getting side of pier"); } else { if (piersideEast_prop->s == ISS_ON) { pierSide = PIER_SIDE_EAST; } if (piersideWest_prop->s == ISS_ON) { pierSide = PIER_SIDE_WEST; } } } catch (const wxString& Msg) { POSSIBLY_UNUSED(Msg); } Debug.Write(wxString::Format("ScopeINDI::SideOfPier() returns %d\n", pierSide)); return pierSide; }
// Special purpose function to return the guiding declination (radians) - either the actual scope position or the // default values defined in mount.cpp. Doesn't throw exceptions to callers. double ScopeASCOM::GetGuidingDeclination(void) { double dReturn = Scope::GetDefGuidingDeclination(); try { if (!IsConnected()) { throw ERROR_INFO("ASCOM Scope: cannot get Declination when not connected to mount"); } if (!m_bCanGetCoordinates) { throw THROW_INFO("!m_bCanGetCoordinates"); } GITObjRef scope(m_gitEntry); Variant vRes; if (!scope.GetProp(&vRes, dispid_declination)) { throw ERROR_INFO("GetDeclination() fails: " + ExcepMsg(scope.Excep())); } dReturn = radians(vRes.dblVal); } catch (wxString Msg) { POSSIBLY_UNUSED(Msg); m_bCanGetCoordinates = false; } Debug.AddLine("ScopeASCOM::GetDeclination() returns %.1f", degrees(dReturn)); return dReturn; }
sBool sTCPClientSocket::Connect(sIPAddress address, sIPPort port) { TransferError=0; if (IsConnected()) Disconnect(); sNET_SOCKTYPE s=socket(PF_INET,SOCK_STREAM,0); if (s==sINVALID_SOCKET) { P->HandleError(); return sFALSE; } sClear(P->Address); P->Address.sin_family=AF_INET; P->Address.sin_port=htons(port); sCopyMem(&P->Address.sin_addr,&address,4); sInt res=connect(s,(sockaddr*)&P->Address,sizeof(P->Address)); if (!res) { P->Socket=s; P->Connected=sTRUE; return sTRUE; } int namelen = sizeof(P->LocalAddress); getsockname(s,(sockaddr*)&P->LocalAddress,&namelen); P->HandleError(); closesocket(s); return sFALSE; }
bool Exword::Authenticate(wxString user, wxMemoryBuffer& key) { bool success = false; int rsp; uint16_t count; exword_dirent_t *entries; exword_authchallenge_t c; exword_authinfo_t ai; exword_userid_t u; if (!IsConnected()) return success; memcpy(c.challenge, key.GetData(), 20); memcpy(ai.blk1, "FFFFFFFFFFFFFFFF", 16); strncpy((char*)ai.blk2, user.utf8_str().data(), 24); strncpy(u.name, user.utf8_str().data(), 16); exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0); rsp = exword_authchallenge(m_device, c); if (rsp == EXWORD_SUCCESS) { exword_setpath(m_device, (uint8_t*)"", 0); exword_list(m_device, &entries, &count); for (int i = 0; i < count; i++) { if (strcmp((const char*)entries[i].name, "_SD_00") == 0) { exword_setpath(m_device, (uint8_t*)"\\_SD_00", 0); rsp = exword_authchallenge(m_device, c); if (rsp != EXWORD_SUCCESS) exword_authinfo(m_device, &ai); } } exword_free_list(entries); exword_userid(m_device, u); success = true; } return success; }
Model Exword::GetModel() { Model modelInfo; exword_model_t model; memset(&model, 0, sizeof(exword_model_t)); if (IsConnected()) { if (exword_get_model(m_device, &model) == EXWORD_SUCCESS) { modelInfo = ModelDatabase::Get()->Lookup(wxString::FromAscii(model.model), wxString::FromAscii(model.sub_model), wxString::FromAscii(model.ext_model)); if (modelInfo.GetSeries() == 0) { if ((model.capabilities & CAP_F) && (model.capabilities & CAP_C)) { modelInfo = Model(5); } else if (model.capabilities & CAP_P) { modelInfo = Model(4); } else { modelInfo = Model(3); } } } } return modelInfo; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- const char *C_PlayerResource::GetPlayerName( int iIndex ) { if ( cl_names_debug.GetInt() ) return PLAYER_DEBUG_NAME; if ( iIndex < 1 || iIndex > MAX_PLAYERS ) { Assert( false ); return "ERRORNAME"; } if ( !IsConnected( iIndex ) ) return PLAYER_UNCONNECTED_NAME; // X360TBD: Network - figure out why the name isn't set if ( !m_szName[ iIndex ] || !Q_stricmp( m_szName[ iIndex ], PLAYER_UNCONNECTED_NAME ) ) { // If you get a full "reset" uncompressed update from server, then you can have NULLNAME show up in the scoreboard UpdatePlayerName( iIndex ); } // This gets updated in ClientThink, so it could be up to 1 second out of date, oh well. return m_szName[iIndex]; }
// Check streaming status HRESULT CTransformInputPin::CheckStreaming() { ASSERT(m_pTransformFilter->m_pOutput != NULL); if(!m_pTransformFilter->m_pOutput->IsConnected()) { return VFW_E_NOT_CONNECTED; } else { // Shouldn't be able to get any data if we're not connected! ASSERT(IsConnected()); // we're flushing if(m_bFlushing) { return S_FALSE; } // Don't process stuff in Stopped state if(IsStopped()) { return VFW_E_WRONG_STATE; } if(m_bRunTimeError) { return VFW_E_RUNTIME_ERROR; } return S_OK; } }
void IOCPConnection::OnDisconnect( int flag ) { bool bNotifyClosed = false; { THREAD_SYNC( m_closeCS ); if( !m_bDisconnectSignal ) { m_bDisconnectSignal = true; m_disconnectReason = flag; } // 쿼리 갯수가 0이라면? if( GetPendingQueryCount() == 0 ) { if( !m_bDisconnectEventPosted ) { if( IsConnected() ) { m_bConnected = false; Close(); } m_bDisconnectEventPosted = true; bNotifyClosed = true; } } } if( bNotifyClosed ) { PostQueuedCompletionStatus( m_hIOCP, 0, IOCP::EVENT_CONNECTION_CLOSED, m_pRecvOverlapped ); } }
void Wiimote::ThreadFunc() { Common::SetCurrentThreadName("Wiimote Device Thread"); bool ok = ConnectInternal(); if (!ok) { // try again, it might take a moment to settle Common::SleepCurrentThread(100); ok = ConnectInternal(); } m_thread_ready_event.Set(); m_run_thread.Set(); if (!ok) { return; } // main loop while (IsConnected() && m_run_thread.IsSet()) { if (m_need_prepare.TestAndClear() && !PrepareOnThread()) { ERROR_LOG(WIIMOTE, "Wiimote::PrepareOnThread failed. Disconnecting Wiimote %d.", m_index + 1); break; } Write(); Read(); } DisconnectInternal(); }
CNetworkModule::~CNetworkModule( void ) { // Are we connected? if( IsConnected() ) { // Disconnect from the network Disconnect(); } // Unregister the network RPC's CNetworkRPC::Unregister( m_pRPC ); // Unregister the scripting RPC's CScriptingRPC::Unregister( m_pRPC ); // Detach RPC4 from RakPeerInterface m_pRakPeer->DetachPlugin( m_pRPC ); // Destroy the RPC4 instance RakNet::RPC4::DestroyInstance( m_pRPC ); // Destroy the RakPeerInterface instance RakNet::RakPeerInterface::DestroyInstance( m_pRakPeer ); }
void CNetworkManager::Pulse() { // Is the game not loaded? if(!g_pCore->IsGameLoaded()) return; // Are we disconnected from the network? if(GetNetworkState() == NETSTATE_DISCONNECTED) return; // Should we try connecting again? if(GetNetworkState() == NETSTATE_TIMEOUT && ((unsigned short)SharedUtility::GetTime() - m_uiLastConnectionTry) >= NETWORK_TIMEOUT) { // Attempt to reconnect Connect(m_strIp, m_usPort, m_strPass); // Set the network state SetNetworkState(NETSTATE_CONNECTING); // Set the last connection try m_uiLastConnectionTry = (unsigned int)SharedUtility::GetTime(); } // Process the network UpdateNetwork(); // Are we connected? if(IsConnected()) { // Pulse the player manager g_pCore->GetGame()->GetPlayerManager()->Pulse(); // Pulse the vehicle manager g_pCore->GetGame()->GetVehicleManager()->Pulse(); } }
HRESULT CWavPackSplitterFilterInputPin::Active() { HRESULT hr; if (m_pParentFilter->IsActive()) { return S_FALSE; } if (!IsConnected()) { return NOERROR; } hr = CBaseInputPin::Active(); if (FAILED(hr)) { return hr; } // Create and start the thread if (!Create()) { return E_FAIL; } CallWorker(CMD_RUN); return NOERROR; }
void ClientSession::Disconnect() { if ( !IsConnected() ) return ; printf("[DEBUG] Client Disconnected: IP=%s, PORT=%d\n", inet_ntoa(mClientAddr.sin_addr), ntohs(mClientAddr.sin_port)) ; /// 즉각 해제 LINGER lingerOption; lingerOption.l_onoff = 1; lingerOption.l_linger = 0; /// no TCP TIME_WAIT if (SOCKET_ERROR == setsockopt(mSocket, SOL_SOCKET, SO_LINGER, (char*)&lingerOption, sizeof(LINGER))) { printf_s("[DEBUG] setsockopt linger option error: %d\n", GetLastError()); return; } closesocket(mSocket) ; mConnected = false ; }