51#include <netinet/in.h>
52#include <sys/socket.h>
54#define ZSOCKLEN socklen_t
65 Socket(
int af,
int type,
int protocol);
68 Socket(ZSOCKET sock,
int af = PF_INET);
74 bool Connect(
const std::string& host, uint16_t port);
77 bool Bind(
unsigned short port);
94 bool SendLooped(
const unsigned char* buf,
int count);
113 bool SetRxTimeout(
unsigned int microSeconds);
114 bool SetTxTimeout(
unsigned int microSeconds);
117 bool SetTxBuffer(
int bufsize);
118 bool SetRxBuffer(
int bufsize);
124 operator const ZSOCKET&()
const {
return m_socket; }
129 return (
m_socket != INVALID_SOCKET);
135 Socket& operator=(ZSOCKET rhs);
Class representing a network socket.
Definition: Socket.h:63
int m_protocol
Protocol of the socket.
Definition: Socket.h:151
bool Connect(const std::string &host, uint16_t port)
Establishes a TCP connection to a remote host.
Definition: Socket.cpp:132
bool SendPascalString(const std::string &str)
Sends a string to a socket.
Definition: Socket.cpp:554
bool DisableDelayedACK()
Disable delayed-ACK so that we send ACKs immediately upon packet receipt.
Definition: Socket.cpp:610
void FlushRxBuffer(void)
Flush RX buffer.
Definition: Socket.cpp:348
Socket(int af, int type, int protocol)
Creates a socket.
Definition: Socket.cpp:54
int m_af
Address family of this socket (typically AF_INET or AF_INET6)
Definition: Socket.h:145
virtual ~Socket(void)
Closes a socket.
Definition: Socket.cpp:97
ZSOCKET Detach()
Detaches the socket from this object.
Definition: Socket.cpp:535
bool RecvLooped(unsigned char *buf, int len)
Recives data from a UDP socket.
Definition: Socket.cpp:293
bool Bind(unsigned short port)
Binds the socket to an address.
Definition: Socket.cpp:391
Socket Accept()
Accepts a connection on the socket.
Definition: Socket.cpp:475
bool Listen()
Puts the socket in listening mode.
Definition: Socket.cpp:432
bool RecvPascalString(std::string &str)
Reads a Pascal-style string from a socket.
Definition: Socket.cpp:576
bool SetReuseaddr(bool on=true)
Set SO_REUSEADDR on our socket, allowing binding to it again without waiting for timeout if our task ...
Definition: Socket.cpp:629
int m_type
Type of the socket.
Definition: Socket.h:148
ZSOCKET m_socket
The socket handle.
Definition: Socket.h:160
bool DisableNagle()
Disable the Nagle algorithm on the socket so that messages get sent right away.
Definition: Socket.cpp:596
bool SendLooped(const unsigned char *buf, int count)
Sends data over the socket.
Definition: Socket.cpp:206