|
tobicore
7.0.0
|
TCP/UDP socket. More...
#include <tobiplatform/TPSocket.hpp>
Collaboration diagram for TPSocket:Public Types | |
| enum | { TCP = 0, UDP = 1 } |
Public Member Functions | |
| TPSocket (int type=TPSocket::TCP, size_t bsize=4096) | |
| Constructor. | |
| virtual | ~TPSocket (void) |
| Destructor. | |
| bool | Open (bool asserver) |
| Initializes whatever needs to be initialized. | |
| bool | Close (void) |
| Closes the socket. | |
| bool | Async (bool block) |
| Configures the socket for asynchronous operation. | |
| bool | Bind (const std::string &ip, const std::string &port) |
| Bind the socket to a specified IP:port. | |
| bool | Listen (void) |
| Starts listening. | |
| int | Accept (TPSocket *endpoint) |
| Accepts an endpoint. | |
| bool | Connect (const std::string &ip, const std::string &port) |
| Connects the socket to a specified IP:port. | |
| ssize_t | Send (const std::string &message) |
| Sends a string to the remote endpoint. | |
| ssize_t | Recv (std::string *message) |
| Receives a string from the remote endpoint. | |
| bool | IsConnected (void) |
| Checks if socket is connected. | |
Public Attributes | |
| TPHost | local |
| Host informations associated to the current socket. | |
| TPHost | remote |
| Host informations associated to the remote endpoint. | |
Protected Member Functions | |
| void | Init (void) |
| Allocates internal memory and initializes structures. | |
| void | Free (void) |
| Releases internal memory. | |
| bool | GetLocal (void) |
| Updates local TPHost. | |
| bool | GetRemote (void) |
| Updates remote TPHost. | |
| void | GetMaxBSize (void) |
| Updates maximum buffer size. | |
Protected Attributes | |
| int | _fd |
| File descriptor. | |
| struct sockaddr_in | _address |
| Socket address. | |
| struct sockaddr_storage | _endpoint |
| Endpoint address. | |
| void * | _buffer |
| Buffer. | |
| size_t | _bsize |
| Buffer size. | |
| unsigned int | _mc |
| Maximum number of connections. | |
| struct addrinfo | _results |
| Socket info. | |
| struct addrinfo * | _info |
| Socket info. | |
| size_t | _bsizemax |
| Maximum size of message. | |
TCP/UDP socket.
Provides basic sync/async connectivity.
Definition at line 61 of file TPSocket.hpp.
| anonymous enum |
Definition at line 159 of file TPSocket.hpp.
| TPSocket::TPSocket | ( | int | type = TPSocket::TCP, |
| size_t | bsize = 4096 |
||
| ) |
Constructor.
Definition at line 42 of file TPSocket.cpp.
| int TPSocket::Accept | ( | TPSocket * | endpoint | ) |
Accepts an endpoint.
Definition at line 216 of file TPSocket.cpp.
Here is the call graph for this function:| bool TPSocket::Async | ( | bool | block | ) |
Configures the socket for asynchronous operation.
Definition at line 53 of file TPSocket.cpp.
| bool TPSocket::Bind | ( | const std::string & | ip, |
| const std::string & | port | ||
| ) |
Bind the socket to a specified IP:port.
If TPSocket is configured AsClient this method will always fail.
Definition at line 173 of file TPSocket.cpp.
Here is the call graph for this function:| bool TPSocket::Connect | ( | const std::string & | ip, |
| const std::string & | port | ||
| ) |
Connects the socket to a specified IP:port.
If TPSocket is configured AsServer this method will always fail.
Definition at line 235 of file TPSocket.cpp.
Here is the call graph for this function:| bool TPSocket::IsConnected | ( | void | ) |
Checks if socket is connected.
Definition at line 324 of file TPSocket.cpp.
Here is the call graph for this function:| bool TPSocket::Listen | ( | void | ) |
Starts listening.
Definition at line 212 of file TPSocket.cpp.
| bool TPSocket::Open | ( | bool | asserver | ) |
Initializes whatever needs to be initialized.
Definition at line 150 of file TPSocket.cpp.
Here is the call graph for this function:| ssize_t TPSocket::Recv | ( | std::string * | message | ) |
Receives a string from the remote endpoint.
Definition at line 285 of file TPSocket.cpp.
Here is the caller graph for this function:| ssize_t TPSocket::Send | ( | const std::string & | message | ) |
Sends a string to the remote endpoint.
Definition at line 266 of file TPSocket.cpp.
Here is the caller graph for this function: