NCBI C++ ToolKit
|
Classes | |
class | IServer_ConnectionBase |
class | CServer_Connection |
class | CServer_Listener |
class | CServer |
CServer:: More... | |
class | IServer_ConnectionHandler |
IServer_ConnectionHandler:: More... | |
class | IServer_MessageHandler |
IServer_MessageHandler:: More... | |
class | IServer_LineMessageHandler |
IServer_LineMessageHandler:: More... | |
class | IServer_StreamHandler |
IServer_StreamHandler:: More... | |
class | IServer_ConnectionFactory |
IServer_ConnectionFactory:: More... | |
class | CServer_ConnectionFactory< TServer_ConnectionHandler > |
CServer_ConnectionFactory:: More... | |
struct | SServer_Parameters |
SServer_Parameters:: More... | |
class | CServer_Exception |
CServer_Exception:: More... | |
struct | IServer_Monitor |
Base interface for monitoring. More... | |
class | CServer_Monitor |
Server monitor. More... | |
class | CThreadedServerException |
Exceptions thrown by CThreadedServer::Run. More... | |
class | CServer_ConnectionPool |
Typedefs | |
typedef IServer_ConnectionBase | CServer_ConnectionPool::TConnBase |
typedef CServer_Connection | CServer_ConnectionPool::TConnection |
typedef CServer_Listener | CServer_ConnectionPool::TListener |
typedef set< TConnBase * > | CServer_ConnectionPool::TData |
IServer_Monitor interface | |
virtual bool | CServer_Monitor::IsActive () |
Check if monitoring is active. More... | |
virtual void | CServer_Monitor::Send (const char *msg, size_t length) |
Send message. More... | |
virtual void | CServer_Monitor::Send (const string &str) |
Send message. More... | |
Definition at line 55 of file connection_pool.hpp.
Definition at line 56 of file connection_pool.hpp.
|
private |
Definition at line 100 of file connection_pool.hpp.
Definition at line 57 of file connection_pool.hpp.
Type of connection closing.
Enumerator | |
---|---|
eOurClose | Connection closed by ourselves. |
eClientClose | Connection closed by other peer. |
Definition at line 268 of file server.hpp.
Enumerator | |
---|---|
eBadParameters | Out-of-range parameters given. |
eCouldntListen | Unable to bind listening port. |
ePoolOverflow | Connection pool overflowed. |
Definition at line 467 of file server.hpp.
Enumerator | |
---|---|
eBadParameters | Out-of-range parameters given. |
eCouldntListen | Unable to bind listening port. |
Definition at line 55 of file threaded_server.hpp.
What to do if the port is busy.
Enumerator | |
---|---|
eLAFail | |
eLAIgnore | |
eLARetry |
Definition at line 391 of file server.hpp.
enum EOverflowReason |
Error codes for OnOverflow method in IServer_ConnectionHandler.
Enumerator | |
---|---|
eOR_Unknown | |
eOR_ConnectionPoolFull | |
eOR_RequestQueueFull | |
eOR_UnpollableSocket |
Definition at line 209 of file server.hpp.
enum EServerConnType |
Enumerator | |
---|---|
eInactiveSocket | |
eActiveSocket | |
eListener | |
ePreDeferredSocket | |
eDeferredSocket | |
ePreClosedSocket | |
eClosedSocket |
Definition at line 49 of file server_connection.hpp.
enum EServIO_Event |
Extended copy of the type EIO_Event allowing to distinguish between connection closing from client and from ourselves.
Enumerator | |
---|---|
eServIO_Open | |
eServIO_Read | |
eServIO_Write | |
eServIO_ReadWrite | eIO_Read | eIO_Write |
eServIO_ClientClose | |
eServIO_OurClose | |
eServIO_Inactivity | |
eServIO_Delete | |
eServIO_Alarm |
Definition at line 61 of file server.hpp.
|
inlinevirtual |
Reimplemented in CServer_Listener.
Definition at line 77 of file server_connection.hpp.
|
inlinevirtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 127 of file server_connection.hpp.
References eIO_Success, IServer_ConnectionFactory::eLAFail, IServer_ConnectionFactory::eLAIgnore, CListeningSocket::GetStatus(), CListeningSocket::Listen(), CServer_Listener::m_Factory, CServer_Listener::m_Port, NCBI_THROW, and st().
bool CServer_ConnectionPool::Add | ( | TConnBase * | conn, |
EServerConnType | type | ||
) |
Definition at line 100 of file connection_pool.cpp.
References abort(), conn, eListener, set< Key, Compare >::end(), set< Key, Compare >::find(), set< Key, Compare >::insert(), CServer_ConnectionPool::m_Data, CServer_ConnectionPool::m_ListeningStarted, CServer_ConnectionPool::m_MaxConnections, CServer_ConnectionPool::m_Mutex, CServer_ConnectionPool::PingControlConnection(), set< Key, Compare >::size(), type, and CServer_ConnectionPool::x_UpdateExpiration().
Referenced by CServer::AddConnectionToPool(), CServer::AddListener(), and CAcceptRequest::x_DoProcess().
void CServer::AddConnectionToPool | ( | CServer_Connection * | conn | ) |
Add externally created connection to the connection pool which server polls on.
Throws exception if pool is full. NOTE: events to this connection can come theoretically even NOTE: if connection gets some error or its peer closes it then conn object will be deleted after processing OnClose event. If you don't want that you have to call RemoveConnectionFromPool while handling OnClose.
Definition at line 824 of file server.cpp.
References CServer_ConnectionPool::Add(), conn, eInactiveSocket, CServer::m_ConnectionPool, and NCBI_THROW.
void CServer::AddListener | ( | IServer_ConnectionFactory * | factory, |
unsigned short | port | ||
) |
Register a listener.
Definition at line 605 of file server.cpp.
References CServer_ConnectionPool::Add(), eListener, and CServer::m_ConnectionPool.
Referenced by CNetScheduleServer::AddDefaultListener(), CNetStorageServer::AddDefaultListener(), CWorkerNodeControlServer::CWorkerNodeControlServer(), and CBDBEnvKeeperApp::Run().
|
inlinevirtual |
Implements IServer_MessageHandler.
Definition at line 352 of file server.hpp.
References buffer, data, IServer_LineMessageHandler::m_SeenCR, Server_CheckLineMessage(), and ncbi::grid::netcache::search::fields::size.
|
pure virtual |
Implemented in IServer_LineMessageHandler.
Referenced by IServer_MessageHandler::OnRead().
void CServer::CloseConnection | ( | CSocket * | sock | ) |
Close connection.
Method should be called only when closing is initiated by server itself, because it will generate then event eServIO_OurClose.
Definition at line 643 of file server.cpp.
References CServer_ConnectionPool::CloseConnection(), and CServer::m_ConnectionPool.
Referenced by CNetScheduleHandler::OnMessage(), CNetStorageHandler::OnRead(), CNetScheduleHandler::x_HandleSocketErrorOnResponse(), CNetScheduleHandler::x_OnCmdParserError(), CNetStorageHandler::x_OnMessage(), CNetStorageHandler::x_OnSocketWriteError(), CNetScheduleHandler::x_PrepareWriteBuffer(), CNetScheduleHandler::x_ProcessMsgAuth(), CNetScheduleHandler::x_ProcessMsgQueue(), CNetScheduleHandler::x_ProcessQuitSession(), CNetStorageHandler::x_ReadRawData(), and CNetScheduleHandler::x_WriteMessage().
void CServer_ConnectionPool::CloseConnection | ( | TConnBase * | conn | ) |
Close connection as if it was initiated by server (not by client).
Definition at line 213 of file connection_pool.cpp.
References CSocket::Abort(), conn, Critical(), eActiveSocket, ePreClosedSocket, ePreDeferredSocket, ERR_POST, eServIO_OurClose, g_ServerConnTypeToString(), and CServer_Connection::OnSocketEvent().
Referenced by CServer::CloseConnection(), and CServerConnectionRequest::x_Process().
|
inlinevirtual |
Implements IServer_ConnectionFactory.
Definition at line 420 of file server.hpp.
|
pure virtual |
Implemented in CWNCTConnectionFactory, CNetStorageConnectionFactory, CNetScheduleConnectionFactory, CBDBEnvKeeperConnectionFactory, and CServer_ConnectionFactory< TServer_ConnectionHandler >.
|
virtual |
Implements IServer_ConnectionBase.
Definition at line 521 of file server.cpp.
|
virtual |
Implements IServer_ConnectionBase.
Definition at line 510 of file server.cpp.
References CServer_Listener::CAcceptRequest.
|
pure virtual |
Implemented in CServer_Listener, and CServer_Connection.
Referenced by CServer::x_DoRun().
CServer::CServer | ( | void | ) |
Definition at line 579 of file server.cpp.
References CServer::m_ConnectionPool, CServer::m_Parameters, and SServer_Parameters::max_connections.
|
inline |
Definition at line 93 of file server_connection.hpp.
References CServer_Connection::m_Handler.
CServer_ConnectionPool::CServer_ConnectionPool | ( | unsigned | max_connections | ) |
Definition at line 59 of file connection_pool.cpp.
|
inline |
Definition at line 121 of file server_connection.hpp.
CServer_Monitor::CServer_Monitor | ( | ) |
Server monitor.
Definition at line 41 of file server_monitor.cpp.
|
private |
void CServer::DeferConnectionProcessing | ( | CSocket * | sock | ) |
Definition at line 818 of file server.cpp.
References CServer::DeferConnectionProcessing().
void CServer::DeferConnectionProcessing | ( | IServer_ConnectionBase * | conn | ) |
Mark connection as deferred for processing, i.e.
do not poll on it and wait when IsReadyToProcess() will return true.
Definition at line 812 of file server.cpp.
References conn, ePreDeferredSocket, CServer::m_ConnectionPool, and CServer_ConnectionPool::SetConnType().
Referenced by CServer::DeferConnectionProcessing().
void CServer_ConnectionPool::Erase | ( | void | ) |
Erase all connections.
Definition at line 68 of file connection_pool.cpp.
References set< Key, Compare >::clear(), conn, eServIO_OurClose, CServer_ConnectionPool::m_Data, CServer_ConnectionPool::m_Mutex, and NON_CONST_ITERATE.
Referenced by CServer::Run(), and CServer_ConnectionPool::~CServer_ConnectionPool().
|
inlineprotectedvirtual |
Cleanup the server.
Called by Run method after poll cycle when all processing threads are stopped, but before releasing listening ports. Here you're still guaranteed that another instance running on the same set of ports will fail at StartListening point.
Reimplemented in CNetStorageServer, and CNetScheduleServer.
Definition at line 181 of file server.hpp.
Referenced by CServer::Run().
std::string g_ServerConnTypeToString | ( | enum EServerConnType | conn_type | ) |
Definition at line 44 of file connection_pool.cpp.
References eActiveSocket, eClosedSocket, eDeferredSocket, eInactiveSocket, eListener, ePreClosedSocket, and ePreDeferredSocket.
Referenced by CServer_ConnectionPool::CloseConnection().
|
overridevirtual |
Definition at line 863 of file server.cpp.
References CServer_Exception::eBadParameters, CServer_Exception::eCouldntListen, CServer_Exception::ePoolOverflow, and CException::GetErrCodeString().
|
overridevirtual |
Definition at line 135 of file threaded_server.cpp.
References CThreadedServerException::eBadParameters, CThreadedServerException::eCouldntListen, and CException::GetErrCodeString().
Reimplemented in CServer_Connection.
Definition at line 67 of file server_connection.hpp.
References eIO_Read.
Referenced by CServer_ConnectionPool::GetPollAndTimerVec(), and CServer::x_DoRun().
|
inlinevirtual |
Following three methods are guaranteed to be called NOT at the same time as On*, so if you implement them you should not guard the variables which they can use with mutexes.
alarm_time | Set this parameter to a pointer to a CTime object to recieve an OnTimer event at the moment in time specified by this object. |
Reimplemented in CNetStorageHandler.
Definition at line 239 of file server.hpp.
References eIO_Read.
|
inlinevirtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 96 of file server_connection.hpp.
References CServer_Connection::m_Handler.
vector< unsigned short > CServer::GetListenerPorts | ( | void | ) |
Provides a list of ports on which the server is listening.
Definition at line 842 of file server.cpp.
References CServer_ConnectionPool::GetListenerPorts(), and CServer::m_ConnectionPool.
vector< unsigned short > CServer_ConnectionPool::GetListenerPorts | ( | void | ) |
Provides a list of ports on which the server is listening.
Definition at line 415 of file connection_pool.cpp.
References eListener, CServer_Listener::GetPort(), ITERATE, CFastMutex::Lock(), CServer_ConnectionPool::m_Data, CServer_ConnectionPool::m_ListenerPortsToStop, CServer_ConnectionPool::m_Mutex, IServer_ConnectionBase::type, IServer_ConnectionBase::type_lock, and CFastMutex::Unlock().
Referenced by CServer::GetListenerPorts().
void CServer::GetParameters | ( | SServer_Parameters * | params | ) |
Definition at line 631 of file server.cpp.
References CServer::m_Parameters.
Referenced by CNetScheduleServer::SetNSParameters(), CNetStorageServer::SetParameters(), and CNetScheduleHandler::x_GetServerSection().
bool CServer_ConnectionPool::GetPollAndTimerVec | ( | vector< CSocketAPI::SPoll > & | polls, |
vector< IServer_ConnectionBase * > & | timer_requests, | ||
STimeout * | timer_timeout, | ||
vector< IServer_ConnectionBase * > & | revived_conns, | ||
vector< IServer_ConnectionBase * > & | to_close_conns, | ||
vector< IServer_ConnectionBase * > & | to_delete_conns | ||
) |
Definition at line 233 of file connection_pool.cpp.
References _ASSERT, CTime::DiffTimeSpan(), eActiveSocket, eClosedSocket, eDeferredSocket, CTime::eEmpty, eInactiveSocket, eIO_Read, eListener, set< Key, Compare >::erase(), ERASE_ITERATE, IServer_ConnectionBase::expiration, CTimeSpan::GetCompleteSeconds(), IServer_ConnectionBase::GetEventsToPollFor(), GetFastLocalTime(), CTimeSpan::GetNanoSecondsAfterSecond(), CServer_Listener::GetPort(), IServer_ConnectionBase::IsOpen(), IServer_ConnectionBase::IsReadyToProcess(), CFastMutex::Lock(), CServer_ConnectionPool::m_ControlTrigger, CServer_ConnectionPool::m_Data, CServer_ConnectionPool::m_ListenerPortsToStop, CServer_ConnectionPool::m_Mutex, NULL, CGuard< Resource, Lock, Unlock, ReportExceptions >::Release(), STimeoutTag::sec, IServer_ConnectionBase::type, IServer_ConnectionBase::type_lock, CFastMutex::Unlock(), and STimeoutTag::usec.
Referenced by CServer::x_DoRun().
unsigned short GetPort | ( | void | ) | const |
Get the listening port number back.
Definition at line 107 of file threaded_server.hpp.
References m_Port.
Referenced by CSeqGraphicPane::AdjustViewPort(), CSeqGraphicPane::AdjustViewPortHeightToImage(), CGlWidgetDemo::CGlWidgetDemo(), CNetScheduleNotificationHandler::CmdAppendTimeoutGroupAndClientInfo(), CHitMatrixPane::OnSize(), CTcpWorker::OnTcpConnection(), CHitMatrixPane::RenderVectorGraphics(), CNetScheduleNotificationHandler::RequestJobWatching(), CSeqGraphicPane::SetHorizontal(), CNetScheduleNotificationHandler::SubmitJob(), CHitMatrixPane::Update(), CSeqGraphicPane::x_Render(), and CHitMatrixPane::x_RenderContent().
|
inline |
Definition at line 142 of file server_connection.hpp.
References CServer_Listener::m_Port.
Referenced by CServer_ConnectionPool::GetListenerPorts(), CServer_ConnectionPool::GetPollAndTimerVec(), and CServer_ConnectionPool::RemoveListener().
|
inline |
Get underlying socket.
Definition at line 294 of file server.hpp.
References IServer_ConnectionHandler::m_Socket.
Referenced by CRelocateCallback::Callback(), CNetScheduleHandler::OnClose(), CNetStorageHandler::OnClose(), CBDBEnvKeeperConnectionHandler::OnMessage(), CNetScheduleHandler::OnMessage(), CWNCTConnectionHandler::OnMessage(), CBDBEnvKeeperConnectionHandler::OnOpen(), CNetScheduleHandler::OnOpen(), CNetStorageHandler::OnOpen(), CWNCTConnectionHandler::OnOpen(), IServer_MessageHandler::OnRead(), CNetStorageHandler::OnRead(), CNetScheduleHandler::x_CreateConnContext(), CNetStorageHandler::x_CreateConnContext(), CNetScheduleHandler::x_GetPeerAddress(), CNetStorageHandler::x_GetPeerAddress(), CNetScheduleHandler::x_HandleSocketErrorOnResponse(), CNetScheduleHandler::x_OnCmdParserError(), CNetStorageHandler::x_OnMessage(), CNetStorageHandler::x_OnSocketWriteError(), CNetScheduleHandler::x_PrepareWriteBuffer(), CNetScheduleHandler::x_PrintCmdRequestStart(), CNetStorageHandler::x_PrintMessageRequestStart(), CNetScheduleHandler::x_ProcessMsgAuth(), CNetScheduleHandler::x_ProcessMsgBatchJob(), CNetScheduleHandler::x_ProcessMsgQueue(), CNetScheduleHandler::x_ProcessMsgRequest(), CNetScheduleHandler::x_ProcessQuitSession(), CWNCTConnectionHandler::x_ProcessRequest(), CNetScheduleHandler::x_ProcessStatistics(), CNetStorageHandler::x_ReadRawData(), CNetStorageHandler::x_SendOutputBuffer(), CNetStorageHandler::x_SendOverUTTP(), CNetScheduleHandler::x_SetQuickAcknowledge(), CNetStorageHandler::x_SetQuickAcknowledge(), and CNetScheduleHandler::x_WriteMessage().
CNcbiIostream& IServer_StreamHandler::GetStream | ( | ) |
|
inlineprivate |
Definition at line 197 of file server.hpp.
References CServer::m_ThreadPool.
Returns the timeout for this connection.
Definition at line 242 of file server.hpp.
References kDefaultTimeout.
|
inlineprotectedvirtual |
Initialize the server.
Called by Run method before poll cycle.
Definition at line 173 of file server.hpp.
Referenced by CServer::x_DoRun().
|
inline |
Transform EIO_Event type to EServIO_Event.
Definition at line 76 of file server.hpp.
Referenced by CServer::x_DoRun().
|
virtual |
Check if monitoring is active.
Implements IServer_Monitor.
Definition at line 99 of file server_monitor.cpp.
References CServer_Monitor::IsMonitorActive().
|
pure virtual |
Check if monitoring is active.
Implemented in CServer_Monitor.
Referenced by CBDB_Cache::EvaluateTimeLine(), CBDB_Env::MempTrickle(), CBDB_Cache::Purge(), and CBDB_Cache::x_Store().
|
inline |
Definition at line 349 of file server.hpp.
|
inline |
Definition at line 315 of file server.hpp.
bool CServer_Monitor::IsMonitorActive | ( | ) |
Definition at line 67 of file server_monitor.cpp.
References eIO_Open, eIO_Success, CSocket::GetStatus(), CServer_Monitor::m_Lock, CServer_Monitor::m_Sock, and st().
Referenced by CServer_Monitor::IsActive().
|
inlinevirtual |
Reimplemented in CServer_Connection.
Definition at line 72 of file server_connection.hpp.
Referenced by CServer_ConnectionPool::GetPollAndTimerVec().
|
virtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 528 of file server.cpp.
References CServer_Connection::m_Open.
|
inlinevirtual |
Returns connection handler's perception of whether we open or not.
It is unsafe to just close underlying socket because of the race, emerging due to the fact that the socket can linger for a while.
Definition at line 247 of file server.hpp.
|
inlinevirtual |
Reimplemented in CServer_Connection.
Definition at line 73 of file server_connection.hpp.
Referenced by CServer_ConnectionPool::GetPollAndTimerVec().
|
inlinevirtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 105 of file server_connection.hpp.
References CServer_Connection::m_Handler.
|
inlinevirtual |
Returns the handler's readiness to process input data or to write some output data.
OnRead() and OnWrite() are not called unless this method return true.
Definition at line 252 of file server.hpp.
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT m_AcceptTimeout | ( | kInfiniteTimeout | ) |
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT m_MaxThreads | ( | 10 | ) |
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT m_Port | ( | port | ) |
Definition at line 84 of file threaded_server.hpp.
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT m_QueueSize | ( | 20 | ) |
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT m_SpawnThreshold | ( | 1 | ) |
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT m_TemporarilyStopListening | ( | false | ) |
CServer_Exception::NCBI_EXCEPTION_DEFAULT | ( | CServer_Exception | , |
CConnException | |||
) |
CThreadedServerException::NCBI_EXCEPTION_DEFAULT | ( | CThreadedServerException | , |
CConnException | |||
) |
|
inlinevirtual |
The connection has closed (with information on type of closing)
Reimplemented in CNetStorageHandler, and CNetScheduleHandler.
Definition at line 274 of file server.hpp.
Referenced by IServer_MessageHandler::OnRead().
Runs when a socket error is detected.
Reimplemented in CNetScheduleHandler.
Definition at line 291 of file server.hpp.
Referenced by IServer_MessageHandler::OnRead().
|
inlinevirtual |
Return desired action if the port, mentioned in AddListener is busy.
If the action is eLARetry, provide new port. The
Reimplemented in CWNCTConnectionFactory.
Definition at line 403 of file server.hpp.
References IServer_ConnectionFactory::eLAFail.
|
pure virtual |
Implemented in CWNCTConnectionHandler, CNetScheduleHandler, and CBDBEnvKeeperConnectionHandler.
Referenced by IServer_MessageHandler::OnRead().
|
pure virtual |
Runs in response to an external event [asynchronous].
You can get socket by calling GetSocket(), if you close the socket this object will be destroyed. Individual events are: A client has just established this connection.
Implemented in CWNCTConnectionHandler, CNetStorageHandler, CNetScheduleHandler, and CBDBEnvKeeperConnectionHandler.
|
inlinevirtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 102 of file server_connection.hpp.
References CServer_Connection::m_Handler.
Referenced by CAcceptRequest::Cancel(), CServerConnectionRequest::Cancel(), and CAcceptRequest::x_DoProcess().
|
inlinevirtual |
Reimplemented in CServer_Connection.
Definition at line 76 of file server_connection.hpp.
|
inlinevirtual |
Runs when there are insufficient resources to queue a connection, prior to closing it.
Provides a reason why the connection is being close, which can be reported back to the client.
Reimplemented in CNetStorageHandler, and CNetScheduleHandler.
Definition at line 288 of file server.hpp.
|
virtual |
The client has just sent data.
Implements IServer_ConnectionHandler.
Definition at line 55 of file server.cpp.
References IServer_MessageHandler::CheckMessage(), conn, eActiveSocket, IServer_ConnectionHandler::eClientClose, eIO_Success, eIO_Timeout, CSocket::GetPeerAddress(), IServer_ConnectionHandler::GetSocket(), int, IO_StatusStr(), IServer_MessageHandler::m_Buffer, NStr::NumericToString(), IServer_ConnectionHandler::OnClose(), IServer_ConnectionHandler::OnError(), IServer_MessageHandler::OnMessage(), IServer_ConnectionHandler::OnTimeout(), CSocket::Read(), read_buf(), and string.
|
pure virtual |
The client has just sent data.
Implemented in CNetStorageHandler, and IServer_MessageHandler.
void CServer_Connection::OnSocketEvent | ( | EServIO_Event | event | ) |
Definition at line 533 of file server.cpp.
References IServer_ConnectionHandler::eClientClose, IServer_ConnectionHandler::eOurClose, eServIO_Alarm, eServIO_ClientClose, eServIO_Delete, eServIO_Inactivity, eServIO_Open, eServIO_OurClose, eServIO_Read, eServIO_Write, CServer_Connection::m_Handler, CServer_Connection::m_Open, and CServer_Connection::OnTimeout().
Referenced by CServer_ConnectionPool::CloseConnection(), CAcceptRequest::x_DoProcess(), and CServerConnectionRequest::x_Process().
|
inlinevirtual |
Reimplemented in CServer_Connection.
Definition at line 74 of file server_connection.hpp.
|
inlinevirtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 101 of file server_connection.hpp.
References CServer_Connection::m_Handler.
Referenced by CServer_Connection::OnSocketEvent().
|
inlinevirtual |
Runs when a client has been idle for too long, prior to closing the connection [synchronous].
Reimplemented in CNetStorageHandler, and CNetScheduleHandler.
Definition at line 278 of file server.hpp.
Referenced by IServer_MessageHandler::OnRead().
|
inlinevirtual |
Definition at line 75 of file server_connection.hpp.
|
inlinevirtual |
This method is called at the moment in time specified earlier by the alarm_time parameter of the GetEventsToPollFor method [synchronous].
Definition at line 282 of file server.hpp.
|
pure virtual |
The client is ready to receive data.
Implemented in CNetStorageHandler, CNetScheduleHandler, CBDBEnvKeeperConnectionHandler, and CWNCTConnectionHandler.
|
private |
|
inlinevirtual |
Reimplemented in CServer_Listener.
Definition at line 78 of file server_connection.hpp.
|
inlinevirtual |
Reimplemented from IServer_ConnectionBase.
Definition at line 141 of file server_connection.hpp.
References CListeningSocket::Close().
void CServer_ConnectionPool::PingControlConnection | ( | void | ) |
Definition at line 202 of file connection_pool.cpp.
References eIO_Success, ERR_POST_X, IO_StatusStr(), CServer_ConnectionPool::m_ControlTrigger, CTrigger::Set(), and Warning().
Referenced by CServer_ConnectionPool::Add(), CServer_ConnectionPool::RemoveListener(), CServer_ConnectionPool::SetConnType(), and CServer::WakeUpPollCycle().
|
pure virtual |
Runs asynchronously (from a separate thread) for each request.
Implementor must take care of closing the socket when done. (Using it as the basis of a CConn_SocketStream object will do so automatically.)
Referenced by CId1ReaderBase::LoadBlob(), CId2ReaderBase::LoadBlob(), CId2ReaderBase::LoadBlobs(), and CwxNCBIApp::OnIdle().
|
protectedvirtual |
Runs synchronously when request queue is full.
Implementor must take care of closing socket when done.
Definition at line 112 of file threaded_server.hpp.
References SOCK_Close().
|
inlineprotectedvirtual |
Runs synchronously when no socket activity has occurred in a while (as determined by m_AcceptTimeout).
Reimplemented in CWorkerNodeControlServer.
Definition at line 186 of file server.hpp.
Referenced by CServer::x_DoRun().
|
protectedvirtual |
Runs synchronously when accept has timed out.
Definition at line 115 of file threaded_server.hpp.
void CServer_ConnectionPool::Remove | ( | TConnBase * | conn | ) |
Definition at line 128 of file connection_pool.cpp.
References conn, set< Key, Compare >::erase(), CServer_ConnectionPool::m_Data, and CServer_ConnectionPool::m_Mutex.
Referenced by CServer::RemoveConnectionFromPool().
void CServer::RemoveConnectionFromPool | ( | CServer_Connection * | conn | ) |
Remove externally created connection from pool.
Definition at line 832 of file server.cpp.
References conn, CServer::m_ConnectionPool, and CServer_ConnectionPool::Remove().
bool CServer::RemoveListener | ( | unsigned short | port | ) |
Removes a listener.
port | the listener on the port will be removed |
Definition at line 612 of file server.cpp.
References CServer::m_ConnectionPool, and CServer_ConnectionPool::RemoveListener().
bool CServer_ConnectionPool::RemoveListener | ( | unsigned short | port | ) |
Definition at line 135 of file connection_pool.cpp.
References eListener, ERR_POST, CServer_Listener::GetPort(), ITERATE, CFastMutex::Lock(), CServer_ConnectionPool::m_Data, CServer_ConnectionPool::m_ListenerPortsToStop, CServer_ConnectionPool::m_Mutex, CServer_ConnectionPool::PingControlConnection(), IServer_ConnectionBase::type, IServer_ConnectionBase::type_lock, CFastMutex::Unlock(), and Warning().
Referenced by CServer::RemoveListener().
void CServer::Run | ( | void | ) |
Enter the main loop.
Definition at line 771 of file server.cpp.
References CServer_ConnectionPool::Erase(), ERR_POST, CServer::Exit(), CPoolOfThreads_ForServer::KillAllThreads(), CServer::m_ConnectionPool, CServer::m_Parameters, CServer::m_ThreadPool, CServer::m_ThreadSuffix, SServer_Parameters::max_threads, s_ServerCatchExceptions, CServer::StartListening(), CServer_ConnectionPool::StopListening(), and CServer::x_DoRun().
Referenced by CGridControlThread::Main(), and CBDBEnvKeeperApp::Run().
void Run | ( | void | ) |
Enter the main loop.
Referenced by CCompartmentAccessor< THit >::CCompartmentAccessor(), and CTbl2AsnApp::DryRun().
|
virtual |
Send message.
Implements IServer_Monitor.
Definition at line 104 of file server_monitor.cpp.
References msg(), and CServer_Monitor::SendMessage().
|
pure virtual |
Send message.
Implemented in CServer_Monitor.
Referenced by CBDB_Cache::EvaluateTimeLine(), CBDB_Env::MempTrickle(), CBDB_Cache::Purge(), and CBDB_Cache::x_Store().
Send message.
Implements IServer_Monitor.
Definition at line 109 of file server_monitor.cpp.
References CServer_Monitor::SendString(), and str().
Send message.
Implemented in CServer_Monitor.
void CServer_Monitor::SendMessage | ( | const char * | msg, |
size_t | length | ||
) |
Definition at line 82 of file server_monitor.cpp.
References eIO_Success, CServer_Monitor::m_Lock, CServer_Monitor::m_Sock, msg(), st(), and CSocket::Write().
Referenced by CServer_Monitor::Send(), and CServer_Monitor::SendString().
Definition at line 93 of file server_monitor.cpp.
References CServer_Monitor::SendMessage(), and str().
Referenced by CServer_Monitor::Send(), CServer_Monitor::SetSocket(), and CServer_Monitor::~CServer_Monitor().
Definition at line 103 of file server.cpp.
References BUF_Write(), buffer, data, int, msg(), n, and ncbi::grid::netcache::search::fields::size.
Referenced by IServer_LineMessageHandler::CheckMessage().
void CServer_ConnectionPool::SetAllActive | ( | const vector< CSocketAPI::SPoll > & | polls | ) |
Definition at line 361 of file connection_pool.cpp.
References abort(), eActiveSocket, eInactiveSocket, eListener, ITERATE, CFastMutex::Lock(), IServer_ConnectionBase::type, IServer_ConnectionBase::type_lock, and CFastMutex::Unlock().
Referenced by CServer::x_DoRun().
void CServer_ConnectionPool::SetAllActive | ( | const vector< IServer_ConnectionBase * > & | conns | ) |
Definition at line 383 of file connection_pool.cpp.
References abort(), eActiveSocket, eInactiveSocket, ITERATE, CFastMutex::Lock(), IServer_ConnectionBase::type, IServer_ConnectionBase::type_lock, and CFastMutex::Unlock().
void CServer_ConnectionPool::SetConnType | ( | TConnBase * | conn, |
EServerConnType | type | ||
) |
Guard connection from out-of-order packet processing by pulling eActiveSocket's from poll vector Resets the expiration time as a bonus.
Definition at line 179 of file connection_pool.cpp.
References conn, eClosedSocket, eDeferredSocket, eInactiveSocket, ePreClosedSocket, ePreDeferredSocket, CServer_ConnectionPool::PingControlConnection(), type, and CServer_ConnectionPool::x_UpdateExpiration().
Referenced by CServerConnectionRequest::Cancel(), CServer::DeferConnectionProcessing(), CServerConnectionRequest::Process(), and CAcceptRequest::x_DoProcess().
Set custom suffix to use on all threads in the server's pool.
Value can be set only before call to Run(), any change of the value after call to Run() will be ignored.
Definition at line 161 of file server.hpp.
References CServer::m_ThreadSuffix.
|
inline |
Definition at line 59 of file connection_pool.hpp.
References CServer_ConnectionPool::m_MaxConnections.
Referenced by CServer::SetParameters().
void CServer::SetParameters | ( | const SServer_Parameters & | new_params | ) |
Definition at line 618 of file server.cpp.
References SServer_Parameters::init_threads, CServer::m_ConnectionPool, CServer::m_Parameters, SServer_Parameters::max_connections, SServer_Parameters::max_threads, NCBI_THROW, and CServer_ConnectionPool::SetMaxConnections().
Referenced by CWorkerNodeControlServer::CWorkerNodeControlServer(), CBDBEnvKeeperApp::Run(), CNetScheduleServer::SetNSParameters(), and CNetStorageServer::SetParameters().
|
protectedvirtual |
Called at the beginning of Run, before creating thread pool.
Definition at line 121 of file threaded_server.hpp.
Referenced by BOOST_AUTO_TEST_CASE(), CClustererApplication::x_RunBinary(), and CClustererApplication::x_RunSparse().
void CServer_Monitor::SetSocket | ( | CSocket & | socket | ) |
Pass open socket for monitor output.
The original socket is empty afterwards, ownership is handled by monitor. It activates the monitor.
Definition at line 50 of file server_monitor.cpp.
References eCopyTimeoutsFromSOCK, eCopyTimeoutsToSOCK, eNoOwnership, eTakeOwnership, CSocket::GetSOCK(), CServer_Monitor::m_Lock, CServer_Monitor::m_Sock, CSocket::Reset(), CServer_Monitor::SendString(), and CSocket::SetOwnership().
|
inline |
Definition at line 298 of file server.hpp.
References IServer_ConnectionHandler::m_Socket.
|
inlineprotectedvirtual |
Runs synchronously between iterations.
Reimplemented in CWorkerNodeControlServer, CNetStorageServer, CNetScheduleServer, and CBDBEnvKeeperServer.
Definition at line 191 of file server.hpp.
Referenced by CServer::x_DoRun().
|
protectedvirtual |
Runs synchronously between iterations.
Definition at line 118 of file threaded_server.hpp.
SServer_Parameters::SServer_Parameters | ( | ) |
Create structure with the default set of parameters.
Definition at line 852 of file server.cpp.
void CServer::StartListening | ( | void | ) |
Start listening before the main loop.
If called, tries to listen on all requested ports for all listeners, correcting errors by calling listeners' OnFailure
Definition at line 637 of file server.cpp.
References CServer::m_ConnectionPool, and CServer_ConnectionPool::StartListening().
Referenced by CGridControlThread::Prepare(), and CServer::Run().
void StartListening | ( | void | ) |
Start listening immediately, or throw an exception if it is impossible to do so.
(Does nothing if *this* object is already listening on the port.) Calling StartListening() before Run() will permit detecting port-in-use problems before the last minute. (On the other hand, clients that attempt to connect in the interim will get no response until the main loop actually starts.)
void CServer_ConnectionPool::StartListening | ( | void | ) |
Definition at line 396 of file connection_pool.cpp.
References ITERATE, CServer_ConnectionPool::m_Data, CServer_ConnectionPool::m_ListeningStarted, and CServer_ConnectionPool::m_Mutex.
Referenced by CServer::StartListening().
void CServer_ConnectionPool::StopListening | ( | void | ) |
Definition at line 406 of file connection_pool.cpp.
References ITERATE, CServer_ConnectionPool::m_Data, and CServer_ConnectionPool::m_Mutex.
Referenced by CServer::Run().
void CServer::SubmitRequest | ( | const CRef< CStdRequest > & | request | ) |
Submit request to be executed by the server thread pool.
Definition at line 805 of file server.cpp.
References CPoolOfThreads_ForServer::AcceptRequest(), CServer::m_ThreadPool, and NULL.
void CServer::WakeUpPollCycle | ( | void | ) |
Force poll cycle to make another iteration.
Should be called if IsReadyToProcess() for some connection handler became true.
Definition at line 837 of file server.cpp.
References CServer::m_ConnectionPool, and CServer_ConnectionPool::PingControlConnection().
Referenced by CNetStorageHandler::x_SendAsyncMessage().
|
private |
Definition at line 656 of file server.cpp.
References _ASSERT, SServer_Parameters::accept_timeout, CPoolOfThreads_ForServer::AcceptRequest(), count, IServer_ConnectionBase::CreateRequest(), Critical(), eIO_Success, eIO_Timeout, ERR_POST_X, eServIO_Alarm, eServIO_Delete, eServIO_Inactivity, IServer_ConnectionBase::GetEventsToPollFor(), CServer_ConnectionPool::GetPollAndTimerVec(), SServer_Parameters::idle_timeout, CServer::Init(), NStr::IntToString(), IO_StatusStr(), IOEventToServIOEvent(), ITERATE, kDefaultTimeout, kInfiniteTimeout, CServer::m_ConnectionPool, CServer::m_Parameters, CServer::m_ThreadPool, SServer_Parameters::max_threads, NULL, CSocketAPI::Poll(), CServer::ProcessTimeout(), CTrigger::Reset(), CServer_ConnectionPool::SetAllActive(), CServer::ShutdownRequested(), CPoolOfThreads_ForServer::Spawn(), and NStr::UIntToString().
Referenced by CServer::Run().
|
private |
Definition at line 83 of file connection_pool.cpp.
References conn, CTime::eIgnoreDaylight, eIO_ReadWrite, GetFastLocalTime(), CSocket::GetTimeout(), kDefaultTimeout, kInfiniteTimeout, STimeoutTag::sec, and STimeoutTag::usec.
Referenced by CServer_ConnectionPool::Add(), and CServer_ConnectionPool::SetConnType().
|
virtual |
Definition at line 594 of file server.cpp.
References CServer::m_ConnectionPool, CServer::m_Parameters, CServer::m_ThreadPool, and NULL.
|
virtual |
Definition at line 567 of file server.cpp.
References eIO_Close, and CSocket::SetTimeout().
CServer_ConnectionPool::~CServer_ConnectionPool | ( | ) |
Definition at line 63 of file connection_pool.cpp.
References CServer_ConnectionPool::Erase().
|
virtual |
Definition at line 43 of file server_monitor.cpp.
References CServer_Monitor::m_Sock, and CServer_Monitor::SendString().
|
virtual |
Definition at line 86 of file threaded_server.hpp.
|
inlinevirtual |
Definition at line 66 of file server_connection.hpp.
|
inlinevirtual |
Definition at line 396 of file server.hpp.
|
inlinevirtual |
Definition at line 228 of file server.hpp.
|
inlinevirtual |
Definition at line 318 of file server.hpp.
References BUF_Destroy(), and IServer_MessageHandler::m_Buffer.
|
inlinevirtual |
Definition at line 50 of file server_monitor.hpp.
Maximum t between exit checks.
Definition at line 440 of file server.hpp.
Referenced by CWorkerNodeControlServer::CWorkerNodeControlServer(), CBDBEnvKeeperApp::Run(), CNetScheduleDApp::Run(), CNetStorageDApp::Run(), and CServer::x_DoRun().
NCBI_DEPRECATED_CLASS NCBI_XCONNECT_EXPORT CThreadedServer |
CThreadedServer - abstract class for network servers using thread pools.
This code maintains a pool of threads (initially m_InitThreads, but potentially as many as m_MaxThreads) to deal with incoming connections; each connection gets assigned to one of the worker threads, allowing the server to handle multiple requests in parallel while still checking for new requests.
You must define Process() to indicate what to do with each incoming connection; .../src/connect/test_threaded_server.cpp illustrates how you might do this.
Definition at line 77 of file threaded_server.hpp.
|
private |
Definition at line 84 of file server_connection.hpp.
Referenced by CServer_ConnectionPool::GetPollAndTimerVec().
For how long to keep inactive non-listening sockets open (default: 10 minutes)
Definition at line 443 of file server.hpp.
Referenced by CServer::x_DoRun().
unsigned int SServer_Parameters::init_threads |
Number of initial threads.
Definition at line 446 of file server.hpp.
Referenced by CWorkerNodeControlServer::CWorkerNodeControlServer(), SNS_Parameters::Read(), SNetStorageServerParameters::Read(), CBDBEnvKeeperApp::Run(), CServer::SetParameters(), and CNetScheduleHandler::x_GetServerSection().
Maximum time between exit checks.
Definition at line 129 of file threaded_server.hpp.
|
private |
Definition at line 332 of file server.hpp.
Referenced by IServer_MessageHandler::OnRead(), and IServer_MessageHandler::~IServer_MessageHandler().
|
private |
Definition at line 200 of file server.hpp.
Referenced by CServer::AddConnectionToPool(), CServer::AddListener(), CServer::CloseConnection(), CServer::CServer(), CServer::DeferConnectionProcessing(), CServer::GetListenerPorts(), CServer::RemoveConnectionFromPool(), CServer::RemoveListener(), CServer::Run(), CServer::SetParameters(), CServer::StartListening(), CServer::WakeUpPollCycle(), CServer::x_DoRun(), and CServer::~CServer().
|
mutableprivate |
Definition at line 105 of file connection_pool.hpp.
Referenced by CServer_ConnectionPool::GetPollAndTimerVec(), and CServer_ConnectionPool::PingControlConnection().
|
private |
Definition at line 102 of file connection_pool.hpp.
Referenced by CServer_ConnectionPool::Add(), CServer_ConnectionPool::Erase(), CServer_ConnectionPool::GetListenerPorts(), CServer_ConnectionPool::GetPollAndTimerVec(), CServer_ConnectionPool::Remove(), CServer_ConnectionPool::RemoveListener(), CServer_ConnectionPool::StartListening(), and CServer_ConnectionPool::StopListening().
|
private |
Definition at line 145 of file server_connection.hpp.
Referenced by CServer_Listener::Activate(), and CAcceptRequest::CAcceptRequest().
|
private |
|
protected |
Settings for thread pool (which is local to Run):
Number of initial threads
Definition at line 125 of file threaded_server.hpp.
|
private |
Definition at line 113 of file connection_pool.hpp.
Referenced by CServer_ConnectionPool::GetListenerPorts(), CServer_ConnectionPool::GetPollAndTimerVec(), and CServer_ConnectionPool::RemoveListener().
|
private |
Definition at line 114 of file connection_pool.hpp.
Referenced by CServer_ConnectionPool::Add(), and CServer_ConnectionPool::StartListening().
|
private |
Definition at line 89 of file server_monitor.hpp.
Referenced by CServer_Monitor::IsMonitorActive(), CServer_Monitor::SendMessage(), and CServer_Monitor::SetSocket().
|
private |
Listening socket.
Definition at line 136 of file threaded_server.hpp.
|
private |
Definition at line 104 of file connection_pool.hpp.
Referenced by CServer_ConnectionPool::Add(), and CServer_ConnectionPool::SetMaxConnections().
|
protected |
Maximum simultaneous threads.
Definition at line 126 of file threaded_server.hpp.
Referenced by CPoolOfThreads< TRequest >::HasImmediateRoom(), and CPoolOfThreads< TRequest >::x_AcceptRequest().
|
mutableprivate |
Definition at line 103 of file connection_pool.hpp.
Referenced by CServer_ConnectionPool::Add(), CServer_ConnectionPool::Erase(), CServer_ConnectionPool::GetListenerPorts(), CServer_ConnectionPool::GetPollAndTimerVec(), CServer_ConnectionPool::Remove(), CServer_ConnectionPool::RemoveListener(), CServer_ConnectionPool::StartListening(), and CServer_ConnectionPool::StopListening().
|
private |
Definition at line 114 of file server_connection.hpp.
Referenced by CServer_Connection::IsOpen(), and CServer_Connection::OnSocketEvent().
|
private |
Definition at line 199 of file server.hpp.
Referenced by CServer::CServer(), CServer::GetParameters(), CServer::Run(), CServer::SetParameters(), CServer::x_DoRun(), and CServer::~CServer().
|
private |
Definition at line 146 of file server_connection.hpp.
Referenced by CServer_Listener::Activate(), and CServer_Listener::GetPort().
|
private |
TCP port to listen on.
Definition at line 135 of file threaded_server.hpp.
Referenced by CGLTestWMClient::CGLTestWMClient(), CNetScheduleKeyGenerator::CNetScheduleKeyGenerator(), CRulerDemoPanel::CRulerDemoPanel(), CNetScheduleKeyGenerator::GenerateCompoundID(), GetPort(), CNSNotificationList::Notify(), and wx__DECLARE_EVT1().
|
protected |
Maximum size of request queue.
Definition at line 127 of file threaded_server.hpp.
|
private |
Definition at line 356 of file server.hpp.
Referenced by IServer_LineMessageHandler::CheckMessage().
|
private |
Definition at line 90 of file server_monitor.hpp.
Referenced by CServer_Monitor::IsMonitorActive(), CServer_Monitor::SendMessage(), CServer_Monitor::SetSocket(), and CServer_Monitor::~CServer_Monitor().
|
private |
Definition at line 301 of file server.hpp.
Referenced by IServer_ConnectionHandler::GetSocket(), and IServer_ConnectionHandler::SetSocket().
|
protected |
Controls when to spawn more threads.
Definition at line 128 of file threaded_server.hpp.
|
private |
Definition at line 372 of file server.hpp.
|
protected |
Temporarily close listener when queue fills?
Definition at line 132 of file threaded_server.hpp.
|
private |
Definition at line 201 of file server.hpp.
Referenced by CServer::GetThreadPool(), CServer::Run(), CServer::SubmitRequest(), CServer::x_DoRun(), and CServer::~CServer().
|
private |
Definition at line 202 of file server.hpp.
Referenced by CServer::Run(), and CServer::SetCustomThreadSuffix().
unsigned int SServer_Parameters::max_connections |
Maximum # of open connections.
Definition at line 436 of file server.hpp.
Referenced by CServer::CServer(), SNS_Parameters::Read(), SNetStorageServerParameters::Read(), CNetScheduleServer::SetNSParameters(), CNetStorageServer::SetParameters(), CServer::SetParameters(), and CNetScheduleHandler::x_GetServerSection().
unsigned int SServer_Parameters::max_threads |
Maximum simultaneous threads.
Definition at line 447 of file server.hpp.
Referenced by CWorkerNodeControlServer::CWorkerNodeControlServer(), SNS_Parameters::Read(), SNetStorageServerParameters::Read(), CServer::Run(), CBDBEnvKeeperApp::Run(), CServer::SetParameters(), CServer::x_DoRun(), and CNetScheduleHandler::x_GetServerSection().
unsigned int SServer_Parameters::spawn_threshold |
Controls when to spawn more threads.
Definition at line 448 of file server.hpp.
bool SServer_Parameters::temporarily_stop_listening |
Temporarily close listener when queue fills?
Definition at line 438 of file server.hpp.
|
private |
Definition at line 86 of file server_connection.hpp.
Referenced by CServer_ConnectionPool::GetListenerPorts(), CServer_ConnectionPool::GetPollAndTimerVec(), CServer_ConnectionPool::RemoveListener(), and CServer_ConnectionPool::SetAllActive().
|
private |
Definition at line 85 of file server_connection.hpp.
Referenced by CServer_ConnectionPool::GetListenerPorts(), CServer_ConnectionPool::GetPollAndTimerVec(), CServer_ConnectionPool::RemoveListener(), and CServer_ConnectionPool::SetAllActive().
|
friend |
Definition at line 144 of file server_connection.hpp.
Referenced by CServer_Listener::CreateRequest().
|
friend |
Definition at line 196 of file server.hpp.
|
friend |
Definition at line 297 of file server.hpp.
|
friend |
Definition at line 81 of file server_connection.hpp.
|
friend |
Definition at line 82 of file server_connection.hpp.