tcp协议的套接字操作类 更多...
#include <sttnet.h>
Public 成员函数 | |
| void | setFD (const int &fd, SSL *ssl, const bool &flag1=false, const bool &flag2=false, const int &sec=-1) |
| 传入套接字初始化对象 更多... | |
| int | getFD () |
| 获取该对象的套接字 更多... | |
| SSL * | getSSL () |
| 获取该对象的加密SSL句柄 更多... | |
| void | close (const bool &cle=true) |
| 关闭对象 更多... | |
| void | blockSet (const int &sec=-1) |
| 设置对象中的套接字为阻塞模式 更多... | |
| void | unblockSet () |
| 设置对象中的套接字为非阻塞模式 更多... | |
| bool | multiUseSet () |
| 设置对象中的套接字为SO_REUSEADDR模式 更多... | |
| bool | isConnect () |
| 判断对象是否有套接字绑定 更多... | |
| int | sendData (const std::string &data, const bool &block=true) |
| 向已连接的套接字发送字符串数据。 更多... | |
| int | sendData (const char *data, const uint64_t &length, const bool &block=true) |
| 向已连接的套接字发送指定长度的二进制数据。 更多... | |
| int | recvDataByLength (std::string &data, const uint64_t &length, const int &sec=2) |
| 从已连接的套接字中阻塞接收指定长度的数据到字符串 更多... | |
| int | recvDataByLength (char *data, const uint64_t &length, const int &sec=2) |
| 从已连接的套接字中阻塞接收指定长度的数据到char*容器 更多... | |
| int | recvData (std::string &data, const uint64_t &length) |
| 从已连接的套接字中接收一次数据到string字符串容器 更多... | |
| int | recvData (char *data, const uint64_t &length) |
| 从已连接的套接字中接收一次数据到char*容器 更多... | |
Public 属性 | |
| bool | flag3 =false |
| 如果sendData的block=true,如果发送过程中连接断开,这个标志位会置为true 更多... | |
Protected 属性 | |
| int | fd =-1 |
| bool | flag1 =false |
| bool | flag2 =false |
| SSL * | ssl =nullptr |
| int | sec =-1 |
tcp协议的套接字操作类
| void stt::network::TcpFDHandler::blockSet | ( | const int & | sec = -1 | ) |
设置对象中的套接字为阻塞模式
| sec | 阻塞超时时间 阻塞超过这个时间就不会再阻塞了 默认为-1 即无限等待 |
| void stt::network::TcpFDHandler::close | ( | const bool & | cle = true | ) |
关闭对象
| cle | true:关闭对象并且关闭原对象句柄的套接字的链接 false:仅关闭对象 (默认为ture,关闭对象也关闭连接) |
|
inline |
获取该对象的套接字
|
inline |
获取该对象的加密SSL句柄
|
inline |
判断对象是否有套接字绑定
| bool stt::network::TcpFDHandler::multiUseSet | ( | ) |
设置对象中的套接字为SO_REUSEADDR模式
| int stt::network::TcpFDHandler::recvData | ( | std::string & | data, |
| const uint64_t & | length | ||
| ) |
从已连接的套接字中接收一次数据到string字符串容器
| data | 接收数据的数据容器(string类型) |
| length | 最大接收长度 |
| int stt::network::TcpFDHandler::recvData | ( | char * | data, |
| const uint64_t & | length | ||
| ) |
从已连接的套接字中接收一次数据到char*容器
| data | 接收数据的数据容器(char*类型) |
| length | 最大接收长度 |
| int stt::network::TcpFDHandler::recvDataByLength | ( | std::string & | data, |
| const uint64_t & | length, | ||
| const int & | sec = 2 |
||
| ) |
从已连接的套接字中阻塞接收指定长度的数据到字符串
| data | 接收数据的数据容器(string类型) |
| length | 接收长度 |
| sec | 等待时间 单位为秒 -1为无限阻塞等待 (默认为2s) |
| int stt::network::TcpFDHandler::recvDataByLength | ( | char * | data, |
| const uint64_t & | length, | ||
| const int & | sec = 2 |
||
| ) |
从已连接的套接字中阻塞接收指定长度的数据到char*容器
| data | 接收数据的数据容器(char*类型) |
| length | 接收长度 |
| sec | 等待时间 单位为秒 -1为无限阻塞等待 (默认为2s) |
| int stt::network::TcpFDHandler::sendData | ( | const std::string & | data, |
| const bool & | block = true |
||
| ) |
向已连接的套接字发送字符串数据。
| data | 要发送的数据内容(std::string 类型)。 |
| block | 是否以阻塞模式发送(默认 true)。
|
| int stt::network::TcpFDHandler::sendData | ( | const char * | data, |
| const uint64_t & | length, | ||
| const bool & | block = true |
||
| ) |
向已连接的套接字发送指定长度的二进制数据。
| data | 指向要发送的数据缓冲区。 |
| length | 数据长度(字节)。 |
| block | 是否以阻塞模式发送(默认 true)。
|
| void stt::network::TcpFDHandler::setFD | ( | const int & | fd, |
| SSL * | ssl, | ||
| const bool & | flag1 = false, |
||
| const bool & | flag2 = false, |
||
| const int & | sec = -1 |
||
| ) |
传入套接字初始化对象
| fd | 套接字 |
| ssl | fd经过TLS加密后的SSL句柄(如果没有可以填nullptr) |
| flag1 | true:启用非阻塞模式 false:启用阻塞模式 (默认为false,即启用阻塞模式) |
| flag2 | true:启用SO_REUSEADDR模式 false:不启用SO_REUSEADDR模式 (默认为false,即不启用SO_REUSEADDR模式) |
| sec | 阻塞超时时间 阻塞超过这个时间就不会再阻塞了 默认为-1 即无限等待 |
| void stt::network::TcpFDHandler::unblockSet | ( | ) |
设置对象中的套接字为非阻塞模式
|
protected |
|
protected |
|
protected |
| bool stt::network::TcpFDHandler::flag3 =false |
如果sendData的block=true,如果发送过程中连接断开,这个标志位会置为true
|
protected |
|
protected |
1.8.5