TCP socket backed by Poco::Net; supports both client (connect) and server (listen/accept) roles. Data arrives via Network::pump as NetCompletion. 更多...
#include <TcpSocket.h>
Public 成员函数 | |
| TcpSocket (Network *net) | |
| Creates an unconnected socket owned by the given module. | |
| ~TcpSocket () | |
| bool | connect (std::string host, uint16_t port) |
| Connects to host:port; true on success. | |
| bool | listen (uint16_t port) |
| Starts listening on the given port; true on success. | |
| TcpSocket * | accept () |
| Accepts one pending client, or nullptr if none. | |
| bool | send (eve::data::ByteData *data) |
| Sends a framed byte payload; true when queued/accepted. | |
| bool | sendString (std::string s) |
| Sends a string payload. | |
| void | close () |
| Closes the socket. | |
| bool | isConnected () const |
| True while a stream is connected. | |
| std::string | getPeer () const |
| Remote peer address string, e.g. "1.2.3.4:5678". | |
| uint16_t | getLocalPort () const |
| Local listening port, or 0. | |
| Network * | network () const |
| Internal: owning module (used by Network::pump / NetWorker). | |
| void | setConnectedSocket (std::unique_ptr< Poco::Net::StreamSocket > sock) |
| Poco::Net::StreamSocket * | stream () |
| Poco::Net::ServerSocket * | server () |
| bool | isListening () const |
| True after listen(). | |
| bool | takeAccepted (std::unique_ptr< TcpSocket > &out) |
| void | pushAccepted (std::unique_ptr< TcpSocket > sock) |
| size_t | pendingSendBytes () const |
| Internal: queued-outgoing byte counter for back-pressure. | |
| bool | queueSend (const void *d, size_t n) |
| Append bytes to the pending send queue (worker-thread flush via pollSockets). | |
| void | flushSend () |
| Push pending bytes onto the socket; called from Network::pollSockets. | |
| void | clearPendingSend () |
详细描述
TCP socket backed by Poco::Net; supports both client (connect) and server (listen/accept) roles. Data arrives via Network::pump as NetCompletion.
在文件 TcpSocket.h 第 28 行定义.
构造及析构函数说明
◆ TcpSocket()
|
explicit |
Creates an unconnected socket owned by the given module.
在文件 TcpSocket.cpp 第 17 行定义.
◆ ~TcpSocket()
| eve::network::TcpSocket::~TcpSocket | ( | ) |
在文件 TcpSocket.cpp 第 19 行定义.
引用了 close().
成员函数说明
◆ accept()
| TcpSocket * eve::network::TcpSocket::accept | ( | ) |
◆ clearPendingSend()
| void eve::network::TcpSocket::clearPendingSend | ( | ) |
在文件 TcpSocket.cpp 第 172 行定义.
被这些函数引用 close().
◆ close()
| void eve::network::TcpSocket::close | ( | ) |
Closes the socket.
在文件 TcpSocket.cpp 第 227 行定义.
引用了 clearPendingSend() , 以及 eve::network::Network::unwatchTcp().
被这些函数引用 eve::network::Channel::feed(), flushSend() , 以及 ~TcpSocket().
◆ connect()
| bool eve::network::TcpSocket::connect | ( | std::string | host, |
| uint16_t | port | ||
| ) |
Connects to host:port; true on success.
在文件 TcpSocket.cpp 第 56 行定义.
引用了 c, eve::network::Conn, eve::network::Err, eve::network::NetCompletion::handle, eve::network::NetCompletion::kind, eve::network::NetCompletion::reason, eve::network::NetWorker::submit(), eve::network::Tcp, eve::network::NetCompletion::type , 以及 eve::network::Network::worker().
◆ flushSend()
| void eve::network::TcpSocket::flushSend | ( | ) |
Push pending bytes onto the socket; called from Network::pollSockets.
在文件 TcpSocket.cpp 第 177 行定义.
引用了 c, close(), eve::network::Err, n, eve::network::Network::post(), eve::network::Tcp , 以及 eve::network::NetCompletion::type.
◆ getLocalPort()
| uint16_t eve::network::TcpSocket::getLocalPort | ( | ) | const |
Local listening port, or 0.
在文件 TcpSocket.cpp 第 252 行定义.
◆ getPeer()
| std::string eve::network::TcpSocket::getPeer | ( | ) | const |
Remote peer address string, e.g. "1.2.3.4:5678".
在文件 TcpSocket.cpp 第 248 行定义.
被这些函数引用 eve::network::Network::pollSockets().
◆ isConnected()
| bool eve::network::TcpSocket::isConnected | ( | ) | const |
True while a stream is connected.
在文件 TcpSocket.cpp 第 244 行定义.
◆ isListening()
|
inline |
True after listen().
在文件 TcpSocket.h 第 59 行定义.
◆ listen()
| bool eve::network::TcpSocket::listen | ( | uint16_t | port | ) |
Starts listening on the given port; true on success.
在文件 TcpSocket.cpp 第 106 行定义.
引用了 c, eve::network::Err, eve::network::Network::post(), eve::network::Tcp, eve::network::NetCompletion::type , 以及 eve::network::Network::watchTcp().
◆ network()
|
inline |
Internal: owning module (used by Network::pump / NetWorker).
在文件 TcpSocket.h 第 54 行定义.
被这些函数引用 eve::network::Channel::feed(), eve::network::Channel::sendMsg() , 以及 eve::network::Channel::~Channel().
◆ pendingSendBytes()
| size_t eve::network::TcpSocket::pendingSendBytes | ( | ) | const |
Internal: queued-outgoing byte counter for back-pressure.
在文件 TcpSocket.cpp 第 167 行定义.
◆ pushAccepted()
| void eve::network::TcpSocket::pushAccepted | ( | std::unique_ptr< TcpSocket > | sock | ) |
在文件 TcpSocket.cpp 第 43 行定义.
被这些函数引用 eve::network::Network::pollSockets().
◆ queueSend()
| bool eve::network::TcpSocket::queueSend | ( | const void * | d, |
| size_t | n | ||
| ) |
Append bytes to the pending send queue (worker-thread flush via pollSockets).
在文件 TcpSocket.cpp 第 146 行定义.
引用了 c, d, eve::network::Err, eve::network::kMaxSendBuffer, n, p, eve::network::Network::post(), eve::network::Tcp , 以及 eve::network::NetCompletion::type.
被这些函数引用 send().
◆ send()
| bool eve::network::TcpSocket::send | ( | eve::data::ByteData * | data | ) |
Sends a framed byte payload; true when queued/accepted.
在文件 TcpSocket.cpp 第 134 行定义.
引用了 data, n , 以及 queueSend().
被这些函数引用 eve::network::Channel::sendMsg() , 以及 sendString().
◆ sendString()
| bool eve::network::TcpSocket::sendString | ( | std::string | s | ) |
◆ server()
| Poco::Net::ServerSocket * eve::network::TcpSocket::server | ( | ) |
在文件 TcpSocket.cpp 第 39 行定义.
◆ setConnectedSocket()
| void eve::network::TcpSocket::setConnectedSocket | ( | std::unique_ptr< Poco::Net::StreamSocket > | sock | ) |
在文件 TcpSocket.cpp 第 23 行定义.
◆ stream()
| Poco::Net::StreamSocket * eve::network::TcpSocket::stream | ( | ) |
在文件 TcpSocket.cpp 第 35 行定义.
◆ takeAccepted()
| bool eve::network::TcpSocket::takeAccepted | ( | std::unique_ptr< TcpSocket > & | out | ) |
在文件 TcpSocket.cpp 第 48 行定义.
被这些函数引用 accept().
该类的文档由以下文件生成:
- src/modules/network/TcpSocket.h
- src/modules/network/TcpSocket.cpp