BOOL CHostBrowser::OnRun() { CTransfer::OnRun(); DWORD nNow = GetTickCount(); switch ( m_nState ) { case hbsConnecting: if ( nNow - m_tConnected > Settings.Connection.TimeoutConnect * 2 ) { OnDropped( TRUE ); return FALSE; } break; case hbsRequesting: case hbsHeaders: if ( nNow - m_tConnected > Settings.Connection.TimeoutHandshake * 3 ) { theApp.Message( MSG_ERROR, IDS_BROWSE_TIMEOUT, (LPCTSTR)m_sAddress ); Stop(); return FALSE; } break; case hbsContent: if ( nNow - m_mInput.tLast > Settings.Connection.TimeoutTraffic ) { theApp.Message( MSG_ERROR, IDS_BROWSE_TIMEOUT, (LPCTSTR)m_sAddress ); Stop(); return FALSE; } } return TRUE; }
BOOL CMonitorChannel::OnRun() { if ( ! CChannel::OnRun() ) return FALSE; DWORD tNow = GetTickCount(); if ( IsConnected() && tNow - m_tConnected >= 180* 1000 ) { OnDropped( WSA_WAIT_TIMEOUT ); return FALSE; } return TRUE; }
BOOL CTransfer::OnRun() { if ( ! CConnection::OnRun() ) return FALSE; DWORD tNow = GetTickCount(); if ( ! IsConnected() && tNow - m_tConnected >= 15* 1000 ) { OnDropped( FALSE ); return FALSE; } return TRUE; }
BOOL CConnection::OnRun() { if ( INVALID_SOCKET == m_hSocket ) return FALSE; WSANETWORKEVENTS pEvents; WSAEnumNetworkEvents( m_hSocket, NULL, &pEvents ); if ( pEvents.lNetworkEvents & FD_CONNECT ) { if ( pEvents.iErrorCode[ FD_CONNECT_BIT ] != 0 ) { OnDropped( TRUE ); return FALSE; } if ( ! OnConnected() ) return FALSE; } BOOL bClosed = ( pEvents.lNetworkEvents & FD_CLOSE ) ? TRUE : FALSE; // if ( pEvents.lNetworkEvents & FD_WRITE ) { if ( ! OnWrite() ) return FALSE; } // if ( pEvents.lNetworkEvents & FD_READ ) { if ( ! OnRead() ) return FALSE; } if ( bClosed ) { OnDropped( pEvents.iErrorCode[ FD_CLOSE_BIT ] != 0 ); return FALSE; } return TRUE; }
BOOL CHostBrowser::OnRun() { //CQuickLock oTransfersLock( Transfers.m_pSection ); CTransfer::OnRun(); const DWORD tNow = GetTickCount(); switch ( m_nState ) { case hbsConnecting: if ( tNow >= m_tConnected + Settings.Connection.TimeoutConnect * 2 ) { OnDropped(); return FALSE; } break; case hbsRequesting: case hbsHeaders: if ( tNow >= m_tConnected + Settings.Connection.TimeoutHandshake * 3 ) { theApp.Message( MSG_ERROR, IDS_BROWSE_TIMEOUT, (LPCTSTR)m_sAddress ); Stop(); return FALSE; } break; case hbsContent: if ( tNow >= m_mInput.tLast + Settings.Connection.TimeoutTraffic ) { theApp.Message( MSG_ERROR, IDS_BROWSE_TIMEOUT, (LPCTSTR)m_sAddress ); Stop(); return FALSE; } } return TRUE; }
// Talk to the other computer, write the output buffer to the socket and read from the socket to the input buffer // Return true if this worked, false if we've lost the connection BOOL CConnection::DoRun() { // If this socket is invalid, call OnRun and return the result (do) if ( ! IsValid() ) return OnRun(); // Setup pEvents to store the socket's internal information about network events WSANETWORKEVENTS pEvents = {}; if ( WSAEnumNetworkEvents( m_hSocket, NULL, &pEvents ) != 0 ) return FALSE; // If the FD_CONNECT network event has occurred if ( pEvents.lNetworkEvents & FD_CONNECT ) { // If there is a nonzero error code for the connect operation, this connection was dropped if ( pEvents.iErrorCode[ FD_CONNECT_BIT ] != 0 ) { Statistics.Current.Connections.Errors++; OnDropped(); return FALSE; } // The socket is now connected m_bConnected = TRUE; m_tConnected = m_mInput.tLast = m_mOutput.tLast = GetTickCount(); // Store the time 3 places // Call CShakeNeighbour::OnConnected to start reading the handshake if ( ! OnConnected() ) return FALSE; Network.AcquireLocalAddress( m_hSocket ); } // If the FD_CLOSE network event has occurred, set bClosed to true, otherwise set it to false BOOL bClosed = ( pEvents.lNetworkEvents & FD_CLOSE ) ? TRUE : FALSE; // If the close event happened, null a pointer within the TCP bandwidth meter for input (do) if ( bClosed ) m_mInput.pLimit = NULL; // Change the queued run state to 1 (do) m_nQueuedRun = 1; // Write the contents of the output buffer to the remote computer, and read in data it sent us if ( ! OnWrite() ) return FALSE; if ( ! OnRead() ) return FALSE; // If the close event happened if ( bClosed ) { // theApp.Message( MSG_DEBUG, _T("socket close() error %i"), pEvents.iErrorCode[ FD_CLOSE_BIT ] ); // Call OnDropped, telling it true if there is a close error OnDropped(); // True if there is an nonzero error code for the close bit return FALSE; } // Make sure the handshake doesn't take too long if ( ! OnRun() ) return FALSE; // If the queued run state is 2 and OnWrite returns false, leave here with false also if ( m_nQueuedRun == 2 && ! OnWrite() ) return FALSE; // Change the queued run state back to 0 and report success (do) m_nQueuedRun = 0; return TRUE; }