#include <UT_NetSocket.h>
|
| UT_NetSocket (UT_NetSocket &sock)=delete |
|
UT_NetSocket & | operator= (UT_NetSocket &sock)=delete |
|
bool | isSocketSelected (fd_set &set) |
|
void | addToFDSet (fd_set *set, int &maxfd) |
|
virtual | ~UT_NetSocket () |
|
virtual int64 | getMemoryUsage (bool inclusive) const |
|
virtual UT_UniquePtr
< UT_NetSocket > | accept (bool blocking, int &condition) |
|
virtual int | connect (int timeout_ms=0) |
|
virtual int | close () |
|
virtual int | shutdown (int type) |
|
virtual int | write (const void *data, int len, int *numWritten=0) |
|
virtual int | dataAvailable (int timeout=0) |
|
virtual int | read (void *data, int len, int *numRead=0, int timeout_ms=-1) |
|
virtual int | read (UT_WorkBuffer &data, int timeout_ms=-1, bool wait_for_null_terminator=false) |
|
virtual int | peek (void *data, int len, int timeout_ms=-1) |
|
virtual int | flushRead () |
|
virtual int | flushWrite () |
|
void | terminateOnConnectionLost (bool term=true) |
|
const char * | getAddress () const |
|
int | getPort () const |
|
virtual int | getRemoteSocket (UT_IpAddressV4 &host, int &port) const |
|
virtual int | setBlocking (bool blocking) |
|
bool | isBlocking () const |
|
void | setNoDelay (int usenodelay) |
|
void | setQuickAck (int quickack) |
|
virtual bool | isValid () const |
|
bool | isServer () const |
|
bool | isConnected () const |
|
int | getSocket () const |
|
const UT_IpAddressV4 & | getRemoteIP4 () const |
|
bool | getRemoteIP4 (UT_IpAddressV4 &ip) |
|
UT_IpAddressV4 | getLocalIP4 () const |
|
bool | getLocalIP4 (UT_IpAddressV4 &ip) |
|
SYS_NO_DISCARD_RESULT bool | isLocalConnection () const |
|
int | sockRecv (void *data, int len, int *num_read=nullptr) |
|
|
static const char * | getErrorName (int code) |
|
static int | getPortByService (const char *service, const char *proto="tcp", int default_port=0) |
|
static void | getHostName (char *name, int max) |
|
static bool | getHostAddress (UT_IpAddressV4 &address, const char *hostname=0) |
|
static bool | getLocalAddresses (UT_Array< UT_IpAddress > &addresses, UT_IpAddressFamily family=UT_IpAddressFamily::IPv4) |
|
static bool | getLocalAddress (UT_IpAddress &address, UT_IpAddressFamily family=UT_IpAddressFamily::IPv4) |
|
static bool | getHostNameByAlias (UT_String &host, const char *alias=NULL) |
|
static int | mapToUnprivilegedPort (int port) |
|
static bool | sendCommandAndGetResult (int port, const char *command, UT_WorkBuffer &response, const char *host_name=0, bool remap_privileged_ports=true) |
|
static bool | nonBlockingSendCommandAndGetResult (int port, const char *command, UT_WorkBuffer &response, const char *host_name=0, bool remap_privileged_ports=true) |
|
static UT_UniquePtr< UT_NetSocket > | newSocket (int port, bool blocking=false, bool portisonlyhint=false) |
|
static UT_UniquePtr< UT_NetSocket > | newSocketFromAddr (const char *address, int port, bool blocking=false, int localport=-1) |
|
static void | fdZero (fd_set *set) |
|
static void | fdSet (int fd, fd_set *set) |
|
static void | fdClr (int fd, fd_set *set) |
|
static int | fdIsSet (int fd, fd_set *set) |
|
static int | select (int fd, fd_set *r_set, fd_set *w_set, fd_set *e_set, SYS_TimeVal *tv) |
|
static int | selectInMS (int maxfd, fd_set *r_set, fd_set *w_set, fd_set *e_set, int timeoutms=0) |
|
static SYS_NO_DISCARD_RESULT bool | isLocalConnection (int fd) |
|
Definition at line 32 of file UT_NetSocket.h.
Enumerator |
---|
UT_CONNECT_SUCCESS |
|
UT_WOULD_BLOCK |
|
UT_BAD_ADDRESS |
|
UT_CONNECT_FAILED |
|
UT_ERROR_OCCURED |
|
UT_WRONG_SOCKET |
|
UT_NO_CONNECTION |
|
Definition at line 35 of file UT_NetSocket.h.
Enumerator |
---|
UT_SHUTDOWN_RECEIVE |
|
UT_SHUTDOWN_SEND |
|
UT_SHUTDOWN_BOTH |
|
Definition at line 47 of file UT_NetSocket.h.
virtual UT_NetSocket::~UT_NetSocket |
( |
| ) |
|
|
virtual |
UT_NetSocket::UT_NetSocket |
( |
UT_NetSocket * |
netsocket, |
|
|
int |
socket, |
|
|
bool |
blocking |
|
) |
| |
|
protected |
UT_NetSocket::UT_NetSocket |
( |
const char * |
address, |
|
|
int |
port, |
|
|
bool |
blocking = false , |
|
|
int |
localport = -1 |
|
) |
| |
|
protected |
UT_NetSocket::UT_NetSocket |
( |
| ) |
|
|
protected |
void UT_NetSocket::addToFDSet |
( |
fd_set * |
set, |
|
|
int & |
maxfd |
|
) |
| |
virtual int UT_NetSocket::close |
( |
| ) |
|
|
inlinevirtual |
int UT_NetSocket::closeInetSocket |
( |
| ) |
|
|
protected |
virtual int UT_NetSocket::connect |
( |
int |
timeout_ms = 0 | ) |
|
|
virtual |
virtual int UT_NetSocket::dataAvailable |
( |
int |
timeout = 0 | ) |
|
|
virtual |
static void UT_NetSocket::fdClr |
( |
int |
fd, |
|
|
fd_set * |
set |
|
) |
| |
|
static |
static int UT_NetSocket::fdIsSet |
( |
int |
fd, |
|
|
fd_set * |
set |
|
) |
| |
|
static |
static void UT_NetSocket::fdSet |
( |
int |
fd, |
|
|
fd_set * |
set |
|
) |
| |
|
static |
static void UT_NetSocket::fdZero |
( |
fd_set * |
set | ) |
|
|
static |
virtual int UT_NetSocket::flushRead |
( |
| ) |
|
|
virtual |
virtual int UT_NetSocket::flushWrite |
( |
| ) |
|
|
virtual |
const char* UT_NetSocket::getAddress |
( |
| ) |
const |
|
inline |
static const char* UT_NetSocket::getErrorName |
( |
int |
code | ) |
|
|
static |
Convertes the enum of UT_CONNECT_SUCCESS, etc, into an english error message roughly matching the enum's name. Be careful as this uses different errors different locations.
static bool UT_NetSocket::getHostAddress |
( |
UT_IpAddressV4 & |
address, |
|
|
const char * |
hostname = 0 |
|
) |
| |
|
static |
static void UT_NetSocket::getHostName |
( |
char * |
name, |
|
|
int |
max |
|
) |
| |
|
static |
static bool UT_NetSocket::getHostNameByAlias |
( |
UT_String & |
host, |
|
|
const char * |
alias = NULL |
|
) |
| |
|
static |
virtual int64 UT_NetSocket::getMemoryUsage |
( |
bool |
inclusive | ) |
const |
|
virtual |
int UT_NetSocket::getPort |
( |
| ) |
const |
|
inline |
static int UT_NetSocket::getPortByService |
( |
const char * |
service, |
|
|
const char * |
proto = "tcp" , |
|
|
int |
default_port = 0 |
|
) |
| |
|
static |
int UT_NetSocket::getSocket |
( |
| ) |
const |
|
inline |
bool UT_NetSocket::isBlocking |
( |
| ) |
const |
|
inline |
bool UT_NetSocket::isConnected |
( |
| ) |
const |
|
inline |
bool UT_NetSocket::isServer |
( |
| ) |
const |
|
inline |
bool UT_NetSocket::isSocketSelected |
( |
fd_set & |
set | ) |
|
virtual bool UT_NetSocket::isValid |
( |
| ) |
const |
|
inlinevirtual |
static int UT_NetSocket::mapToUnprivilegedPort |
( |
int |
port | ) |
|
|
static |
Creates a new listen socket on the specified port. A port of 0 will auto-choose a free port. Be careful overusing that, however, as Windows in particular has very few ports available by default. portisonlyhint will attempt to bind to the given port but if it fails (ie, already in use) will revert to using 0 to select a free port. The caller should thus double check the actual bound port if they care.
static bool UT_NetSocket::nonBlockingSendCommandAndGetResult |
( |
int |
port, |
|
|
const char * |
command, |
|
|
UT_WorkBuffer & |
response, |
|
|
const char * |
host_name = 0 , |
|
|
bool |
remap_privileged_ports = true |
|
) |
| |
|
static |
virtual int UT_NetSocket::peek |
( |
void * |
data, |
|
|
int |
len, |
|
|
int |
timeout_ms = -1 |
|
) |
| |
|
virtual |
virtual int UT_NetSocket::read |
( |
void * |
data, |
|
|
int |
len, |
|
|
int * |
numRead = 0 , |
|
|
int |
timeout_ms = -1 |
|
) |
| |
|
virtual |
virtual int UT_NetSocket::read |
( |
UT_WorkBuffer & |
data, |
|
|
int |
timeout_ms = -1 , |
|
|
bool |
wait_for_null_terminator = false |
|
) |
| |
|
virtual |
static int UT_NetSocket::select |
( |
int |
fd, |
|
|
fd_set * |
r_set, |
|
|
fd_set * |
w_set, |
|
|
fd_set * |
e_set, |
|
|
SYS_TimeVal * |
tv |
|
) |
| |
|
static |
Performs a select() call on the socket.
Note, it turns out there is a discrepancy between how select() works on Linux vs. Windows.
On Windows, the select() call selects for reading the sockets even if they were closed by the remote counterparts. The rationale is that trying to read from such a socket returns zero, which is a signal that the connection was closed.
On Linux/OSX, select() call does not select such sockets for reading. The rationale is that there cannot be any more data for reading on closed sockets.
static int UT_NetSocket::selectInMS |
( |
int |
maxfd, |
|
|
fd_set * |
r_set, |
|
|
fd_set * |
w_set, |
|
|
fd_set * |
e_set, |
|
|
int |
timeoutms = 0 |
|
) |
| |
|
static |
static bool UT_NetSocket::sendCommandAndGetResult |
( |
int |
port, |
|
|
const char * |
command, |
|
|
UT_WorkBuffer & |
response, |
|
|
const char * |
host_name = 0 , |
|
|
bool |
remap_privileged_ports = true |
|
) |
| |
|
static |
virtual int UT_NetSocket::setBlocking |
( |
bool |
blocking | ) |
|
|
virtual |
void UT_NetSocket::setNoDelay |
( |
int |
usenodelay | ) |
|
void UT_NetSocket::setQuickAck |
( |
int |
quickack | ) |
|
virtual int UT_NetSocket::shutdown |
( |
int |
type | ) |
|
|
virtual |
int UT_NetSocket::sockRecv |
( |
void * |
data, |
|
|
int |
len, |
|
|
int * |
num_read = nullptr |
|
) |
| |
void UT_NetSocket::terminateOnConnectionLost |
( |
bool |
term = true | ) |
|
int UT_NetSocket::waitForDataOrTimeout |
( |
int |
timeout_ms | ) |
|
|
protected |
char* UT_NetSocket::myAddressName |
|
protected |
int UT_NetSocket::myAddressPort |
|
protected |
unsigned char UT_NetSocket::myConnected |
|
protected |
unsigned char UT_NetSocket::myIsBlocking |
|
protected |
unsigned char UT_NetSocket::myIsServer |
|
protected |
int UT_NetSocket::mySocket |
|
protected |
unsigned char UT_NetSocket::myTermOnLost |
|
protected |
The documentation for this class was generated from the following file: