NCBI C++ ToolKit
connection_pool.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CONNECT___CONNECTION_POOL__HPP
2 #define CONNECT___CONNECTION_POOL__HPP
3 
4 /* $Id: connection_pool.hpp 73499 2016-07-11 15:26:50Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Aaron Ucko, Victor Joukov
30  *
31  */
32 
33 /// @file connection_pool.hpp
34 /// Internal header for threaded server connection pools.
35 
36 
38 
39 
40 /** @addtogroup ThreadedServer
41  *
42  * @{
43  */
44 
45 
47 
48 
50 {
51 public:
52  CServer_ConnectionPool(unsigned max_connections);
54 
58 
59  void SetMaxConnections(unsigned max_connections) {
60  m_MaxConnections = max_connections;
61  }
62 
64  void Remove(TConnBase* conn);
65  bool RemoveListener(unsigned short port);
66  void PingControlConnection(void);
67 
68  /// Guard connection from out-of-order packet processing by
69  /// pulling eActiveSocket's from poll vector
70  /// Resets the expiration time as a bonus.
72  void SetAllActive(const vector<CSocketAPI::SPoll>& polls);
73  void SetAllActive(const vector<IServer_ConnectionBase*>& conns);
74 
75  /// Close connection as if it was initiated by server (not by client).
77 
78  /// Erase all connections
79  void Erase(void);
80 
81  bool GetPollAndTimerVec(vector<CSocketAPI::SPoll>& polls,
82  vector<IServer_ConnectionBase*>& timer_requests,
83  STimeout* timer_timeout,
84  vector<IServer_ConnectionBase*>& revived_conns,
85  vector<IServer_ConnectionBase*>& to_close_conns,
86  vector<IServer_ConnectionBase*>& to_delete_conns);
87 
88  void StartListening(void);
89  void StopListening(void);
90 
91  /// Provides a list of ports on which the server is listening
92  /// @return
93  /// currently listened ports
94  vector<unsigned short> GetListenerPorts(void);
95 
96 private:
98 
99 
101 
103  mutable CMutex m_Mutex;
104  unsigned int m_MaxConnections;
106 
107 private:
108  // A list of ports on which the listeners should be stopped.
109  // A storage for the ports is needed because the listener deletion could
110  // not be done synchronously - the listener needs to be taken out of a poll
111  // vector.
112  // The access to the container is protected with m_Mutex
113  vector<unsigned short> m_ListenerPortsToStop;
115 };
116 
117 
119 
120 
121 /* @} */
122 
123 #endif /* CONNECT___CONNECTION_POOL__HPP */
CMutex –.
Definition: ncbimtx.hpp:749
CTrigger::
Definition: ncbi_socket.hpp:88
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void CloseConnection(TConnBase *conn)
Close connection as if it was initiated by server (not by client).
CServer_Listener TListener
void Erase(void)
Erase all connections.
void SetAllActive(const vector< CSocketAPI::SPoll > &polls)
CServer_Connection TConnection
CServer_ConnectionPool(unsigned max_connections)
void SetMaxConnections(unsigned max_connections)
bool 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)
vector< unsigned short > GetListenerPorts(void)
Provides a list of ports on which the server is listening.
EServerConnType
set< TConnBase * > TData
bool Add(TConnBase *conn, EServerConnType type)
void Remove(TConnBase *conn)
void SetConnType(TConnBase *conn, EServerConnType type)
Guard connection from out-of-order packet processing by pulling eActiveSocket's from poll vector Rese...
bool RemoveListener(unsigned short port)
void x_UpdateExpiration(TConnBase *conn)
vector< unsigned short > m_ListenerPortsToStop
IServer_ConnectionBase TConnBase
Internal header for threaded server connections.
Timeout structure.
Definition: ncbi_types.h:76
Definition: type.c:6
Modified on Fri Sep 20 14:57:45 2024 by modify_doxy.py rev. 669887