NCBI C++ ToolKit
Classes | Enumerations | Functions | Variables
Threaded Server
CONNECT
+ Collaboration diagram for Threaded Server:

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_ControlConnection
class  CServer_ConnectionPool

Enumerations

enum  EServerConnType {
  eInactiveSocket, eActiveSocket, eListener, ePreDeferredSocket,
  eDeferredSocket, ePreClosedSocket, eClosedSocket
}
enum  EServIO_Event {
  eServIO_Open = 0x00, eServIO_Read = 0x01, eServIO_Write = 0x02, eServIO_ReadWrite = 0x03,
  eServIO_ClientClose = 0x04, eServIO_OurClose = 0x08, eServIO_Inactivity = 0x10, eServIO_Delete = 0x20
}
 Extended copy of the type EIO_Event allowing to distinguish between connection closing from client and from ourselves. More...
enum  EOverflowReason { eOR_Unknown = 0, eOR_ConnectionPoolFull, eOR_RequestQueueFull, eOR_UnpollableSocket }
 Error codes for OnOverflow method in IServer_ConnectionHandler. More...

Functions

EServIO_Event IOEventToServIOEvent (EIO_Event event)
 Transform EIO_Event type to EServIO_Event.
int Server_CheckLineMessage (BUF *buffer, const void *data, size_t size, bool &seen_CR)
NCBI_DEPRECATED_CLASS
NCBI_XCONNECT_EXPORT 
m_MaxThreads (10)
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_AcceptTimeout (kInfiniteTimeout)
NCBI_DEPRECATED_CLASS
NCBI_XCONNECT_EXPORT 
m_TemporarilyStopListening (false)
NCBI_DEPRECATED_CLASS
NCBI_XCONNECT_EXPORT 
m_Port (port)
virtual ~CThreadedServer ()
void Run (void)
 Enter the main loop.
void StartListening (void)
 Start listening immediately, or throw an exception if it is impossible to do so.
virtual void Process (SOCK sock)=0
 Runs asynchronously (from a separate thread) for each request.
unsigned short GetPort () const
 Get the listening port number back.
virtual void ProcessOverflow (SOCK sock)
 Runs synchronously when request queue is full.
virtual void ProcessTimeout (void)
 Runs synchronously when accept has timed out.
virtual bool ShutdownRequested (void)
 Runs synchronously between iterations.
virtual void SetParams ()
 Called at the beginning of Run, before creating thread pool.

Variables

NCBI_DEPRECATED_CLASS
NCBI_XCONNECT_EXPORT 
CThreadedServer
 CThreadedServer - abstract class for network servers using thread pools.
unsigned int m_InitThreads
 Settings for thread pool (which is local to Run):
unsigned int m_MaxThreads
 Maximum simultaneous threads.
unsigned int m_QueueSize
 Maximum size of request queue.
unsigned int m_SpawnThreshold
 Controls when to spawn more threads.
const STimeoutm_AcceptTimeout
 Maximum time between exit checks.
bool m_TemporarilyStopListening
 Temporarily close listener when queue fills?
unsigned short m_Port
 TCP port to listen on.
CListeningSocket m_LSock
 Listening socket.

Enumeration Type Documentation

Error codes for OnOverflow method in IServer_ConnectionHandler.

Enumerator:
eOR_Unknown 
eOR_ConnectionPoolFull 
eOR_RequestQueueFull 
eOR_UnpollableSocket 

Definition at line 196 of file server.hpp.

Enumerator:
eInactiveSocket 
eActiveSocket 
eListener 
ePreDeferredSocket 
eDeferredSocket 
ePreClosedSocket 
eClosedSocket 

Definition at line 48 of file server_connection.hpp.

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 

Definition at line 61 of file server.hpp.


Function Documentation

unsigned short GetPort ( ) const

Transform EIO_Event type to EServIO_Event.

Definition at line 75 of file server.hpp.

Referenced by CServer::x_DoRun().

Definition at line 85 of file threaded_server.hpp.

virtual void Process ( SOCK  sock) [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(), and CId2ReaderBase::LoadBlobs().

virtual void ProcessOverflow ( SOCK  sock) [protected, virtual]

Runs synchronously when request queue is full.

Implementor must take care of closing socket when done.

Definition at line 113 of file threaded_server.hpp.

References SOCK_Close().

virtual void ProcessTimeout ( void  ) [protected, virtual]

Runs synchronously when accept has timed out.

Definition at line 116 of file threaded_server.hpp.

void Run ( void  )

Enter the main loop.

Referenced by CCompartmentAccessor< THit >::CCompartmentAccessor().

int Server_CheckLineMessage ( BUF buffer,
const void *  data,
size_t  size,
bool seen_CR 
)

Definition at line 98 of file server.cpp.

References BUF_Write(), int, and size.

Referenced by IServer_LineMessageHandler::CheckMessage().

virtual void SetParams ( ) [protected, virtual]

Called at the beginning of Run, before creating thread pool.

Definition at line 122 of file threaded_server.hpp.

Referenced by BOOST_AUTO_TEST_CASE(), CClustererApplication::x_RunBinary(), and CClustererApplication::x_RunSparse().

virtual bool ShutdownRequested ( void  ) [protected, virtual]

Runs synchronously between iterations.

Definition at line 119 of file threaded_server.hpp.

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.)

virtual ~CThreadedServer ( ) [virtual]

Definition at line 87 of file threaded_server.hpp.


Variable Documentation

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.

Deprecated:
Use CServer instead.

Definition at line 83 of file threaded_server.hpp.

Maximum time between exit checks.

Definition at line 130 of file threaded_server.hpp.

unsigned int m_InitThreads

Settings for thread pool (which is local to Run):

Number of initial threads

Definition at line 126 of file threaded_server.hpp.

Listening socket.

Definition at line 137 of file threaded_server.hpp.

unsigned int m_MaxThreads
unsigned short m_Port
unsigned int m_QueueSize

Maximum size of request queue.

Definition at line 128 of file threaded_server.hpp.

Controls when to spawn more threads.

Definition at line 129 of file threaded_server.hpp.

Temporarily close listener when queue fills?

Definition at line 133 of file threaded_server.hpp.

Modified on Fri Aug 22 18:18:44 2014 by modify_doxy.py rev. 426318