|
trantor
Non-blocking I/O cross-platform TCP network library, using C++14
|
This class represents a TCP server. More...
#include <trantor/net/TcpServer.h>


Public Member Functions | |
| TcpServer (EventLoop *loop, const InetAddress &address, std::string name, bool reUseAddr=true, bool reUsePort=true) | |
| Construct a new TCP server instance. | |
| void | start () |
| Start the server. | |
| void | stop () |
| Stop the server. | |
| void | setIoLoopNum (size_t num) |
| Set the number of event loops in which the I/O of connections to the server is handled. An EventLoopThreadPool is created and managed by TcpServer. | |
| void | setIoLoopThreadPool (const std::shared_ptr< EventLoopThreadPool > &pool) |
| Set the event loops pool in which the I/O of connections to the server is handled. A shared_ptr of EventLoopThreadPool is copied. | |
| void | setIoLoops (const std::vector< trantor::EventLoop * > &ioLoops) |
| Set the event loops in which the I/O of connections to the server is handled. The loops are managed by caller. Caller should ensure that ioLoops lives longer than TcpServer. | |
| void | setRecvMessageCallback (const RecvMessageCallback &cb) |
| Set the message callback. | |
| void | setRecvMessageCallback (RecvMessageCallback &&cb) |
| void | setConnectionCallback (const ConnectionCallback &cb) |
| Set the connection callback. | |
| void | setConnectionCallback (ConnectionCallback &&cb) |
| void | setWriteCompleteCallback (const WriteCompleteCallback &cb) |
| Set the write complete callback. | |
| void | setWriteCompleteCallback (WriteCompleteCallback &&cb) |
| void | setBeforeListenSockOptCallback (SockOptCallback cb) |
| Set the before listen setsockopt callback. | |
| void | setAfterAcceptSockOptCallback (SockOptCallback cb) |
| Set the after accept setsockopt callback. | |
| const std::string & | name () const |
| Get the name of the server. | |
| std::string | ipPort () const |
| Get the IP and port string of the server. | |
| const trantor::InetAddress & | address () const |
| Get the address of the server. | |
| EventLoop * | getLoop () const |
| Get the event loop of the server. | |
| std::vector< EventLoop * > | getIoLoops () const |
| Get the I/O event loops of the server. | |
| void | kickoffIdleConnections (size_t timeout) |
| An idle connection is a connection that has no read or write, kick off it after timeout seconds. | |
| void | enableSSL (const std::string &certPath, const std::string &keyPath, bool useOldTLS=false, const std::vector< std::pair< std::string, std::string > > &sslConfCmds={}, const std::string &caPath="") |
| Enable SSL encryption. | |
| void | enableSSL (TLSPolicyPtr policy) |
| Enable SSL encryption. | |
| void | reloadSSL () |
| Reload the SSL context. | |
This class represents a TCP server.
| trantor::TcpServer::TcpServer | ( | EventLoop * | loop, |
| const InetAddress & | address, | ||
| std::string | name, | ||
| bool | reUseAddr = true, | ||
| bool | reUsePort = true ) |
Construct a new TCP server instance.
| loop | The event loop in which the acceptor of the server is handled. |
| address | The address of the server. |
| name | The name of the server. |
| reUseAddr | The SO_REUSEADDR option. |
| reUsePort | The SO_REUSEPORT option. |
| const trantor::InetAddress & trantor::TcpServer::address | ( | ) | const |
Get the address of the server.
| void trantor::TcpServer::enableSSL | ( | const std::string & | certPath, |
| const std::string & | keyPath, | ||
| bool | useOldTLS = false, | ||
| const std::vector< std::pair< std::string, std::string > > & | sslConfCmds = {}, | ||
| const std::string & | caPath = "" ) |
Enable SSL encryption.
| certPath | The path of the certificate file. |
| keyPath | The path of the private key file. |
| useOldTLS | If true, the TLS 1.0 and 1.1 are supported by the server. |
| sslConfCmds | The commands used to call the SSL_CONF_cmd function in OpenSSL. |
| caPath | The path of the certificate authority file. |
|
inline |
Get the I/O event loops of the server.
|
inline |
Get the event loop of the server.
| std::string trantor::TcpServer::ipPort | ( | ) | const |
Get the IP and port string of the server.
|
inline |
An idle connection is a connection that has no read or write, kick off it after timeout seconds.
| timeout |
|
inline |
Get the name of the server.
| void trantor::TcpServer::reloadSSL | ( | ) |
Reload the SSL context.
| void trantor::TcpServer::setAfterAcceptSockOptCallback | ( | SockOptCallback | cb | ) |
Set the after accept setsockopt callback.
| cb | This callback will be called after accept |
| void trantor::TcpServer::setBeforeListenSockOptCallback | ( | SockOptCallback | cb | ) |
Set the before listen setsockopt callback.
| cb | This callback will be called before the listen |
|
inline |
Set the connection callback.
| cb | The callback is called when a connection is established or closed. |
|
inline |
Set the number of event loops in which the I/O of connections to the server is handled. An EventLoopThreadPool is created and managed by TcpServer.
| num |
|
inline |
Set the event loops in which the I/O of connections to the server is handled. The loops are managed by caller. Caller should ensure that ioLoops lives longer than TcpServer.
| ioLoops |
|
inline |
Set the event loops pool in which the I/O of connections to the server is handled. A shared_ptr of EventLoopThreadPool is copied.
| pool |
|
inline |
Set the message callback.
| cb | The callback is called when some data is received on a connection to the server. |
|
inline |
Set the write complete callback.
| cb | The callback is called when data to send is written to the socket of a connection. |