Namespace: dmSocket
Language: C++
Type: Defold C++
File: socket.h
Source: engine/dlib/src/dmsdk/dlib/socket.h
Include: dmsdk/dlib/socket.h
Socket functions.
Type: STRUCT Network addresses were previously represented as an uint32_t, but in order to support IPv6 the internal representation was changed to a struct.
Type: FUNCTION Initiate a connection on a socket
Parameters
socket (Socket) - Socket to initiate connection onaddress (Address) - Address to connect toport (int) - Port to connect toReturns
return (Result) - RESULT_OK on successType: FUNCTION Delete a socket. Corresponds to BSD socket function close()
Parameters
socket (Socket) - Socket to closeReturns
return (Result) - RESULT_OK on successType: ENUM Domain type
Members
DOMAIN_MISSINGDOMAIN_IPV4DOMAIN_IPV6DOMAIN_UNKNOWNType: FUNCTION Get underlying file descriptor
Parameters
socket (Socket) - socket to get fd forReturns
return (int) - file-descriptorType: FUNCTION Get host by name
Parameters
name (const char*) - Hostname to resolveaddress (Address*) - Host address resultipv4 (bool) - Whether or not to search for IPv4 addressesipv6 (bool) - Whether or not to search for IPv6 addressesReturns
return (Result) - RESULT_OK on successType: FUNCTION Get host by name with timeout and cancelability
Notes
Parameters
name (const char*) - Hostname to resolveaddress (Address*) - Host address resulttimeout (uint64_t) - Timeout in microsecondscancelflag (int*) - if non null and set, will abort the callipv4 (bool) - Whether or not to search for IPv4 addressesipv6 (bool) - Whether or not to search for IPv6 addressesReturns
return (Result) - RESULT_OK on successType: CONSTANT Invalid socket handle
Type: FUNCTION Create a new socket. Corresponds to BSD socket function socket().
Notes
Parameters
type (Type) - Socket typeprotocol (Protocol) - Protocolsocket (Socket*) - Pointer to socketReturns
return (Result) - RESULT_OK on succcessType: ENUM Network protocol
Members
PROTOCOL_TCPPROTOCOL_UDPType: FUNCTION Receive data on a socket
Notes
Parameters
socket (Socket) - Socket to receive data onbuffer[out] (void*) - Buffer to receive tolength (int) - Receive buffer lengthreceived_bytes[out] (int*) - Number of received bytes (result)Returns
return (Result) - RESULT_OK on successType: ENUM Socket result
Members
RESULT_OK - 0RESULT_ACCES - -1RESULT_AFNOSUPPORT - -2RESULT_WOULDBLOCK - -3RESULT_BADF - -4RESULT_CONNRESET - -5RESULT_DESTADDRREQ - -6RESULT_FAULT - -7RESULT_HOSTUNREACH - -8RESULT_INTR - -9RESULT_INVAL - -10RESULT_ISCONN - -11RESULT_MFILE - -12RESULT_MSGSIZE - -13RESULT_NETDOWN - -14RESULT_NETUNREACH - -15RESULT_NOBUFS - -17RESULT_NOTCONN - -20RESULT_NOTSOCK - -22RESULT_OPNOTSUPP - -23RESULT_PIPE - -24RESULT_PROTONOSUPPORT - -25RESULT_PROTOTYPE - -26RESULT_TIMEDOUT - -27RESULT_ADDRNOTAVAIL - -28RESULT_CONNREFUSED - -29RESULT_ADDRINUSE - -30RESULT_CONNABORTED - -31RESULT_INPROGRESS - -32RESULT_HOST_NOT_FOUND - -100RESULT_TRY_AGAIN - -101RESULT_NO_RECOVERY - -102RESULT_NO_DATA - -103RESULT_UNKNOWN - -1000Type: FUNCTION Convert result value to string
Parameters
result (Result) - Result to convertReturns
return (const char*) - Result as stringType: FUNCTION Select for pending data
Parameters
selector (Selector*) - Selectortimeout (int) - Timeout. For blocking pass -1. (microseconds)Returns
return (Result) - RESULT_OK on successType: STRUCT Selector
Type: FUNCTION Clear selector for socket. Similar to FD_CLR
Parameters
selector (Selector*) - Selectorselector_kind (SelectorKind) - Kind to clearsocket (Socket) - Socket to clearReturns
return (void)Type: FUNCTION Check if selector is set. Similar to FD_ISSET
Parameters
selector (Selector*) - Selectorselector_kind (SelectorKind) - Selector kindsocket (Socket) - Socket to check forReturns
return (bool) - True if set.Type: ENUM Selector kind
Members
SELECTOR_KIND_READSELECTOR_KIND_WRITESELECTOR_KIND_EXCEPTType: FUNCTION Set selector for socket. Similar to FD_SET
Parameters
selector (Selector*) - Selectorselector_kind (SelectorKind) - Kind to clearsocket (Socket) - Socket to setReturns
return (void)Type: FUNCTION Clear selector (all kinds). Similar to FD_ZERO
Parameters
selector (Selector*) - SelectorReturns
return (void)Type: FUNCTION Send a message on a socket
Notes
Parameters
socket (Socket) - Socket to send a message onbuffer (void*) - Buffer to sendlength (int) - Length of buffer to sendsent_bytes[out] (int*) - Number of bytes sent (result)Returns
return (Result) - RESULT_OK on successType: FUNCTION Set blocking option on a socket
Parameters
socket (Socket) - Socket to set blocking onblocking (bool) - True to blockReturns
return (Result) - RESULT_OK on successType: FUNCTION Set broadcast address option on socket. Socket option SO_BROADCAST on most platforms.
Parameters
socket (Socket) - Socket to set reuse address tobroadcast (bool) - True if broadcastReturns
return (Result) - RESULT_OK on successType: FUNCTION Set TCP_NODELAY on socket
Parameters
socket (Socket) - Socket to set TCP_NODELAY onno_delay (bool) - True for no delayReturns
return (Result) - RESULT_OK on successType: FUNCTION Set TCP_QUICKACK on socket
Notes
Parameters
socket (Socket) - Socket to set TCP_QUICKACK onuse_quick_ack (bool) - False to disable quick ackReturns
return (Result) - RESULT_OK on successType: FUNCTION Set socket receive timeout
Notes
Parameters
socket (Socket) - sockettimeout (uint64_t) - timeout in microsecondsReturns
return (Result) - RESULT_OK on successType: FUNCTION Set reuse socket address option on socket. Socket option SO_REUSEADDR on most platforms
Parameters
socket (Socket) - Socket to set reuse address toreuse (bool) - True if reuseReturns
return (Result) - RESULT_OK on successType: FUNCTION Set socket send timeout
Notes
Parameters
socket (Socket) - sockettimeout (uint64_t) - timeout in microsecondsReturns
return (Result) - RESULT_OK on successType: FUNCTION Shutdown part of a socket connection
Parameters
socket (Socket) - Socket to shutdown connection owhow (ShutdownType) - Shutdown typeReturns
return (Result) - RESULT_OK on successType: ENUM Socket shutdown type
Members
SHUTDOWNTYPE_READSHUTDOWNTYPE_WRITESHUTDOWNTYPE_READWRITEType: TYPEDEF Socket type definition
Notes
Type: CONSTANT Socket default timeout value
Type: ENUM Socket type
Members
TYPE_STREAMTYPE_DGRAM