HDK
|
#include <UT_NetSocket.h>
Public Types | |
enum | { UT_CONNECT_SUCCESS = 0, UT_WOULD_BLOCK = -1, UT_BAD_ADDRESS = -2, UT_CONNECT_FAILED = -3, UT_ERROR_OCCURED = -4, UT_WRONG_SOCKET = -5, UT_NO_CONNECTION = -6 } |
enum | { UT_SHUTDOWN_RECEIVE = 0, UT_SHUTDOWN_SEND = 1, UT_SHUTDOWN_BOTH = 2 } |
Public Member Functions | |
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 Public Member Functions | |
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 | getHostAddress (UT_IpAddress &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) |
Protected Member Functions | |
int | closeInetSocket () |
UT_NetSocket (UT_NetSocket *netsocket, int socket, bool blocking) | |
UT_NetSocket (const char *address, int port, bool blocking=false, int localport=-1) | |
UT_NetSocket () | |
int | waitForDataOrTimeout (int timeout_ms) |
Protected Attributes | |
char * | myAddressName |
int | myAddressPort |
int | mySocket |
UT_IpAddressV4 | myRemoteIP4 |
unsigned char | myIsServer:1 |
unsigned char | myConnected:1 |
unsigned char | myTermOnLost:1 |
unsigned char | myIsBlocking:1 |
Use NET_TCPSocket instead of UT_NetSocket. UT_NetSocket has a lot of short comings when something unexpected occurs. UT_NetSocket also doesnt support async very well. Additionally, its very difficult to get proper error information when something goes wrong.
Definition at line 38 of file UT_NetSocket.h.
anonymous enum |
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 41 of file UT_NetSocket.h.
anonymous enum |
Enumerator | |
---|---|
UT_SHUTDOWN_RECEIVE | |
UT_SHUTDOWN_SEND | |
UT_SHUTDOWN_BOTH |
Definition at line 53 of file UT_NetSocket.h.
|
delete |
|
virtual |
|
protected |
|
protected |
|
protected |
|
virtual |
|
inlinevirtual |
Definition at line 177 of file UT_NetSocket.h.
|
protected |
|
static |
|
virtual |
|
virtual |
|
inline |
Definition at line 228 of file UT_NetSocket.h.
|
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 |
|
static |
|
static |
|
static |
|
static |
UT_IpAddressV4 UT_NetSocket::getLocalIP4 | ( | ) | const |
bool UT_NetSocket::getLocalIP4 | ( | UT_IpAddressV4 & | ip | ) |
|
virtual |
|
inline |
Definition at line 231 of file UT_NetSocket.h.
|
static |
|
inline |
Definition at line 258 of file UT_NetSocket.h.
bool UT_NetSocket::getRemoteIP4 | ( | UT_IpAddressV4 & | ip | ) |
|
virtual |
|
inline |
Definition at line 256 of file UT_NetSocket.h.
|
inline |
Definition at line 239 of file UT_NetSocket.h.
|
inline |
Definition at line 253 of file UT_NetSocket.h.
SYS_NO_DISCARD_RESULT bool UT_NetSocket::isLocalConnection | ( | ) | const |
|
static |
|
inline |
Definition at line 251 of file UT_NetSocket.h.
bool UT_NetSocket::isSocketSelected | ( | fd_set & | set | ) |
|
inlinevirtual |
Definition at line 248 of file UT_NetSocket.h.
|
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 |
|
static |
|
delete |
|
virtual |
|
virtual |
|
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 |
|
static |
|
virtual |
void UT_NetSocket::terminateOnConnectionLost | ( | bool | term = true | ) |
|
protected |
Definition at line 319 of file UT_NetSocket.h.
|
protected |
Definition at line 320 of file UT_NetSocket.h.
|
protected |
Definition at line 325 of file UT_NetSocket.h.
|
protected |
Definition at line 325 of file UT_NetSocket.h.
|
protected |
Definition at line 325 of file UT_NetSocket.h.
|
protected |
Definition at line 322 of file UT_NetSocket.h.
|
protected |
Definition at line 321 of file UT_NetSocket.h.
|
protected |
Definition at line 325 of file UT_NetSocket.h.