1 #ifndef CONNECT___SERVER__HPP
2 #define CONNECT___SERVER__HPP
82 class CNetCacheServer;
105 unsigned short port);
113 bool RemoveListener(
unsigned short port);
135 void DeferConnectionProcessing(
CSocket* sock);
142 void CloseConnection(
CSocket* sock);
157 void WakeUpPollCycle(
void);
162 { m_ThreadSuffix = suffix; }
167 vector<unsigned short> GetListenerPorts(
void);
196 friend class CNetCacheServer;
319 virtual void OnRead(
void);
416 template <
class TServer_ConnectionHandler>
421 {
return new TServer_ConnectionHandler(); }
472 virtual const char* GetErrCodeString(
void)
const override;
Helper hook-up class that installs default logging/registry/locking (but only if they have not yet be...
This stream exchanges data in a TCP channel, using the SOCK socket API.
CServer_ConnectionFactory::
IServer_ConnectionFactory::
IServer_ConnectionHandler::
IServer_LineMessageHandler::
static CS_CONNECTION * conn
void BUF_Destroy(BUF buf)
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::iostream CNcbiIostream
Portable alias for iostream.
virtual void Init()
Initialize the server.
virtual bool ShutdownRequested(void)
Runs synchronously between iterations.
virtual void OnOverflow(EOverflowReason)
Runs when there are insufficient resources to queue a connection, prior to closing it.
EServIO_Event
Extended copy of the type EIO_Event allowing to distinguish between connection closing from client an...
virtual void Exit()
Cleanup the server.
virtual EIO_Event GetEventsToPollFor(const CTime **) const
Following three methods are guaranteed to be called NOT at the same time as On*, so if you implement ...
virtual void OnRead(void)=0
The client has just sent data.
virtual const STimeout * GetTimeout(void)
Returns the timeout for this connection.
virtual int CheckMessage(BUF *buffer, const void *data, size_t size)=0
virtual void OnOpen(void)=0
Runs in response to an external event [asynchronous].
virtual void OnClose(EClosePeer)
The connection has closed (with information on type of closing)
EListenAction
What to do if the port is busy.
NCBI_EXCEPTION_DEFAULT(CServer_Exception, CConnException)
EClosePeer
Type of connection closing.
void SetCustomThreadSuffix(const string &suffix)
Set custom suffix to use on all threads in the server's pool.
SServer_Parameters * m_Parameters
CNcbiIostream & GetStream()
unsigned int spawn_threshold
Controls when to spawn more threads.
const STimeout * accept_timeout
Maximum t between exit checks.
virtual IServer_ConnectionHandler * Create(void)=0
void Run(void)
Enter the main loop.
virtual EListenAction OnFailure(unsigned short *)
Return desired action if the port, mentioned in AddListener is busy.
EOverflowReason
Error codes for OnOverflow method in IServer_ConnectionHandler.
virtual void OnError(const string &)
Runs when a socket error is detected.
CPoolOfThreads_ForServer * m_ThreadPool
bool temporarily_stop_listening
Temporarily close listener when queue fills?
void StartListening(void)
Start listening immediately, or throw an exception if it is impossible to do so.
CPoolOfThreads_ForServer * GetThreadPool(void)
virtual void OnTimer(void)
This method is called at the moment in time specified earlier by the alarm_time parameter of the GetE...
virtual ~IServer_ConnectionHandler()
unsigned int max_threads
Maximum simultaneous threads.
EServIO_Event IOEventToServIOEvent(EIO_Event event)
Transform EIO_Event type to EServIO_Event.
CConn_SocketStream m_Stream
virtual bool IsOpen(void)
Returns connection handler's perception of whether we open or not.
virtual void OnMessage(BUF buffer)=0
IServer_LineMessageHandler()
CServer_ConnectionPool * m_ConnectionPool
virtual int CheckMessage(BUF *buffer, const void *data, size_t size)
void SetSocket(CSocket *socket)
unsigned int max_connections
Maximum # of open connections.
int Server_CheckLineMessage(BUF *buffer, const void *data, size_t size, bool &seen_CR)
virtual bool IsReadyToProcess(void) const
Returns the handler's readiness to process input data or to write some output data.
virtual void ProcessTimeout(void)
Runs synchronously when no socket activity has occurred in a while (as determined by m_AcceptTimeout)...
CSocket & GetSocket(void)
Get underlying socket.
virtual void OnTimeout(void)
Runs when a client has been idle for too long, prior to closing the connection [synchronous].
virtual IServer_ConnectionHandler * Create()
virtual void OnWrite(void)=0
The client is ready to receive data.
unsigned int init_threads
Number of initial threads.
const STimeout * idle_timeout
For how long to keep inactive non-listening sockets open (default: 10 minutes)
virtual ~IServer_MessageHandler()
virtual ~IServer_ConnectionFactory()
@ eServIO_ReadWrite
eIO_Read | eIO_Write
@ eOurClose
Connection closed by ourselves.
@ eBadParameters
Out-of-range parameters given.
@ eCouldntListen
Unable to bind listening port.
EIO_Event
I/O event (or direction).
#define NCBI_XCONNECT_EXPORT
const struct ncbi::grid::netcache::search::fields::SIZE size