UDP operation class Pass in the socket for UDP protocol operations.
More...
#include <sttnet_English.h>
|
| void | setFD (const int &fd, const bool &flag1=false, const int &sec=-1, const bool &flag2=false) |
| | Set fd. More...
|
| |
| void | blockSet (const int &sec=-1) |
| | Set to blocking mode. More...
|
| |
| void | unblockSet () |
| | Set to non-blocking mode. More...
|
| |
| bool | multiUseSet () |
| | Set SO_REUSEADDR mode. More...
|
| |
| int | getFD () |
| | Return fd. More...
|
| |
| void | close (const bool &cle=true) |
| | Empty the object and close the socket. More...
|
| |
| int | sendData (const std::string &data, const std::string &ip, const int &port, const bool &block=true) |
| | Send string data to the target. More...
|
| |
| int | sendData (const char *data, const uint64_t &length, const std::string &ip, const int &port, const bool &block=true) |
| | Send a specified length of binary data to the target. More...
|
| |
| int | recvData (std::string &data, const uint64_t &length, std::string &ip, int &port) |
| | Receive data once into a string container. More...
|
| |
| int | recvData (char *data, const uint64_t &length, std::string &ip, int &port) |
| | Receive data once into a char* container. More...
|
| |
UDP operation class Pass in the socket for UDP protocol operations.
| void stt::network::UdpFDHandler::blockSet |
( |
const int & |
sec = -1 | ) |
|
Set to blocking mode.
- Parameters
-
| sec | Blocking timeout, no longer block if blocking exceeds this time, default is -1, i.e., infinite wait |
| void stt::network::UdpFDHandler::close |
( |
const bool & |
cle = true | ) |
|
Empty the object and close the socket.
- Parameters
-
| cle | true: Empty the object and close the socket, false: Only empty the object, do not close the socket |
| int stt::network::UdpFDHandler::getFD |
( |
| ) |
|
|
inline |
| bool stt::network::UdpFDHandler::multiUseSet |
( |
| ) |
|
Set SO_REUSEADDR mode.
- Returns
- true: Set successfully, false: Set failed
| int stt::network::UdpFDHandler::recvData |
( |
std::string & |
data, |
|
|
const uint64_t & |
length, |
|
|
std::string & |
ip, |
|
|
int & |
port |
|
) |
| |
Receive data once into a string container.
- Parameters
-
| data | Data container for received data (string type) |
| length | Maximum reception length |
| ip | Record the source ip of the sender |
| port | Record the source port of the sender |
- Returns
- Return value > 0: Number of bytes successfully received;
- Return value = 0: Connection closed;
- Return value < 0: Reception failed;
- -99: Object not bound to a socket;
- -100: No data in non-blocking mode
- Note
- Whether reception blocks depends on the fd's blocking state
| int stt::network::UdpFDHandler::recvData |
( |
char * |
data, |
|
|
const uint64_t & |
length, |
|
|
std::string & |
ip, |
|
|
int & |
port |
|
) |
| |
Receive data once into a char* container.
- Parameters
-
| data | Data container for received data (char* type) |
| length | Maximum reception length |
| ip | Record the source ip of the sender |
| port | Record the source port of the sender |
- Returns
- Return value > 0: Number of bytes successfully received;
- Return value = 0: Connection closed;
- Return value < 0: Reception failed;
- -99: Object not bound to a socket;
- -100: No data in non-blocking mode
- Note
- Whether reception blocks depends on the fd's blocking state
| int stt::network::UdpFDHandler::sendData |
( |
const std::string & |
data, |
|
|
const std::string & |
ip, |
|
|
const int & |
port, |
|
|
const bool & |
block = true |
|
) |
| |
Send string data to the target.
- Parameters
-
| data | Data content to be sent (std::string type). |
| block | Whether to send in blocking mode (default true).
- true: Will block until all data is sent successfully unless an error occurs (regardless of socket blocking state);
- false: Blocking depends on socket state.
|
- Returns
- Return value > 0: Number of bytes successfully sent;
- Return value <= 0: Sending failed;
- -98: Target error
- -99: Object not bound to a socket;
- -100: Send buffer full in non-blocking mode.
- Note
- If block is true, it will continue to block until all data is sent unless an error occurs (regardless of socket blocking state), suitable for scenarios where complete sending is required. If block is false, blocking depends on socket state. The return value may be less than length, requiring manual handling of remaining data.
| int stt::network::UdpFDHandler::sendData |
( |
const char * |
data, |
|
|
const uint64_t & |
length, |
|
|
const std::string & |
ip, |
|
|
const int & |
port, |
|
|
const bool & |
block = true |
|
) |
| |
Send a specified length of binary data to the target.
- Parameters
-
| data | Pointer to the data buffer to be sent. |
| length | Data length (bytes). |
| block | Whether to send in blocking mode (default true).
- true: Will block until all data is sent successfully unless an error occurs (regardless of socket blocking state);
- false: Blocking depends on socket state.
|
- Returns
- Return value > 0: Number of bytes successfully sent;
- Return value <= 0: Sending failed;
- -98: Target error
- -99: Object not bound to a socket;
- -100: Send buffer full in non-blocking mode.
- Note
- If block is true, it will continue to block until all data is sent unless an error occurs. If block is false, blocking depends on socket state. The return value may be less than length, requiring manual handling of remaining data.
| void stt::network::UdpFDHandler::setFD |
( |
const int & |
fd, |
|
|
const bool & |
flag1 = false, |
|
|
const int & |
sec = -1, |
|
|
const bool & |
flag2 = false |
|
) |
| |
Set fd.
- Parameters
-
| fd | Socket fd to be passed in |
| flag1 | true: Set to non-blocking mode, false: Set to blocking mode (default is blocking mode) |
| sec | Set blocking timeout (seconds) (default is -1, i.e., infinite wait) |
| flag2 | true: Set SO_REUSEADDR mode, false: Do not set SO_REUSEADDR mode |
| void stt::network::UdpFDHandler::unblockSet |
( |
| ) |
|
Set to non-blocking mode.
| int stt::network::UdpFDHandler::fd = -1 |
|
protected |
| bool stt::network::UdpFDHandler::flag1 = false |
|
protected |
| bool stt::network::UdpFDHandler::flag2 = false |
|
protected |
| int stt::network::UdpFDHandler::sec = -1 |
|
protected |
The documentation for this class was generated from the following file: