#include <tcp_socket.h>
Public Types | |
| enum class | EEvent : UInt32 { InputReady , OutputReady , HangUp , ErrorCondition , InvalidRequest } |
Public Member Functions | |
| CTCPSocket (int n_stream=-1) | |
| CTCPSocket (const CTCPSocket &c_other)=delete | |
| CTCPSocket (CTCPSocket &&c_other) | |
| ~CTCPSocket () | |
| CTCPSocket & | operator= (const CTCPSocket &c_other)=delete |
| CTCPSocket & | operator= (CTCPSocket &&c_other) |
| bool | operator== (const CTCPSocket &c_other) const |
Returns true if the two sockets refer to same file descriptor. More... | |
| bool | IsConnected () const |
Returns true if the socket is connected. More... | |
| int | GetStream () const |
| Returns the socket stream. More... | |
| const std::string & | GetAddress () const |
| Returns a string containing the IPv4 address in dot notation. More... | |
| void | Connect (const std::string &str_hostname, SInt32 n_port) |
| Connects this socket to the specified hostname and port. More... | |
| void | Listen (SInt32 n_port, SInt32 n_queue_length=10) |
| Listens for connections on the specified local port. More... | |
| void | Accept (CTCPSocket &c_socket) |
| Accept a connection from a client. More... | |
| void | Disconnect () |
| Close the socket. More... | |
| std::unordered_set< EEvent > | GetEvents () |
| Check the socket for events. More... | |
| void | SendBuffer (const UInt8 *pun_buffer, size_t un_size) |
| Sends the passed buffer through the socket. More... | |
| bool | ReceiveBuffer (UInt8 *pun_buffer, size_t un_size) |
| Fills the passed buffer with the data received through the socket. More... | |
| void | SendByteArray (const CByteArray &c_byte_array) |
| Sends the passed byte array through the socket. More... | |
| bool | ReceiveByteArray (CByteArray &c_byte_array) |
| Receives the passed byte array through the socket. More... | |
| void | SendMsg (const CByteArray &c_payload, bool b_more=false) |
| void | RecvMsg (CByteArray &c_payload) |
Definition at line 15 of file tcp_socket.h.
|
strong |
| Enumerator | |
|---|---|
| InputReady | |
| OutputReady | |
| HangUp | |
| ErrorCondition | |
| InvalidRequest | |
Definition at line 19 of file tcp_socket.h.
| argos::CTCPSocket::CTCPSocket | ( | int | n_stream = -1 | ) |
Definition at line 20 of file tcp_socket.cpp.
|
delete |
| argos::CTCPSocket::CTCPSocket | ( | CTCPSocket && | c_other | ) |
Definition at line 27 of file tcp_socket.cpp.
| argos::CTCPSocket::~CTCPSocket | ( | ) |
Definition at line 54 of file tcp_socket.cpp.
| void argos::CTCPSocket::Accept | ( | CTCPSocket & | c_socket | ) |
Accept a connection from a client.
Internally, the connection is forced to be only IPv4. Before calling this function, you must first call Listen() to setup connection listening.
| c_socket | The socket on which the connection has been created |
| CARGoSException | in case of error |
Definition at line 149 of file tcp_socket.cpp.
| void argos::CTCPSocket::Connect | ( | const std::string & | str_hostname, |
| SInt32 | n_port | ||
| ) |
Connects this socket to the specified hostname and port.
Internally, the connection is forced to be only IPv4.
| str_hostname | The wanted hostname |
| n_port | The wanted port |
| CARGoSException | in case of error |
Definition at line 61 of file tcp_socket.cpp.
| void argos::CTCPSocket::Disconnect | ( | ) |
Close the socket.
| CARGoSException | in case of error |
Definition at line 165 of file tcp_socket.cpp.
|
inline |
Returns a string containing the IPv4 address in dot notation.
Definition at line 69 of file tcp_socket.h.
| std::unordered_set< CTCPSocket::EEvent > argos::CTCPSocket::GetEvents | ( | ) |
Check the socket for events.
Definition at line 173 of file tcp_socket.cpp.
|
inline |
|
inline |
Returns true if the socket is connected.
true if the socket is connected. Definition at line 53 of file tcp_socket.h.
Listens for connections on the specified local port.
Internally, the connection is forced to be only IPv4. To actually accept connections, you must call Accept() after calling this function.
| n_port | The wanted port |
| n_queue_length | The maximum length of the queue of pending connections (also called the backlog) |
| CARGoSException | in case of error |
Definition at line 101 of file tcp_socket.cpp.
|
delete |
| CTCPSocket & argos::CTCPSocket::operator= | ( | CTCPSocket && | c_other | ) |
Definition at line 38 of file tcp_socket.cpp.
|
inline |
Returns true if the two sockets refer to same file descriptor.
true if the two sockets refer to same file descriptor. Definition at line 45 of file tcp_socket.h.
| bool argos::CTCPSocket::ReceiveBuffer | ( | UInt8 * | pun_buffer, |
| size_t | un_size | ||
| ) |
Fills the passed buffer with the data received through the socket.
| pun_buffer | The buffer to fill |
| un_size | The size of the buffer |
true if the buffer was filled correctly; false if the connection was closed by the other peer | CARGoSException | in case of error |
Definition at line 212 of file tcp_socket.cpp.
| bool argos::CTCPSocket::ReceiveByteArray | ( | CByteArray & | c_byte_array | ) |
Receives the passed byte array through the socket.
Internally, this function first receives the size of the byte array as a long int, and then receives the content of the byte array. It is meant to the be used in conjunction with SendByteArray().
| c_byte_array | The byte array |
true if the buffer was filled correctly; false if the connection was closed by the other peer | CARGoSException | in case of error |
Definition at line 242 of file tcp_socket.cpp.
| void argos::CTCPSocket::RecvMsg | ( | CByteArray & | c_payload | ) |
Definition at line 272 of file tcp_socket.cpp.
| void argos::CTCPSocket::SendBuffer | ( | const UInt8 * | pun_buffer, |
| size_t | un_size | ||
| ) |
Sends the passed buffer through the socket.
| pun_buffer | The wanted buffer |
| un_size | The size of the buffer |
| CARGoSException | in case of error |
Definition at line 195 of file tcp_socket.cpp.
| void argos::CTCPSocket::SendByteArray | ( | const CByteArray & | c_byte_array | ) |
Sends the passed byte array through the socket.
Internally, this function first sends the size of the byte array as a long int, and then sends the content of the byte array. It is meant to the be used in conjunction with ReceiveByteArray().
| c_byte_array | The byte array |
| CARGoSException | in case of error |
Definition at line 231 of file tcp_socket.cpp.
| void argos::CTCPSocket::SendMsg | ( | const CByteArray & | c_payload, |
| bool | b_more = false |
||
| ) |
Definition at line 258 of file tcp_socket.cpp.