ngscopeclient 0.1-dev+51fbda87c
|
Class representing a network socket. More...
#include <Socket.h>
Public Member Functions | |
Socket (int af, int type, int protocol) | |
Creates a socket. More... | |
Socket (ZSOCKET sock, int af=PF_INET) | |
Wraps an existing socket. More... | |
virtual | ~Socket (void) |
Closes a socket. | |
bool | Connect (const std::string &host, uint16_t port) |
Establishes a TCP connection to a remote host. More... | |
bool | Bind (unsigned short port) |
Binds the socket to an address. More... | |
bool | Listen () |
Puts the socket in listening mode. | |
Socket | Accept (sockaddr_in *addr, ZSOCKLEN len) |
Accepts an IPv4 connection on the socket. More... | |
Socket | Accept (sockaddr_in6 *addr, ZSOCKLEN len) |
Accepts a IPv6 connection on the socket. More... | |
Socket | Accept () |
Accepts a connection on the socket. More... | |
ZSOCKET | Detach () |
Detaches the socket from this object. More... | |
void | FlushRxBuffer (void) |
Flush RX buffer. More... | |
bool | SendLooped (const unsigned char *buf, int count) |
Sends data over the socket. More... | |
bool | RecvLooped (unsigned char *buf, int len) |
Recives data from a UDP socket. More... | |
bool | RecvPascalString (std::string &str) |
Reads a Pascal-style string from a socket. More... | |
bool | SendPascalString (const std::string &str) |
Sends a string to a socket. More... | |
bool | DisableNagle () |
Disable the Nagle algorithm on the socket so that messages get sent right away. More... | |
bool | DisableDelayedACK () |
Disable delayed-ACK so that we send ACKs immediately upon packet receipt. More... | |
bool | SetReuseaddr (bool on=true) |
Set SO_REUSEADDR on our socket, allowing binding to it again without waiting for timeout if our task crashed hard. More... | |
bool | SetRxTimeout (unsigned int microSeconds) |
bool | SetTxTimeout (unsigned int microSeconds) |
bool | SetTxBuffer (int bufsize) |
bool | SetRxBuffer (int bufsize) |
operator const ZSOCKET & () const | |
Convert us to the native OS socket type. More... | |
bool | IsValid () const |
Socket & | operator= (ZSOCKET rhs) |
void | Close () |
Protected Member Functions | |
void | Open () |
Class representing a network socket.
Socket::Socket | ( | int | af, |
int | type, | ||
int | protocol | ||
) |
Creates a socket.
af | Address family of the socket (layer 3 protocol selection) |
type | Type of the socket (stream or datagram) |
protocol | Protocol of the socket (layer 4 protocol selection) |
Socket::Socket | ( | ZSOCKET | sock, |
int | af = PF_INET |
||
) |
Wraps an existing socket.
sock | Socket to encapsulate |
af | Address family of the provided socket |
Socket Socket::Accept | ( | ) |
Accepts a connection on the socket.
addr Output address of accepted connection
len Size of the output buffer
Socket Socket::Accept | ( | sockaddr_in * | addr, |
ZSOCKLEN | len | ||
) |
Accepts an IPv4 connection on the socket.
addr Output address of accepted connection
len Size of the output buffer
Socket Socket::Accept | ( | sockaddr_in6 * | addr, |
ZSOCKLEN | len | ||
) |
Accepts a IPv6 connection on the socket.
addr Output address of accepted connection
len Size of the output buffer
bool Socket::Bind | ( | unsigned short | port | ) |
Binds the socket to an address.
TODO: allow binding to specific addresses etc
port | Port to listen on |
bool Socket::Connect | ( | const std::string & | host, |
uint16_t | port | ||
) |
Establishes a TCP connection to a remote host.
host | DNS name or string IP address of remote host |
port | Port to connect to (host byte order) |
ZSOCKET Socket::Detach | ( | ) |
Detaches the socket from this object.
bool Socket::DisableDelayedACK | ( | ) |
Disable delayed-ACK so that we send ACKs immediately upon packet receipt.
bool Socket::DisableNagle | ( | ) |
Disable the Nagle algorithm on the socket so that messages get sent right away.
void Socket::FlushRxBuffer | ( | void | ) |
Flush RX buffer.
|
inline |
Convert us to the native OS socket type.
bool Socket::RecvLooped | ( | unsigned char * | buf, |
int | len | ||
) |
Recives data from a UDP socket.
buf | Output buffer |
len | Length of the buffer |
addr | IP address of the sender |
flags | Socket flags |
Sends data to a UDP socket
buf | Input buffer |
len | Length of the buffer |
addr | IP address of the recipient |
flags | Socket flags |
Recieves data from the socket
buf | The buffer to read into |
len | Length of read buffer |
bool Socket::RecvPascalString | ( | std::string & | str | ) |
Reads a Pascal-style string from a socket.
bool Socket::SendLooped | ( | const unsigned char * | buf, |
int | count | ||
) |
Sends data over the socket.
buf | Buffer to send |
count | Length of data buffer |
bool Socket::SendPascalString | ( | const std::string & | str | ) |
Sends a string to a socket.
fd | Socket handle |
str | String to send |
bool Socket::SetReuseaddr | ( | bool | on = true | ) |
Set SO_REUSEADDR on our socket, allowing binding to it again without waiting for timeout if our task crashed hard.