CppServer
1.0.4.0
C++ Server Library
|
TCP session. More...
#include <tcp_session.h>
Public Member Functions | |
TCPSession (const std::shared_ptr< TCPServer > &server) | |
Initialize the session with a given server. More... | |
TCPSession (const TCPSession &)=delete | |
TCPSession (TCPSession &&)=delete | |
virtual | ~TCPSession ()=default |
TCPSession & | operator= (const TCPSession &)=delete |
TCPSession & | operator= (TCPSession &&)=delete |
const CppCommon::UUID & | id () const noexcept |
Get the session Id. More... | |
std::shared_ptr< TCPServer > & | server () noexcept |
Get the server. More... | |
std::shared_ptr< asio::io_service > & | io_service () noexcept |
Get the Asio IO service. More... | |
asio::io_service::strand & | strand () noexcept |
Get the Asio service strand for serialized handler execution. More... | |
asio::ip::tcp::socket & | socket () noexcept |
Get the session socket. More... | |
uint64_t | bytes_pending () const noexcept |
Get the number of bytes pending sent by the session. More... | |
uint64_t | bytes_sent () const noexcept |
Get the number of bytes sent by the session. More... | |
uint64_t | bytes_received () const noexcept |
Get the number of bytes received by the session. More... | |
size_t | option_receive_buffer_limit () const noexcept |
Get the option: receive buffer limit. More... | |
size_t | option_receive_buffer_size () const |
Get the option: receive buffer size. More... | |
size_t | option_send_buffer_limit () const noexcept |
Get the option: send buffer limit. More... | |
size_t | option_send_buffer_size () const |
Get the option: send buffer size. More... | |
bool | IsConnected () const noexcept |
Is the session connected? More... | |
virtual bool | Disconnect () |
Disconnect the session. More... | |
virtual size_t | Send (const void *buffer, size_t size) |
Send data to the client (synchronous) More... | |
virtual size_t | Send (std::string_view text) |
Send text to the client (synchronous) More... | |
virtual size_t | Send (const void *buffer, size_t size, const CppCommon::Timespan &timeout) |
Send data to the client with timeout (synchronous) More... | |
virtual size_t | Send (std::string_view text, const CppCommon::Timespan &timeout) |
Send text to the client with timeout (synchronous) More... | |
virtual bool | SendAsync (const void *buffer, size_t size) |
Send data to the client (asynchronous) More... | |
virtual bool | SendAsync (std::string_view text) |
Send text to the client (asynchronous) More... | |
virtual size_t | Receive (void *buffer, size_t size) |
Receive data from the client (synchronous) More... | |
virtual std::string | Receive (size_t size) |
Receive text from the client (synchronous) More... | |
virtual size_t | Receive (void *buffer, size_t size, const CppCommon::Timespan &timeout) |
Receive data from the client with timeout (synchronous) More... | |
virtual std::string | Receive (size_t size, const CppCommon::Timespan &timeout) |
Receive text from the client with timeout (synchronous) More... | |
virtual void | ReceiveAsync () |
Receive data from the client (asynchronous) More... | |
void | SetupReceiveBufferLimit (size_t limit) noexcept |
Setup option: receive buffer limit. More... | |
void | SetupReceiveBufferSize (size_t size) |
Setup option: receive buffer size. More... | |
void | SetupSendBufferLimit (size_t limit) noexcept |
Setup option: send buffer limit. More... | |
void | SetupSendBufferSize (size_t size) |
Setup option: send buffer size. More... | |
Protected Member Functions | |
virtual void | onConnected () |
Handle session connected notification. More... | |
virtual void | onDisconnected () |
Handle session disconnected notification. More... | |
virtual void | onReceived (const void *buffer, size_t size) |
Handle buffer received notification. More... | |
virtual void | onSent (size_t sent, size_t pending) |
Handle buffer sent notification. More... | |
virtual void | onEmpty () |
Handle empty send buffer notification. More... | |
virtual void | onError (int error, const std::string &category, const std::string &message) |
Handle error notification. More... | |
Friends | |
class | TCPServer |
TCP session.
TCP session is used to read and write data from the connected TCP client.
Thread-safe.
Definition at line 27 of file tcp_session.h.
|
explicit |
Initialize the session with a given server.
server | - Connected server |
Definition at line 15 of file tcp_session.cpp.
|
delete |
|
delete |
|
virtualdefault |
|
inlinenoexcept |
Get the number of bytes pending sent by the session.
Definition at line 57 of file tcp_session.h.
|
inlinenoexcept |
Get the number of bytes received by the session.
Definition at line 61 of file tcp_session.h.
|
inlinenoexcept |
Get the number of bytes sent by the session.
Definition at line 59 of file tcp_session.h.
|
inlinevirtual |
Disconnect the session.
Definition at line 79 of file tcp_session.h.
|
inlinenoexcept |
Get the session Id.
Definition at line 45 of file tcp_session.h.
|
inlinenoexcept |
Get the Asio IO service.
Definition at line 50 of file tcp_session.h.
|
inlinenoexcept |
Is the session connected?
Definition at line 73 of file tcp_session.h.
|
inlineprotectedvirtual |
Handle session connected notification.
Definition at line 191 of file tcp_session.h.
|
inlineprotectedvirtual |
Handle session disconnected notification.
Reimplemented in CppServer::WS::WSSession, and CppServer::HTTP::HTTPSession.
Definition at line 193 of file tcp_session.h.
|
inlineprotectedvirtual |
Handle empty send buffer notification.
Notification is called when the send buffer is empty and ready for a new data to send.
This handler could be used to send another buffer to the client.
Definition at line 224 of file tcp_session.h.
|
inlineprotectedvirtual |
Handle error notification.
error | - Error code |
category | - Error category |
message | - Error message |
Definition at line 232 of file tcp_session.h.
|
inlineprotectedvirtual |
Handle buffer received notification.
Notification is called when another part of buffer was received from the client.
buffer | - Received buffer |
size | - Received buffer size |
Reimplemented in CppServer::WS::WSSession, and CppServer::HTTP::HTTPSession.
Definition at line 203 of file tcp_session.h.
|
inlineprotectedvirtual |
Handle buffer sent notification.
Notification is called when another part of buffer was sent to the client.
This handler could be used to send another buffer to the client for instance when the pending size is zero.
sent | - Size of sent buffer |
pending | - Size of pending buffer |
Definition at line 215 of file tcp_session.h.
|
delete |
|
delete |
|
inlinenoexcept |
Get the option: receive buffer limit.
Definition at line 64 of file tcp_session.h.
size_t CppServer::Asio::TCPSession::option_receive_buffer_size | ( | ) | const |
Get the option: receive buffer size.
Definition at line 33 of file tcp_session.cpp.
|
inlinenoexcept |
Get the option: send buffer limit.
Definition at line 68 of file tcp_session.h.
size_t CppServer::Asio::TCPSession::option_send_buffer_size | ( | ) | const |
Get the option: send buffer size.
Definition at line 40 of file tcp_session.cpp.
|
virtual |
Receive text from the client (synchronous)
size | - Text size to receive |
Definition at line 345 of file tcp_session.cpp.
|
virtual |
Receive text from the client with timeout (synchronous)
size | - Text size to receive |
timeout | - Timeout |
Definition at line 416 of file tcp_session.cpp.
|
virtual |
Receive data from the client (synchronous)
buffer | - Buffer to receive |
size | - Buffer size to receive |
Definition at line 309 of file tcp_session.cpp.
|
virtual |
Receive data from the client with timeout (synchronous)
buffer | - Buffer to receive |
size | - Buffer size to receive |
timeout | - Timeout |
Definition at line 352 of file tcp_session.cpp.
|
virtual |
Receive data from the client (asynchronous)
Definition at line 423 of file tcp_session.cpp.
|
virtual |
Send data to the client (synchronous)
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 157 of file tcp_session.cpp.
|
virtual |
Send data to the client with timeout (synchronous)
buffer | - Buffer to send |
size | - Buffer size |
timeout | - Timeout |
Definition at line 193 of file tcp_session.cpp.
|
inlinevirtual |
Send text to the client (synchronous)
text | - Text to send |
Definition at line 93 of file tcp_session.h.
|
inlinevirtual |
Send text to the client with timeout (synchronous)
text | - Text to send |
timeout | - Timeout |
Definition at line 109 of file tcp_session.h.
|
virtual |
Send data to the client (asynchronous)
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 257 of file tcp_session.cpp.
|
inlinevirtual |
Send text to the client (asynchronous)
text | - Text to send |
Definition at line 123 of file tcp_session.h.
|
inlinenoexcept |
Get the server.
Definition at line 48 of file tcp_session.h.
|
inlinenoexcept |
Setup option: receive buffer limit.
The session will be disconnected if the receive buffer limit is met. Default is unlimited.
limit | - Receive buffer limit |
Definition at line 165 of file tcp_session.h.
void CppServer::Asio::TCPSession::SetupReceiveBufferSize | ( | size_t | size | ) |
Setup option: receive buffer size.
This option will setup SO_RCVBUF if the OS support this feature.
size | - Receive buffer size |
Definition at line 47 of file tcp_session.cpp.
|
inlinenoexcept |
Setup option: send buffer limit.
The session will be disconnected if the send buffer limit is met. Default is unlimited.
limit | - Send buffer limit |
Definition at line 180 of file tcp_session.h.
void CppServer::Asio::TCPSession::SetupSendBufferSize | ( | size_t | size | ) |
Setup option: send buffer size.
This option will setup SO_SNDBUF if the OS support this feature.
size | - Send buffer size |
Definition at line 53 of file tcp_session.cpp.
|
inlinenoexcept |
Get the session socket.
Definition at line 54 of file tcp_session.h.
|
inlinenoexcept |
Get the Asio service strand for serialized handler execution.
Definition at line 52 of file tcp_session.h.
|
friend |
Definition at line 29 of file tcp_session.h.