NCBI C++ ToolKit
Classes | Macros | Typedefs | Enumerations | Enumerator | Functions | Variables
Socket Services
+ Collaboration diagram for Socket Services:

Classes

struct  SSOCK_ApproveInfo
 User-level connection approval hook. More...
 
struct  SSOCK_Poll
 I/O polling structure. More...
 
struct  SSOCK_ErrInfo
 
struct  SPOLLABLE_Poll
 
class  CPollable
 
class  CTrigger
 CTrigger:: More...
 
class  CSocket
 CSocket:: More...
 
class  CDatagramSocket
 CDatagramSocket:: More...
 
class  CListeningSocket
 CListeningSocket:: More...
 
class  CSocketAPI
 CSocketAPI:: More...
 
struct  CSocketAPI::SPoll
 Polling structure m_Event can be either of eIO_Open, eIO_Read, eIO_Write, eIO_ReadWrite. More...
 
class  CUNIXSocket
 
class  CUNIXListeningSocket
 

Macros

#define SOCK_Destroy(s)   SOCK_Close(s)
 
#define SOCK_NetToHostLong   SOCK_HostToNetLong
 
#define SOCK_NetToHostShort   SOCK_HostToNetShort
 
#define NCBI_SOCK_DEPRECATED   NCBI_DEPRECATED
 
#define SOCK_ntohl   SOCK_htonl
 
#define SOCK_ntohs   SOCK_htons
 
#define REG_CONN_TLS_LOGLEVEL   "TLS_LOGLEVEL"
 
#define DEF_CONN_TLS_LOGLEVEL   ""
 

Typedefs

typedef unsigned EBIO_Event
 
typedef unsigned EBIO_Status
 
typedef struct LSOCK_tagLSOCK
 
typedef struct SOCK_tagSOCK
 
typedef struct TRIGGER_tagTRIGGER
 
typedef EIO_Status(* FSOCK_ApproveHook) (const SSOCK_ApproveInfo *info, void *data)
 The approve hook is global per API and gets called with an arbitrary user "data", if so desired as a second argument, which was specified when the hook was installed with the SOCK_SetApproveHookAPI() call. More...
 
typedef unsigned int TSOCK_Flags
 bitwise "OR" of ESOCK_Flags More...
 
typedef void(* FSOCK_ErrHook) (const SSOCK_ErrInfo *info, void *data)
 
typedef struct SPOLLABLE_tag * POLLABLE
 
typedef struct SNcbiCredNCBI_CRED
 Opaque type for credentials. More...
 
typedef const struct SOCKSSL_structSOCKSSL
 Opaque type for SSL implementation. More...
 
typedef SOCKSSL(* FSSLSetup) (void)
 SSL setup callback. More...
 

Enumerations

enum  ENH_ByteOrder { eNH_HostByteOrder , eNH_NetworkByteOrder }
 Network and host byte order enumeration type. More...
 
enum  ESOCK_Type { eSOCK_Listening = 0 , eSOCK_Trigger = 1 , eSOCK_Socket = 2 , eSOCK_Datagram = 3 }
 Socket type (internal) More...
 
enum  ESOCK_Side { eSOCK_Server = 0 , eSOCK_Client = 1 }
 Sides of socket. More...
 
enum  ESOCK_IOWaitSysAPI { eSOCK_IOWaitSysAPIAuto , eSOCK_IOWaitSysAPIPoll , eSOCK_IOWaitSysAPISelect }
 Selector of I/O wait system API: auto, poll(), or select(). More...
 
enum  ESOCK_Flags {
  fSOCK_LogOff = eOff , fSOCK_LogOn = eOn , fSOCK_LogDefault = eDefault , fSOCK_KeepAlive = 8 ,
  fSOCK_BindAny = 0 , fSOCK_BindLocal = 0x10 , fSOCK_KeepOnExec = 0x20 , fSOCK_CloseOnExec = 0 ,
  fSOCK_Secure = 0x40 , fSOCK_KeepOnClose = 0x80 , fSOCK_CloseOnClose = 0 , fSOCK_ReadOnWrite = 0x100 ,
  fSOCK_InterruptOnSignal = 0x200
}
 
enum  ESOCK_AddressFormat { eSAF_Full = 0 , eSAF_Port , eSAF_IP }
 Get textual representation of the socket's peer. More...
 
enum  ESOCK_ErrType { eSOCK_ErrInit = 1 , eSOCK_ErrDns , eSOCK_ErrIO }
 User-level error hook. More...
 
enum  ECopyTimeout { eCopyTimeoutsFromSOCK , eCopyTimeoutsToSOCK }
 

Functions

SOCKSSL NcbiSetupGnuTls (void)
 Explicitly setup GNUTLS library to support SSL in ncbi_socket.h[pp]. More...
 
NCBI_CRED NcbiCredGnuTls (void *xcred)
 Convert a native GNUTLS certificate credentials' handle into an abstract toolkit handle. More...
 
SOCKSSL NcbiSetupMbedTls (void)
 Explicitly setup mbedTLS library to support SSL in ncbi_socket.h[pp]. More...
 
NCBI_CRED NcbiCredMbedTls (void *xcert, void *xpkey)
 Convert native mbedTLS certificate credentials' handles into an abstract toolkit handle. More...
 
EIO_Status SOCK_InitializeAPI (void)
 Initialize all internal/system data & resources to be used by the SOCK API. More...
 
EIO_Status SOCK_ShutdownAPI (void)
 Cleanup; destroy all internal/system data & resources used by the SOCK API. More...
 
size_t SOCK_OSHandleSize (void)
 Get size of OS-dependent native socket handle. More...
 
void SOCK_AllowSigPipeAPI (void)
 By default (on UNIX platforms) the SOCK API functions automagically call "signal(SIGPIPE, SIG_IGN)" on initialization. More...
 
void SOCK_SetApproveHookAPI (FSOCK_ApproveHook hook, void *data)
 The hook is installed when non-NULL, and de-installed otherwise. More...
 
const STimeoutSOCK_SetSelectInternalRestartTimeout (const STimeout *timeslice)
 This is a helper call that can improve I/O behavior. More...
 
ESOCK_IOWaitSysAPI SOCK_SetIOWaitSysAPI (ESOCK_IOWaitSysAPI api)
 This is a helper call that can improve I/O performance (ignored for MSVC). More...
 
EIO_Status TRIGGER_Create (TRIGGER *trigger, ESwitch log)
 Create an event trigger. More...
 
EIO_Status TRIGGER_Close (TRIGGER trigger)
 Close an event trigger. More...
 
EIO_Status TRIGGER_Set (TRIGGER trigger)
 Set an event trigger. More...
 
EIO_Status TRIGGER_IsSet (TRIGGER trigger)
 Check whether the trigger has been set. More...
 
EIO_Status TRIGGER_Reset (TRIGGER trigger)
 Reset the trigger. More...
 
EIO_Status LSOCK_CreateEx (unsigned short port, unsigned short backlog, LSOCK *lsock, TSOCK_Flags flags)
 [SERVER-side] Create and initialize the server-side(listening) socket (socket() + bind() + listen()) More...
 
EIO_Status LSOCK_Create (unsigned short port, unsigned short backlog, LSOCK *lsock)
 [SERVER-side] Create and initialize the server-side(listening) socket Same as LSOCK_CreateEx() called with the last argument provided as fSOCK_LogDefault. More...
 
EIO_Status LSOCK_AcceptEx (LSOCK lsock, const STimeout *timeout, SOCK *sock, TSOCK_Flags flags)
 [SERVER-side] Accept connection from a client. More...
 
EIO_Status LSOCK_Accept (LSOCK lsock, const STimeout *timeout, SOCK *sock)
 [SERVER-side] Accept connection from a client. More...
 
EIO_Status LSOCK_Close (LSOCK lsock)
 [SERVER-side] Close the listening socket, destroy relevant internal data. More...
 
EIO_Status LSOCK_GetOSHandleEx (LSOCK lsock, void *handle_buf, size_t handle_size, EOwnership owndership)
 Get an OS-dependent native socket handle to use by platform-specific API. More...
 
EIO_Status LSOCK_GetOSHandle (LSOCK lsock, void *handle_buf, size_t handle_size)
 Same as LSOCK_GetOSHandleEx(lsock, handle_buf, handle_size, eNoOwnership). More...
 
unsigned short LSOCK_GetPort (LSOCK lsock, ENH_ByteOrder byte_order)
 Get socket port number, which it listens on. More...
 
EIO_Status SOCK_CreateEx (const char *host, unsigned short port, const STimeout *timeout, SOCK *sock, const void *data, size_t size, TSOCK_Flags flags)
 [CLIENT-side] Connect client to another(server-side, listening) socket (socket() + connect() [+ select()]) More...
 
EIO_Status SOCK_Create (const char *host, unsigned short port, const STimeout *timeout, SOCK *sock)
 [CLIENT-side] Connect client to another(server-side, listening) socket (socket() + connect() [+ select()]) Equivalent to SOCK_CreateEx(host, port, timeout, sock, 0, 0, fSOCK_LogDefault). More...
 
EIO_Status SOCK_CreateOnTopEx (const void *handle, size_t handle_size, SOCK *sock, const void *data, size_t size, TSOCK_Flags flags)
 [SERVER-side] Create a SOCKet on top of either an OS-dependent "handle" (file descriptor on Unix, SOCKET on MS-Windows) or an existing SOCK object. More...
 
EIO_Status SOCK_CreateOnTop (const void *handle, size_t handle_size, SOCK *sock)
 [SERVER-side] Create a socket on top of a "handle". More...
 
EIO_Status SOCK_Reconnect (SOCK sock, const char *host, unsigned short port, const STimeout *timeout)
 [CLIENT-side] Close the socket referred to by "sock" and then connect it to another "host:port"; fail if it takes more than "timeout" (close() + connect() [+ select()]) More...
 
EIO_Status SOCK_Shutdown (SOCK sock, EIO_Event how)
 Shutdown the connection in only one direction (specified by "direction"). More...
 
EIO_Status SOCK_Close (SOCK sock)
 Close the SOCK handle, and destroy all relevant internal data. More...
 
EIO_Status SOCK_CloseEx (SOCK sock, int destroy)
 Close the SOCK handle, and conditionally destroy relevant internal data. More...
 
EIO_Status SOCK_CloseOSHandle (const void *handle, size_t handle_size)
 Close socket OS handle (ungracefully aborting the connection if necessary). More...
 
EIO_Status SOCK_Wait (SOCK sock, EIO_Event event, const STimeout *timeout)
 Block on the socket until either the specified "event" is available or "timeout" expires (if "timeout" is NULL then assume it infinite). More...
 
EIO_Status SOCK_Poll (size_t n, SSOCK_Poll polls[], const STimeout *timeout, size_t *n_ready)
 Block until at least one of the sockets enlisted in "polls" array (of size "n") becomes available for requested operation (SSOCK_Poll::event), or until timeout expires (wait indefinitely if timeout is passed as NULL). More...
 
EIO_Status SOCK_SetTimeout (SOCK sock, EIO_Event event, const STimeout *timeout)
 Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()). More...
 
const STimeoutSOCK_GetTimeout (SOCK sock, EIO_Event event)
 Get the connection's i/o timeout (or NULL, if the timeout is infinite). More...
 
EIO_Status SOCK_Read (SOCK sock, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
 Read/peek up to "size" bytes from "sock" to a buffer pointed to by "buf". More...
 
EIO_Status SOCK_ReadLine (SOCK sock, char *line, size_t size, size_t *n_read)
 Read a line from SOCK. More...
 
EIO_Status SOCK_Pushback (SOCK sock, const void *data, size_t size)
 Push the specified data back to the socket's input queue (in the socket's internal read buffer). More...
 
EIO_Status SOCK_Status (SOCK sock, EIO_Event direction)
 Return low-level socket I/O status of *last* socket operation. More...
 
EIO_Status SOCK_Write (SOCK sock, const void *data, size_t size, size_t *n_written, EIO_WriteMethod how)
 Write "size" bytes of "data" to "sock". More...
 
EIO_Status SOCK_Abort (SOCK sock)
 If there is outstanding connection or output data pending, cancel it. More...
 
unsigned short SOCK_GetLocalPortEx (SOCK sock, int trueport, ENH_ByteOrder byte_order)
 Get local port of the socket (true or cached / stored). More...
 
unsigned short SOCK_GetLocalPort (SOCK sock, ENH_ByteOrder byte_order)
 Get local port of the socket. More...
 
void SOCK_GetPeerAddress (SOCK sock, unsigned int *host, unsigned short *port, ENH_ByteOrder byte_order)
 Get host and port of the socket's peer (remote end). More...
 
unsigned short SOCK_GetRemotePort (SOCK sock, ENH_ByteOrder byte_order)
 Get remote port of the socket (the port it is connected to). More...
 
char * SOCK_GetPeerAddressStringEx (SOCK sock, char *buf, size_t bufsize, ESOCK_AddressFormat format)
 
char * SOCK_GetPeerAddressString (SOCK sock, char *buf, size_t bufsize)
 Equivalent to SOCK_GetPeerAddressStringEx(.,.,.,eSAF_Full) More...
 
EIO_Status SOCK_GetOSHandleEx (SOCK sock, void *handle_buf, size_t handle_size, EOwnership ownership)
 Get an OS-dependent native socket handle to use by platform-specific API. More...
 
EIO_Status SOCK_GetOSHandle (SOCK sock, void *handle_buf, size_t handle_size)
 Same as SOCK_GetOSHandleEx(sock, handle_buf, handle_size, eNoOwnership). More...
 
ESwitch SOCK_SetReadOnWriteAPI (ESwitch on_off)
 By default, sockets will not try to read data from inside SOCK_Write(). More...
 
ESwitch SOCK_SetReadOnWrite (SOCK sock, ESwitch on_off)
 Control the reading-while-writing feature for socket "sock" individually. More...
 
void SOCK_SetCork (SOCK sock, int on_off)
 Control OS-defined send strategy by disabling/enabling the TCP layer to send incomplete network frames (packets). More...
 
void SOCK_DisableOSSendDelay (SOCK sock, int on_off)
 Control OS-defined send strategy by disabling/enabling the TCP Nagle algorithm (which is on by default) that packs multiple requests into a single packet and thus transfers the data in fewer transactions, miminizing the network traffic and generally bursting the throughput. More...
 
EIO_Status DSOCK_CreateEx (SOCK *sock, TSOCK_Flags flags)
 Create a datagram socket. More...
 
EIO_Status DSOCK_Create (SOCK *sock)
 Same as DSOCK_CreateEx(, fSOCK_LogDefault) More...
 
EIO_Status DSOCK_Bind (SOCK sock, unsigned short port)
 Assosiate a datagram socket with a local port. More...
 
EIO_Status DSOCK_Connect (SOCK sock, const char *host, unsigned short port)
 Associate a datagram socket with a destination address. More...
 
EIO_Status DSOCK_WaitMsg (SOCK sock, const STimeout *timeout)
 Wait for a datagram in a datagram socket. More...
 
EIO_Status DSOCK_SendMsg (SOCK sock, const char *host, unsigned short port, const void *data, size_t datalen)
 Send a datagram to a datagram socket. More...
 
EIO_Status DSOCK_RecvMsg (SOCK sock, void *buf, size_t bufsize, size_t maxmsglen, size_t *msglen, unsigned int *sender_addr, unsigned short *sender_port)
 Receive a datagram from a datagram socket. More...
 
EIO_Status DSOCK_WipeMsg (SOCK sock, EIO_Event direction)
 Clear message froma datagram socket. More...
 
EIO_Status DSOCK_SetBroadcast (SOCK sock, int broadcast)
 Set a datagram socket for broadcast. More...
 
TNCBI_BigCount DSOCK_GetMessageCount (SOCK sock, EIO_Event direction)
 Get message count. More...
 
int SOCK_IsDatagram (SOCK sock)
 Check whether a socket is a datagram one. More...
 
int SOCK_IsClientSide (SOCK sock)
 Check whether a socket is client-side. More...
 
int SOCK_IsServerSide (SOCK sock)
 Check whether a socket is server-side. More...
 
int SOCK_IsUNIX (SOCK sock)
 Check whether a socket is UNIX type. More...
 
int SOCK_IsSecure (SOCK sock)
 Check whether a socket is using SSL (Secure Socket Layer). More...
 
TNCBI_BigCount SOCK_GetPosition (SOCK sock, EIO_Event direction)
 Get current read or write position within a socket. More...
 
TNCBI_BigCount SOCK_GetCount (SOCK sock, EIO_Event direction)
 Get counts of read or written bytes. More...
 
TNCBI_BigCount SOCK_GetTotalCount (SOCK sock, EIO_Event direction)
 Get the total volume of data transferred by a socket. More...
 
ESwitch SOCK_SetInterruptOnSignalAPI (ESwitch on_off)
 Control restartability of I/O interrupted by signals. More...
 
ESwitch SOCK_SetInterruptOnSignal (SOCK sock, ESwitch on_off)
 Control restartability of I/O interrupted by signals on a per-socket basis. More...
 
ESwitch SOCK_SetReuseAddressAPI (ESwitch on_off)
 Control address reuse for socket addresses taken by the API. More...
 
void SOCK_SetReuseAddress (SOCK sock, int on_off)
 Control reuse of socket addresses on per-socket basis Note: only a boolean parameter value is can be used here. More...
 
ESwitch SOCK_SetDataLoggingAPI (ESwitch log)
 By default data are not logged. More...
 
ESwitch SOCK_SetDataLogging (SOCK sock, ESwitch log)
 Control the data logging for socket "sock" individually. More...
 
void SOCK_SetErrHookAPI (FSOCK_ErrHook hook, void *data)
 
EIO_Status POLLABLE_Poll (size_t n, SPOLLABLE_Poll polls[], const STimeout *timeout, size_t *n_ready)
 Poll for I/O readiness. More...
 
ESOCK_Type POLLABLE_What (POLLABLE)
 Identifies a non-NULL POLLABLE. More...
 
POLLABLE POLLABLE_FromSOCK (SOCK)
 Conversion utilities from handles to POLLABLEs, and back. More...
 
POLLABLE POLLABLE_FromLSOCK (LSOCK)
 
POLLABLE POLLABLE_FromTRIGGER (TRIGGER)
 
SOCK POLLABLE_ToSOCK (POLLABLE)
 
LSOCK POLLABLE_ToLSOCK (POLLABLE)
 
TRIGGER POLLABLE_ToTRIGGER (POLLABLE)
 
int SOCK_ntoa (unsigned int addr, char *buf, size_t bufsize)
 Convert IP address to a string in dotted notation. More...
 
int SOCK_isipEx (const char *host, int fullquad)
 Check whether the given string represents a valid IPv4 address. More...
 
int SOCK_isip (const char *host)
 Equivalent of SOCK_isip(host, 0) More...
 
int SOCK_IsLoopbackAddress (unsigned int ip)
 Check whether an address is a loopback one. More...
 
unsigned int SOCK_HostToNetLong (unsigned int value)
 See man for the BSDisms, htonl() and htons(). More...
 
unsigned short SOCK_HostToNetShort (unsigned short value)
 See man for the BSDisms, htonl() and htons(). More...
 
unsigned int SOCK_htonl (unsigned int)
 
unsigned short SOCK_htons (unsigned short)
 
int SOCK_gethostnameEx (char *name, size_t namelen, ESwitch log)
 Get the local host name. More...
 
int SOCK_gethostname (char *name, size_t namelen)
 Same as SOCK_gethostnameEx(,,<current API data logging>) More...
 
unsigned int SOCK_gethostbynameEx (const char *hostname, ESwitch log)
 Find and return IPv4 address of a named host. More...
 
unsigned int SOCK_gethostbyname (const char *hostname)
 Same as SOCK_gethostbynameEx(,<current API data logging>) More...
 
const char * SOCK_gethostbyaddrEx (unsigned int addr, char *name, size_t namelen, ESwitch log)
 Take IPv4 host address (in network byte order) or 0 for current host, and fill out the provided buffer with the name, which the address corresponds to (in case of multiple names the primary name is used). More...
 
const char * SOCK_gethostbyaddr (unsigned int addr, char *name, size_t namelen)
 Same as SOCK_gethostbyaddrEx(,,<current API data logging>) More...
 
unsigned int SOCK_GetLoopbackAddress (void)
 Get loopback IPv4 address. More...
 
unsigned int SOCK_GetLocalHostAddress (ESwitch reget)
 Get (and cache for faster follow-up retrievals) IPv4 address of local host. More...
 
const char * SOCK_StringToHostPort (const char *str, unsigned int *host, unsigned short *port)
 Read (skipping leading blanks) "[host][:port]" from a string stopping at either EOL or a blank character. More...
 
size_t SOCK_HostPortToString (unsigned int host, unsigned short port, char *buf, size_t bufsize)
 Print numeric string "host:port" into a buffer provided, not to exceed 'bufsize' bytes (including the teminating '\0' character). More...
 
void SOCK_SetupSSL (FSSLSetup setup)
 Store SSL setup callback until actual initialization. More...
 
EIO_Status SOCK_SetupSSLEx (FSSLSetup setup)
 Take SSL setup callback, and then init the entire API (SOCK + SSL). More...
 
const char * SOCK_SSLName (void)
 Return an SSL provider name (in a const static storage), with special considerations: return NULL if SSL has not been set up (yet), and return "" if SSL has not been (properly) initialized for use. More...
 
virtual EIO_Status CPollable::GetOSHandle (void *handle_buf, size_t handle_size, EOwnership ownership=eNoOwnership) const =0
 
virtual POLLABLE CPollable::GetPOLLABLE (void) const =0
 
virtual CPollable::~CPollable ()
 
 CPollable::CPollable (void)
 
 CPollable::CPollable (const CPollable &)
 
CPollableCPollable::operator= (const CPollable &)
 
 CTrigger::CTrigger (ESwitch log=eDefault)
 IMPLEMENTATION of INLINE functions. More...
 
virtual CTrigger::~CTrigger ()
 
EIO_Status CTrigger::GetStatus (void) const
 
EIO_Status CTrigger::Set (void)
 
EIO_Status CTrigger::IsSet (void)
 
EIO_Status CTrigger::Reset (void)
 
virtual EIO_Status CTrigger::GetOSHandle (void *handle_buf, size_t handle_size, EOwnership ownership=eNoOwnership) const
 Access to the system-specific handle. More...
 
TRIGGER CTrigger::GetTRIGGER (void) const
 Access to the underlying "TRIGGER". More...
 
virtual POLLABLE CTrigger::GetPOLLABLE (void) const
 
 CSocket::CSocket (void)
 CSocket:: More...
 
 CSocket::CSocket (const string &host, unsigned short port, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 Create a client-side socket connected to "host:port". More...
 
 CSocket::CSocket (const string &hostport, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 Create a client-side socket connected to "host:port". More...
 
 CSocket::CSocket (unsigned int host, unsigned short port, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 Variant of the above, which takes host as a binary value in network byte order. More...
 
virtual CSocket::~CSocket (void)
 Call Close(), then self-destruct. More...
 
EIO_Status CSocket::GetStatus (EIO_Event direction) const
 Return status of *last* I/O operation without making any actual I/O. More...
 
EIO_Status CSocket::Connect (const string &host, unsigned short port, const STimeout *timeout=kDefaultTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 Connect to "host:port". More...
 
EIO_Status CSocket::Connect (const string &hostport, const STimeout *timeout=kDefaultTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 Connect to "host:port". More...
 
EIO_Status CSocket::Reconnect (const STimeout *timeout=kDefaultTimeout)
 Reconnect to the same address. More...
 
EIO_Status CSocket::Shutdown (EIO_Event how)
 Shutdown socket I/O in the specified direction. More...
 
EIO_Status CSocket::Close (void)
 Close socket. More...
 
EIO_Status CSocket::Wait (EIO_Event event, const STimeout *timeout)
 Wait for I/O availability in the socket. More...
 
EIO_Status CSocket::SetTimeout (EIO_Event event, const STimeout *timeout)
 Set timeout for I/O in the specified direction. More...
 
const STimeoutCSocket::GetTimeout (EIO_Event event) const
 Get timeout for I/O in the specified direction. More...
 
EIO_Status CSocket::Read (void *buf, size_t size, size_t *n_read=0, EIO_ReadMethod how=eIO_ReadPlain)
 Read from socket. More...
 
EIO_Status CSocket::ReadLine (string &str)
 Read a line from socket (up to CR-LF, LF, or null character, discarding any of the EOLs). More...
 
EIO_Status CSocket::ReadLine (char *buf, size_t size, size_t *n_read=0)
 Read a line from socket (up to CR-LF, LF, or null character, discarding any of the EOLs). More...
 
EIO_Status CSocket::Pushback (const void *buf, size_t size)
 Push back data to socket (to be read out first). More...
 
EIO_Status CSocket::Write (const void *buf, size_t size, size_t *n_written=0, EIO_WriteMethod how=eIO_WritePersist)
 Write to socket. More...
 
EIO_Status CSocket::Abort (void)
 Abort socket connection. More...
 
unsigned short CSocket::GetLocalPort (ENH_ByteOrder byte_order, bool trueport=false) const
 Get socket local port number. More...
 
unsigned short CSocket::GetRemotePort (ENH_ByteOrder byte_order) const
 Get socket remote port number. More...
 
void CSocket::GetPeerAddress (unsigned int *host, unsigned short *port, ENH_ByteOrder byte_order) const
 Get peer address. More...
 
string CSocket::GetPeerAddress (ESOCK_AddressFormat format=eSAF_Full) const
 Get peer address as a text string. More...
 
virtual EIO_Status CSocket::GetOSHandle (void *handle_buf, size_t handle_size, EOwnership ownership=eNoOwnership) const
 Access to the system-specific socket handle. More...
 
ESwitch CSocket::SetReadOnWrite (ESwitch read_on_write=eOn)
 
ESwitch CSocket::SetInterruptOnSignal (ESwitch interrupt=eOn)
 
void CSocket::SetReuseAddress (ESwitch reuse=eOff)
 
void CSocket::SetCork (bool on_off=true)
 
void CSocket::DisableOSSendDelay (bool on_off=true)
 
ESwitch CSocket::SetDataLogging (ESwitch log=eOn)
 
bool CSocket::IsDatagram (void) const
 
bool CSocket::IsClientSide (void) const
 
bool CSocket::IsServerSide (void) const
 
bool CSocket::IsUNIX (void) const
 
bool CSocket::IsSecure (void) const
 
TNCBI_BigCount CSocket::GetPosition (EIO_Event direction) const
 Positions and stats (direction is either eIO_Read or eIO_Write). More...
 
TNCBI_BigCount CSocket::GetCount (EIO_Event direction) const
 
TNCBI_BigCount CSocket::GetTotalCount (EIO_Event direction) const
 
void CSocket::Reset (SOCK sock, EOwnership if_to_own, ECopyTimeout whence)
 Close the current underlying "SOCK" (if any, and if owned), and from now on use "sock" as the underlying "SOCK" instead. More...
 
EOwnership CSocket::SetOwnership (EOwnership if_to_own)
 Specify if this "CSocket" is to own the underlying "SOCK". More...
 
SOCK CSocket::GetSOCK (void) const
 Access to the underlying "SOCK". More...
 
bool CSocket::IsEmpty (void) const
 
virtual POLLABLE CSocket::GetPOLLABLE (void) const
 
 CDatagramSocket::CDatagramSocket (TSOCK_Flags flags=fSOCK_LogDefault)
 CDatagramSocket:: More...
 
EIO_Status CDatagramSocket::Bind (unsigned short port)
 
EIO_Status CDatagramSocket::Connect (const string &host, unsigned short port)
 
EIO_Status CDatagramSocket::Connect (const string &hostport)
 
EIO_Status CDatagramSocket::Connect (unsigned int host, unsigned short port)
 
EIO_Status CDatagramSocket::Wait (const STimeout *timeout=kInfiniteTimeout)
 
EIO_Status CDatagramSocket::Recv (void *buf, size_t buflen, size_t *msglen=0, string *sender_host=0, unsigned short *sender_port=0, size_t maxmsglen=0)
 
EIO_Status CDatagramSocket::Send (const void *data, size_t datalen, const string &host=string(), unsigned short port=0)
 
EIO_Status CDatagramSocket::Clear (EIO_Event direction)
 
EIO_Status CDatagramSocket::SetBroadcast (bool do_broadcast=true)
 
TNCBI_BigCount CDatagramSocket::GetMessageCount (EIO_Event direction) const
 Message count. More...
 
EIO_Status CDatagramSocket::Shutdown (EIO_Event how)
 
EIO_Status CDatagramSocket::Reconnect (const STimeout *timeout)
 
EIO_Status CDatagramSocket::Abort (void)
 
 CListeningSocket::CListeningSocket (void)
 CListeningSocket:: More...
 
 CListeningSocket::CListeningSocket (unsigned short port, unsigned short backlog=64, TSOCK_Flags flags=fSOCK_LogDefault)
 
virtual CListeningSocket::~CListeningSocket (void)
 Call Close(), then self-destruct. More...
 
EIO_Status CListeningSocket::GetStatus (void) const
 Return eIO_Closed if not yet bound or Close()'d. More...
 
EIO_Status CListeningSocket::Listen (unsigned short port, unsigned short backlog=64, TSOCK_Flags flags=fSOCK_LogDefault)
 
EIO_Status CListeningSocket::Accept (CSocket *&sock, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault) const
 
EIO_Status CListeningSocket::Accept (CSocket &sock, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault) const
 
EIO_Status CListeningSocket::Close (void)
 
virtual EIO_Status CListeningSocket::GetOSHandle (void *handle_buf, size_t handle_size, EOwnership ownership=eNoOwnership) const
 Access to the system-specific socket handle. More...
 
unsigned short CListeningSocket::GetPort (ENH_ByteOrder byte_order) const
 Return port which the server listens on. More...
 
EOwnership CListeningSocket::SetOwnership (EOwnership if_to_own)
 Specify if this "CListeningSocket" is to own the underlying "LSOCK". More...
 
LSOCK CListeningSocket::GetLSOCK (void) const
 Access to the underlying "LSOCK". More...
 
bool CListeningSocket::IsEmpty (void) const
 
virtual POLLABLE CListeningSocket::GetPOLLABLE (void) const
 
static EIO_Status CSocketAPI::Initialize (void)
 Generic. More...
 
static EIO_Status CSocketAPI::Shutdown (void)
 
static void CSocketAPI::AllowSigPipe (void)
 
static size_t CSocketAPI::OSHandleSize (void)
 
static EIO_Status CSocketAPI::CloseOSHandle (const void *handle, size_t handle_size)
 
static const STimeoutCSocketAPI::SetSelectInternalRestartTimeout (const STimeout *timeout)
 Utility. More...
 
static ESOCK_IOWaitSysAPI CSocketAPI::SetIOWaitSysAPI (ESOCK_IOWaitSysAPI api)
 
static ESwitch CSocketAPI::SetReadOnWrite (ESwitch read_on_write)
 Defaults (see also per-socket CSocket::SetReadOnWrite, etc.) More...
 
static ESwitch CSocketAPI::SetInterruptOnSignal (ESwitch interrupt)
 
static ESwitch CSocketAPI::SetReuseAddress (ESwitch reuse)
 
static ESwitch CSocketAPI::SetDataLogging (ESwitch log)
 
 CSocketAPI::SPoll::SPoll (CPollable *pollable=0, EIO_Event event=eIO_Open)
 
static EIO_Status CSocketAPI::Poll (vector< SPoll > &polls, const STimeout *timeout, size_t *n_ready=0)
 Poll a vector of CPollable objects for I/O readiness. More...
 
static string CSocketAPI::ntoa (unsigned int host)
 BSD-like API. NB: when int, "host" must be in network byte order. More...
 
static bool CSocketAPI::isip (const string &host, bool fullquad=false)
 
static unsigned int CSocketAPI::HostToNetLong (unsigned int value)
 
static unsigned int CSocketAPI::NetToHostLong (unsigned int value)
 
static unsigned short CSocketAPI::HostToNetShort (unsigned short value)
 
static unsigned short CSocketAPI::NetToHostShort (unsigned short value)
 
static string CSocketAPI::gethostname (ESwitch log=eOff)
 Return empty string on error. More...
 
static string CSocketAPI::gethostbyaddr (unsigned int host, ESwitch log=eOff)
 Return empty string on error. More...
 
static unsigned int CSocketAPI::gethostbyname (const string &host, ESwitch log=eOff)
 Return 0 on error. More...
 
static unsigned int CSocketAPI::GetLoopbackAddress (void)
 Loopback address gets returned in network byte order. More...
 
static unsigned int CSocketAPI::GetLocalHostAddress (ESwitch reget=eDefault)
 Local host address in network byte order (cached for faster retrieval) More...
 
static string CSocketAPI::HostPortToString (unsigned int host, unsigned short port)
 See SOCK_HostPortToString() More...
 
static SIZE_TYPE CSocketAPI::StringToHostPort (const string &str, unsigned int *host, unsigned short *port)
 Return position past the end of the parsed portion, NPOS on error. More...
 
EIO_Status LSOCK_CreateUNIX (const char *path, unsigned short backlog, LSOCK *lsock, TSOCK_Flags flags)
 
EIO_Status SOCK_CreateUNIX (const char *path, const STimeout *timeout, SOCK *sock, const void *data, size_t size, TSOCK_Flags flags)
 
 CUNIXSocket::CUNIXSocket (void)
 
 CUNIXSocket::CUNIXSocket (const string &filename, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 
EIO_Status CUNIXSocket::Connect (const string &filename, const STimeout *timeout=kDefaultTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
 
 CUNIXListeningSocket::CUNIXListeningSocket (void)
 
 CUNIXListeningSocket::CUNIXListeningSocket (const string &filename, unsigned short backlog=64, TSOCK_Flags flags=fSOCK_LogDefault)
 IMPLEMENTATION of INLINE functions. More...
 
EIO_Status CUNIXListeningSocket::Listen (const string &filename, unsigned short backlog=64, TSOCK_Flags flags=fSOCK_LogDefault)
 
SOCKSSL NcbiSetupTls (void)
 Setup a TLS (Transport Layer Security) provider library to support SSL in ncbi_socket.h[pp]. More...
 
NCBI_CRED NcbiCreateTlsCertCredentials (const void *cert, size_t certsz, const void *pkey, size_t pkeysz)
 Build NCBI_CRED from memory buffers containing X.509 certificate and private key, respectively, in either PEM or DER format (independently of each other). More...
 
void NcbiDeleteTlsCertCredentials (NCBI_CRED cred)
 Delete a NCBI_CRED handle created by NcbiCreateTlsCertCredentials(). More...
 

Variables

const char * SSOCK_ApproveInfo::host
 Textual hostname if provided for outgoing. More...
 
unsigned int SSOCK_ApproveInfo::addr
 IPv4 (or -1 if unknown / broadcast), never 0. More...
 
unsigned short SSOCK_ApproveInfo::port
 Port number, host byte order, never 0. More...
 
ESOCK_Side SSOCK_ApproveInfo::side
 eSOCK_Client (out) / eSOCK_Server (in) More...
 
ESOCK_Type SSOCK_ApproveInfo::type
 eSOCK_Socket (conn) / eSOCK_Datagram (packet) More...
 
SOCK SSOCK_Poll::sock
 
EIO_Event SSOCK_Poll::event
 [in] SOCK to poll (NULL if not to poll) More...
 
EIO_Event SSOCK_Poll::revent
 [in] one of: eIO_Open/Read/Write/ReadWrite More...
 
ESOCK_ErrType SSOCK_ErrInfo::type
 See ESOCK_ErrType. More...
 
SOCK SSOCK_ErrInfo::sock
 Non-NULL when SOCK-related. More...
 
const char * SSOCK_ErrInfo::host
 Host name/IP (or path for non-IP SOCK) More...
 
unsigned short SSOCK_ErrInfo::port
 Port (host byte order), 0 for non-IP SOCK. More...
 
EIO_Event SSOCK_ErrInfo::event
 Meaningful only for the eSOCK_ErrIO type. More...
 
EIO_Status SSOCK_ErrInfo::status
 Status code about to be returned (if known) More...
 
POLLABLE SPOLLABLE_Poll::poll
 
EIO_Event SPOLLABLE_Poll::event
 
EIO_Event SPOLLABLE_Poll::revent
 
TRIGGER CTrigger::m_Trigger
 
SOCK CSocket::m_Socket
 
EOwnership CSocket::m_IsOwned
 Timeouts. More...
 
STimeoutCSocket::o_timeout
 eIO_Open More...
 
STimeoutCSocket::r_timeout
 eIO_Read More...
 
STimeoutCSocket::w_timeout
 eIO_Write More...
 
STimeoutCSocket::c_timeout
 eIO_Close More...
 
STimeout CSocket::oo_timeout
 storage for o_timeout More...
 
STimeout CSocket::rr_timeout
 storage for r_timeout More...
 
STimeout CSocket::ww_timeout
 storage for w_timeout More...
 
STimeout CSocket::cc_timeout
 storage for c_timeout More...
 
LSOCK CListeningSocket::m_Socket
 
EOwnership CListeningSocket::m_IsOwned
 
CPollableCSocketAPI::SPoll::m_Pollable
 [in] object pointer (or NULL not to poll) More...
 
EIO_Event CSocketAPI::SPoll::m_Event
 [in] event inqury (or eIO_Open for none) More...
 
EIO_Event CSocketAPI::SPoll::m_REvent
 [out] event ready (eIO_Open if not ready) More...
 

Detailed Description

Macro Definition Documentation

◆ DEF_CONN_TLS_LOGLEVEL

#define DEF_CONN_TLS_LOGLEVEL   ""

Definition at line 89 of file ncbi_tls.h.

◆ NCBI_SOCK_DEPRECATED

#define NCBI_SOCK_DEPRECATED   NCBI_DEPRECATED

Definition at line 2113 of file ncbi_socket.h.

◆ REG_CONN_TLS_LOGLEVEL

#define REG_CONN_TLS_LOGLEVEL   "TLS_LOGLEVEL"

Definition at line 88 of file ncbi_tls.h.

◆ SOCK_Destroy

#define SOCK_Destroy (   s)    SOCK_Close(s)

Definition at line 875 of file ncbi_socket.h.

◆ SOCK_NetToHostLong

#define SOCK_NetToHostLong   SOCK_HostToNetLong

Definition at line 2096 of file ncbi_socket.h.

◆ SOCK_NetToHostShort

#define SOCK_NetToHostShort   SOCK_HostToNetShort

Definition at line 2106 of file ncbi_socket.h.

◆ SOCK_ntohl

#define SOCK_ntohl   SOCK_htonl

Definition at line 2117 of file ncbi_socket.h.

◆ SOCK_ntohs

#define SOCK_ntohs   SOCK_htons

Definition at line 2120 of file ncbi_socket.h.

Typedef Documentation

◆ EBIO_Event

typedef unsigned EBIO_Event

Definition at line 186 of file ncbi_socket.h.

◆ EBIO_Status

typedef unsigned EBIO_Status

Definition at line 187 of file ncbi_socket.h.

◆ FSOCK_ApproveHook

typedef EIO_Status(* FSOCK_ApproveHook) (const SSOCK_ApproveInfo *info, void *data)

The approve hook is global per API and gets called with an arbitrary user "data", if so desired as a second argument, which was specified when the hook was installed with the SOCK_SetApproveHookAPI() call.

Definition at line 356 of file ncbi_socket.h.

◆ FSOCK_ErrHook

typedef void(* FSOCK_ErrHook) (const SSOCK_ErrInfo *info, void *data)

Definition at line 1960 of file ncbi_socket.h.

◆ FSSLSetup

typedef SOCKSSL(* FSSLSetup) (void)

SSL setup callback.

Definition at line 2312 of file ncbi_socket.h.

◆ LSOCK

typedef struct LSOCK_tag* LSOCK

Definition at line 220 of file ncbi_socket.h.

◆ NCBI_CRED

typedef struct SNcbiCred* NCBI_CRED

Opaque type for credentials.

Definition at line 2303 of file ncbi_socket.h.

◆ POLLABLE

typedef struct SPOLLABLE_tag* POLLABLE

Definition at line 1976 of file ncbi_socket.h.

◆ SOCK

typedef struct SOCK_tag* SOCK

Definition at line 223 of file ncbi_socket.h.

◆ SOCKSSL

typedef const struct SOCKSSL_struct* SOCKSSL

Opaque type for SSL implementation.

Definition at line 2308 of file ncbi_socket.h.

◆ TRIGGER

typedef struct TRIGGER_tag* TRIGGER

Definition at line 226 of file ncbi_socket.h.

◆ TSOCK_Flags

typedef unsigned int TSOCK_Flags

bitwise "OR" of ESOCK_Flags

Definition at line 503 of file ncbi_socket.h.

Enumeration Type Documentation

◆ ECopyTimeout

Enumerator
eCopyTimeoutsFromSOCK 
eCopyTimeoutsToSOCK 

Definition at line 51 of file ncbi_socket.hpp.

◆ ENH_ByteOrder

Network and host byte order enumeration type.

Enumerator
eNH_HostByteOrder 
eNH_NetworkByteOrder 

Definition at line 192 of file ncbi_socket.h.

◆ ESOCK_AddressFormat

Get textual representation of the socket's peer.

For INET domain sockets, the result is of the form "aaa.bbb.ccc.ddd:ppppp"; for UNIX domain socket, the result is the name of the socket's file.

Parameters
sock[in] socket handle
buf[out] pointer to provided buffer to store the text to
bufsize[in] usable size of the buffer above
format[in] what parts of address to include
Returns
On success, return its "buf" argument; return 0 on error.
See also
SOCK_HostPortToString
Enumerator
eSAF_Full 

address in full, native form

eSAF_Port 

only numeric port if INET socket, empty otherwise

eSAF_IP 

only numeric IP if INET socket, empty otherwise

Definition at line 1389 of file ncbi_socket.h.

◆ ESOCK_ErrType

User-level error hook.

Enumerator
eSOCK_ErrInit 

Socket layer initialization error.

eSOCK_ErrDns 

DNS-related error (unresolvable hostname)

eSOCK_ErrIO 

I/O-related error.

Definition at line 1944 of file ncbi_socket.h.

◆ ESOCK_Flags

Enumerator
fSOCK_LogOff 

NB: logging is inherited in accepted SOCK.

fSOCK_LogOn 
fSOCK_LogDefault 
fSOCK_KeepAlive 

keep socket alive (if supported by OS)

fSOCK_BindAny 

bind to 0.0.0.0 (i.e.

any), default

fSOCK_BindLocal 

bind to 127.0.0.1 only

fSOCK_KeepOnExec 

can be applied to all sockets

fSOCK_CloseOnExec 

can be applied to all sockets, default

fSOCK_Secure 

subsumes CloseOnExec regardless of Keep

fSOCK_KeepOnClose 

retain OS handle in SOCK_Close[Ex]()

fSOCK_CloseOnClose 

close OS handle in SOCK_Close[Ex]()

fSOCK_ReadOnWrite 
fSOCK_InterruptOnSignal 

Definition at line 488 of file ncbi_socket.h.

◆ ESOCK_IOWaitSysAPI

Selector of I/O wait system API: auto, poll(), or select().

See also
SOCK_SetIOWaitSysAPI
Enumerator
eSOCK_IOWaitSysAPIAuto 

default; use some heuristics to choose API

eSOCK_IOWaitSysAPIPoll 

always use poll()

eSOCK_IOWaitSysAPISelect 

always use select()

Definition at line 384 of file ncbi_socket.h.

◆ ESOCK_Side

enum ESOCK_Side

Sides of socket.

Enumerator
eSOCK_Server 
eSOCK_Client 

Definition at line 210 of file ncbi_socket.h.

◆ ESOCK_Type

enum ESOCK_Type

Socket type (internal)

Enumerator
eSOCK_Listening 
eSOCK_Trigger 
eSOCK_Socket 
eSOCK_Datagram 

Definition at line 200 of file ncbi_socket.h.

Function Documentation

◆ Abort() [1/2]

EIO_Status CSocket::Abort ( void  )
inline

Abort socket connection.

See also
SOCK_Abort

Definition at line 920 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_Abort().

Referenced by SNetServerConnectionImpl::Abort(), and CServer_ConnectionPool::CloseConnection().

◆ Abort() [2/2]

EIO_Status CDatagramSocket::Abort ( void  )
protected
Note
The call is not valid with datagram sockets.

◆ Accept() [1/2]

EIO_Status CListeningSocket::Accept ( CSocket sock,
const STimeout timeout = kInfiniteTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
) const

◆ Accept() [2/2]

EIO_Status CListeningSocket::Accept ( CSocket *&  sock,
const STimeout timeout = kInfiniteTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
) const
Note
The created "CSocket" will own its underlying "SOCK".
Parameters
sock
timeout

Definition at line 526 of file ncbi_socket_cxx.cpp.

References assert, eCopyTimeoutsToSOCK, eIO_Success, eTakeOwnership, flags, LSOCK_AcceptEx(), CListeningSocket::m_Socket, CSocket::Reset(), SOCK_Abort(), and SOCK_Close().

Referenced by CAcceptRequest::CAcceptRequest().

◆ AllowSigPipe()

void CSocketAPI::AllowSigPipe ( void  )
inlinestatic

Definition at line 1199 of file ncbi_socket.hpp.

References SOCK_AllowSigPipeAPI().

◆ Bind()

EIO_Status CDatagramSocket::Bind ( unsigned short  port)
inline
Parameters
portport is in host byte order

Definition at line 1068 of file ncbi_socket.hpp.

References DSOCK_Bind(), and CSocket::m_Socket.

Referenced by SNetScheduleNotificationReceiver::SNetScheduleNotificationReceiver().

◆ CDatagramSocket()

CDatagramSocket::CDatagramSocket ( TSOCK_Flags  flags = fSOCK_LogDefault)
inline

CDatagramSocket::

Note
The created underlying "SOCK" will be owned by the object.
Parameters
do_log

Definition at line 1062 of file ncbi_socket.hpp.

References DSOCK_CreateEx(), flags, and CSocket::m_Socket.

◆ Clear()

EIO_Status CDatagramSocket::Clear ( EIO_Event  direction)
inline
Parameters
direction
See also
DSOCK_WipeMsg()

Definition at line 1098 of file ncbi_socket.hpp.

References DSOCK_WipeMsg(), and CSocket::m_Socket.

◆ CListeningSocket() [1/2]

CListeningSocket::CListeningSocket ( unsigned short  port,
unsigned short  backlog = 64,
TSOCK_Flags  flags = fSOCK_LogDefault 
)
inline
Note
"port" ought to be in host byte order
Parameters
port
backlog
flags

Definition at line 1128 of file ncbi_socket.hpp.

References flags, LSOCK_CreateEx(), and CListeningSocket::m_Socket.

◆ CListeningSocket() [2/2]

CListeningSocket::CListeningSocket ( void  )
inline

CListeningSocket::

Definition at line 1121 of file ncbi_socket.hpp.

◆ Close() [1/2]

EIO_Status CSocket::Close ( void  )
inline

Close socket.

Note
Closes the undelying SOCK only if it is owned by this "CSocket"!
See also
SOCK_CloseEx

Definition at line 926 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_CloseEx().

Referenced by SNetServerConnectionImpl::Close(), SNetServerImpl::ConnectImpl(), CBDBEnvKeeperConnectionHandler::OnMessage(), and s_ReadMessage().

◆ Close() [2/2]

EIO_Status CListeningSocket::Close ( void  )
Note
Closes the undelying LSOCK only if it is owned by this object!

Definition at line 572 of file ncbi_socket_cxx.cpp.

References eIO_Success, eNoOwnership, LSOCK_Close(), CListeningSocket::m_IsOwned, and CListeningSocket::m_Socket.

Referenced by CServer_Listener::Passivate(), and CListeningSocket::~CListeningSocket().

◆ CloseOSHandle()

EIO_Status CSocketAPI::CloseOSHandle ( const void *  handle,
size_t  handle_size 
)
inlinestatic

Definition at line 1211 of file ncbi_socket.hpp.

References SOCK_CloseOSHandle().

◆ Connect() [1/6]

EIO_Status CUNIXSocket::Connect ( const string filename,
const STimeout timeout = kDefaultTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

◆ Connect() [2/6]

EIO_Status CDatagramSocket::Connect ( const string host,
unsigned short  port 
)
inline
Parameters
hosthost name or IP address as a string
port"port" is in host byte order

Definition at line 1074 of file ncbi_socket.hpp.

References DSOCK_Connect(), and CSocket::m_Socket.

◆ Connect() [3/6]

EIO_Status CSocket::Connect ( const string host,
unsigned short  port,
const STimeout timeout = kDefaultTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

Connect to "host:port".

Note
Should not be called if already connected;
Timeout from the argument becomes new eIO_Open timeout.
Parameters
hosthost name (or text IP address) of the host to connect to
portport number to connect at "host", always in host byte order
timeoutmaximal time to wait for connection to be established
flagsadditional socket properties (including logging)
See also
SOCK_Create

Definition at line 144 of file ncbi_socket_cxx.cpp.

References assert, CSocket::c_timeout, eIO_Close, eIO_Open, eIO_Read, eIO_Success, eIO_Unknown, eIO_Write, eNoOwnership, flags, kDefaultTimeout, CSocket::m_IsOwned, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, CSocket::r_timeout, SOCK_Close(), SOCK_CreateEx(), SOCK_SetTimeout(), SOCK_Status(), and CSocket::w_timeout.

Referenced by SNetServerImpl::ConnectImpl().

◆ Connect() [4/6]

EIO_Status CDatagramSocket::Connect ( const string hostport)
Parameters
hostport"host:port" as a string (no-port and no-host accepted, such as ":0")

Definition at line 471 of file ncbi_socket_cxx.cpp.

References DSOCK_Connect(), eIO_Unknown, CSocket::m_Socket, SOCK_ntoa(), and SOCK_StringToHostPort().

◆ Connect() [5/6]

EIO_Status CSocket::Connect ( const string hostport,
const STimeout timeout = kDefaultTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

Connect to "host:port".

Note
Should not be called if already connected;
Timeout from the argument becomes new eIO_Open timeout.
Parameters
hostport"host:port" as a string
timeoutmaximal time to wait for connection to be established
flagsadditional socket properties (including logging)
See also
SOCK_Create

Definition at line 175 of file ncbi_socket_cxx.cpp.

References assert, CSocket::c_timeout, eIO_Close, eIO_Open, eIO_Read, eIO_Success, eIO_Unknown, eIO_Write, eNoOwnership, flags, kDefaultTimeout, CSocket::m_IsOwned, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, CSocket::r_timeout, SOCK_Close(), SOCK_CreateEx(), SOCK_ntoa(), SOCK_SetTimeout(), SOCK_Status(), SOCK_StringToHostPort(), and CSocket::w_timeout.

◆ Connect() [6/6]

EIO_Status CDatagramSocket::Connect ( unsigned int  host,
unsigned short  port 
)
Parameters
host"host" is accepted in network byte order
port"port" is in host one

Definition at line 459 of file ncbi_socket_cxx.cpp.

References DSOCK_Connect(), eIO_Unknown, CSocket::m_Socket, and SOCK_ntoa().

◆ CPollable() [1/2]

CPollable::CPollable ( const CPollable )
private

◆ CPollable() [2/2]

CPollable::CPollable ( void  )
inlineprotected

Definition at line 70 of file ncbi_socket.hpp.

◆ CSocket() [1/4]

CSocket::CSocket ( const string host,
unsigned short  port,
const STimeout timeout = kInfiniteTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

Create a client-side socket connected to "host:port".

Note
The created underlying "SOCK" will be owned by the "CSocket";
Timeout from the argument becomes new eIO_Open timeout.
Parameters
hosthost name (or text IP address) of the host to connect to
portport number to connect at "host", always in host byte order
timeoutmaximal time to wait for connection to be established
flagsadditional socket properties (including logging)
See also
CSocket::Connect, SOCK_Create

Definition at line 63 of file ncbi_socket_cxx.cpp.

References flags, kDefaultTimeout, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, and SOCK_CreateEx().

◆ CSocket() [2/4]

CSocket::CSocket ( const string hostport,
const STimeout timeout = kInfiniteTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

Create a client-side socket connected to "host:port".

Note
The created underlying "SOCK" will be owned by the "CSocket";
Timeout from the argument becomes new eIO_Open timeout.
Parameters
hostport"host:port" as a string
timeoutmaximal time to wait for connection to be established
flagsadditional socket properties (including logging)
See also
CSocket::Connect, SOCK_Create

Definition at line 79 of file ncbi_socket_cxx.cpp.

References flags, kDefaultTimeout, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, SOCK_CreateEx(), SOCK_ntoa(), and SOCK_StringToHostPort().

◆ CSocket() [3/4]

CSocket::CSocket ( unsigned int  host,
unsigned short  port,
const STimeout timeout = kInfiniteTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

Variant of the above, which takes host as a binary value in network byte order.

Parameters
hostnetwork byte order
porthost byte order
timeoutmaximal time to wait for connection to be established
flagsadditional socket properties (including logging)
See also
CSocket::Connect, SOCK_Create

Definition at line 103 of file ncbi_socket_cxx.cpp.

References flags, kDefaultTimeout, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, SOCK_CreateEx(), and SOCK_ntoa().

◆ CSocket() [4/4]

CSocket::CSocket ( void  )
inline

CSocket::

Definition at line 882 of file ncbi_socket.hpp.

◆ CTrigger()

CTrigger::CTrigger ( ESwitch  log = eDefault)
inline

IMPLEMENTATION of INLINE functions.

CTrigger::

Definition at line 835 of file ncbi_socket.hpp.

References log, CTrigger::m_Trigger, and TRIGGER_Create().

◆ CUNIXListeningSocket() [1/2]

CUNIXListeningSocket::CUNIXListeningSocket ( const string path,
unsigned short  backlog = 64,
TSOCK_Flags  flags = fSOCK_LogDefault 
)
inline

IMPLEMENTATION of INLINE functions.

CUNIXListeningSocket::

Definition at line 96 of file ncbi_socket_unix.hpp.

References flags, LSOCK_CreateUNIX(), and CListeningSocket::m_Socket.

◆ CUNIXListeningSocket() [2/2]

CUNIXListeningSocket::CUNIXListeningSocket ( void  )
inline

Definition at line 69 of file ncbi_socket_unix.hpp.

◆ CUNIXSocket() [1/2]

CUNIXSocket::CUNIXSocket ( const string filename,
const STimeout timeout = kInfiniteTimeout,
TSOCK_Flags  flags = fSOCK_LogDefault 
)

◆ CUNIXSocket() [2/2]

CUNIXSocket::CUNIXSocket ( void  )
inline

Definition at line 52 of file ncbi_socket_unix.hpp.

◆ DisableOSSendDelay()

void CSocket::DisableOSSendDelay ( bool  on_off = true)
inline

◆ DSOCK_Bind()

EIO_Status DSOCK_Bind ( SOCK  sock,
unsigned short  port 
)

Assosiate a datagram socket with a local port.

All other attempts to use the same port will result in eIO_Closed (for "port busy") unless SOCK_SetReuseAddress() is called, which then allows multiple sockets to bind to the same port, and receive messages, in undefined order, arriving at that port. Passing 0 will ask the OS to automatically choose an unused port, which then can be obtained via SOCK_GetLocalPort().

Parameters
sock[in] SOCK from DSOCK_Create[Ex]()
port[in] port to bind to (0 to auto-choose)
See also
SOCK_SetReuseAddress, SOCK_GetLocalPort

Definition at line 8001 of file ncbi_socket.c.

References assert, CORE_LOGF_ERRNO_EXX, CORE_LOGF_X, eDefault, eIO_InvalidArg, eIO_Open, eIO_Success, eIO_Unknown, eLOG_Error, eLOG_Note, eLOG_Trace, eOn, eSOCK_Datagram, eSOCK_Server, in(), INADDR_ANY, SOCK_tag::log, MAXIDLEN, SOCK_tag::myport, s_DoLog(), s_ID(), s_Log, SOCK_tag::side, SOCK_tag::sock, SOCK_EADDRINUSE, SOCK_ERRNO, SOCK_INVALID, SOCK_STRERROR, SOCK_tag::type, and UTIL_ReleaseBuffer.

Referenced by CDatagramSocket::Bind().

◆ DSOCK_Connect()

EIO_Status DSOCK_Connect ( SOCK  sock,
const char *  host,
unsigned short  port 
)

◆ DSOCK_Create()

EIO_Status DSOCK_Create ( SOCK sock)

Same as DSOCK_CreateEx(, fSOCK_LogDefault)

Parameters
sock[out] socket created

Definition at line 7857 of file ncbi_socket.c.

References DSOCK_CreateEx(), and fSOCK_LogDefault.

◆ DSOCK_CreateEx()

EIO_Status DSOCK_CreateEx ( SOCK sock,
TSOCK_Flags  flags 
)

◆ DSOCK_GetMessageCount()

TNCBI_BigCount DSOCK_GetMessageCount ( SOCK  sock,
EIO_Event  direction 
)

Get message count.

Parameters
sock[in] socket handle (datagram socket only)
direction[in] either eIO_Read (in) or eIO_Write (out)
Returns
Total number of messages sent or received through this datagram socket.

Definition at line 8409 of file ncbi_socket.c.

References assert, eIO_Read, eIO_Write, eSOCK_Datagram, SOCK_tag::n_in, SOCK_tag::n_out, and SOCK_tag::type.

Referenced by CDatagramSocket::GetMessageCount().

◆ DSOCK_RecvMsg()

EIO_Status DSOCK_RecvMsg ( SOCK  sock,
void *  buf,
size_t  bufsize,
size_t  maxmsglen,
size_t *  msglen,
unsigned int sender_addr,
unsigned short *  sender_port 
)

Receive a datagram from a datagram socket.

Parameters
sock[in] SOCK from DSOCK_Create[Ex]()
buf[in] buf to store msg at, may be NULL
bufsize[in] buf length provided
maxmsglen[in] maximal expected message len
msglen[out] actual msg size, may be NULL
sender_addr[out] net byte order, may be NULL
sender_port[out] host byte order, may be NULL
See also
SOCK_Read, SOCK_SetTimeout

Definition at line 8219 of file ncbi_socket.c.

References assert, buf, bufsize, CORE_LOGF_X, eIO_InvalidArg, eIO_Read, eIO_Success, eIO_Unknown, eLOG_Error, eSOCK_Datagram, eSOCK_ErrIO, SOCK_tag::host, info, MAXIDLEN, SOCK_tag::port, s_ErrHook, s_ErrorCallback(), s_ID(), s_RecvMsg(), SOCK_tag::sock, SOCK_INVALID, SOCK_ntoa(), and SOCK_tag::type.

Referenced by CDatagramSocket::Recv().

◆ DSOCK_SendMsg()

EIO_Status DSOCK_SendMsg ( SOCK  sock,
const char *  host,
unsigned short  port,
const void *  data,
size_t  datalen 
)

Send a datagram to a datagram socket.

Parameters
sock[in] SOCK from DSOCK_Create[Ex]()
host[in] hostname or dotted IP
port[in] port number, host byte order
data[in] additional data to send
datalen[in] size of additional data (bytes)
See also
SOCK_Write, SOCK_SetTimeout

Definition at line 8272 of file ncbi_socket.c.

References assert, CORE_LOGF_X, data, eIO_InvalidArg, eIO_Success, eIO_Write, eLOG_Error, eSOCK_Datagram, eSOCK_ErrIO, SOCK_tag::host, info, MAXIDLEN, SOCK_tag::port, s_ErrHook, s_ErrorCallback(), s_ID(), s_SendMsg(), SOCK_tag::sock, SOCK_INVALID, SOCK_ntoa(), and SOCK_tag::type.

Referenced by CDatagramSocket::Send().

◆ DSOCK_SetBroadcast()

EIO_Status DSOCK_SetBroadcast ( SOCK  sock,
int  broadcast 
)

Set a datagram socket for broadcast.

Parameters
sock[in] SOCK from DSOCK_Create[Ex]()
broadcast[in] set(1)/unset(0) broadcast capability

Definition at line 8361 of file ncbi_socket.c.

References assert, CORE_LOGF_ERRNO_EXX, CORE_LOGF_X, eIO_InvalidArg, eIO_NotSupported, eIO_Success, eIO_Unknown, eLOG_Error, eSOCK_Datagram, MAXIDLEN, s_ID(), SOCK_tag::sock, SOCK_ERRNO, SOCK_INVALID, SOCK_STRERROR, SOCK_tag::type, and UTIL_ReleaseBuffer.

Referenced by CDatagramSocket::SetBroadcast().

◆ DSOCK_WaitMsg()

EIO_Status DSOCK_WaitMsg ( SOCK  sock,
const STimeout timeout 
)

Wait for a datagram in a datagram socket.

Parameters
sock[in] SOCK from DSOCK_Create[Ex]()
timeout[in] time to wait for message

Definition at line 8170 of file ncbi_socket.c.

References assert, CORE_LOGF_X, eIO_Close, eIO_InvalidArg, eIO_Open, eIO_Read, eIO_Success, eIO_Timeout, eIO_Unknown, eLOG_Error, eSOCK_Datagram, eSOCK_ErrIO, SOCK_tag::host, info, MAXIDLEN, poll, SOCK_tag::port, s_ErrHook, s_ErrorCallback(), s_ID(), s_Select(), s_to2tv(), SOCK_tag::sock, SOCK_INVALID, SOCK_ntoa(), and SOCK_tag::type.

Referenced by CDatagramSocket::Wait().

◆ DSOCK_WipeMsg()

EIO_Status DSOCK_WipeMsg ( SOCK  sock,
EIO_Event  direction 
)

Clear message froma datagram socket.

Parameters
sock[in] SOCK from DSOCK_Create[Ex]()
direction[in] either of eIO_Read (incoming), eIO_Write (outgoing)

Definition at line 8315 of file ncbi_socket.c.

References assert, BUF_Erase(), CORE_LOGF_X, eIO_InvalidArg, eIO_Read, eIO_Success, eIO_Write, eLOG_Error, eSOCK_Datagram, MAXIDLEN, SOCK_tag::r_buf, SOCK_tag::r_len, SOCK_tag::r_status, s_ID(), SOCK_tag::sock, SOCK_INVALID, SOCK_tag::type, SOCK_tag::w_buf, and SOCK_tag::w_status.

Referenced by CDatagramSocket::Clear().

◆ GetCount()

TNCBI_BigCount CSocket::GetCount ( EIO_Event  direction) const
inline

◆ gethostbyaddr()

string CSocketAPI::gethostbyaddr ( unsigned int  host,
ESwitch  log = eOff 
)
static

◆ gethostbyname()

unsigned int CSocketAPI::gethostbyname ( const string host,
ESwitch  log = eOff 
)
static

◆ gethostname()

string CSocketAPI::gethostname ( ESwitch  log = eOff)
static

◆ GetLocalHostAddress()

unsigned int CSocketAPI::GetLocalHostAddress ( ESwitch  reget = eDefault)
inlinestatic

Local host address in network byte order (cached for faster retrieval)

Definition at line 1292 of file ncbi_socket.hpp.

References SOCK_GetLocalHostAddress().

Referenced by CDumpSysInfo::DumpSystemInfo(), g_OSG_GetPreferredAddress(), SPSG_DiscoveryImpl::OnTimer(), and CNetScheduleHandler::x_PrintGetJobResponse().

◆ GetLocalPort()

unsigned short CSocket::GetLocalPort ( ENH_ByteOrder  byte_order,
bool  trueport = false 
) const
inline

Get socket local port number.

Parameters
byte_order
See also
SOCK_GetLocalPort

Definition at line 933 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_GetLocalPortEx().

Referenced by SNetScheduleNotificationReceiver::SNetScheduleNotificationReceiver().

◆ GetLoopbackAddress()

unsigned int CSocketAPI::GetLoopbackAddress ( void  )
inlinestatic

Loopback address gets returned in network byte order.

Definition at line 1286 of file ncbi_socket.hpp.

References SOCK_GetLoopbackAddress().

Referenced by CNetScheduleHandler::x_GetPeerAddress(), and CNetStorageHandler::x_GetPeerAddress().

◆ GetLSOCK()

LSOCK CListeningSocket::GetLSOCK ( void  ) const
inline

Access to the underlying "LSOCK".

Definition at line 1176 of file ncbi_socket.hpp.

References CListeningSocket::m_Socket.

Referenced by CSocketAPI::Poll().

◆ GetMessageCount()

TNCBI_BigCount CDatagramSocket::GetMessageCount ( EIO_Event  direction) const
inline

Message count.

Definition at line 1110 of file ncbi_socket.hpp.

References DSOCK_GetMessageCount(), and CSocket::m_Socket.

◆ GetOSHandle() [1/4]

EIO_Status CTrigger::GetOSHandle ( void *  handle_buf,
size_t  handle_size,
EOwnership  ownership = eNoOwnership 
) const
inlinevirtual

Access to the system-specific handle.

Implements CPollable.

Definition at line 865 of file ncbi_socket.hpp.

References eIO_NotSupported, and CTrigger::m_Trigger.

◆ GetOSHandle() [2/4]

EIO_Status CSocket::GetOSHandle ( void *  handle_buf,
size_t  handle_size,
EOwnership  ownership = eNoOwnership 
) const
inlinevirtual

Access to the system-specific socket handle.

Parameters
handle_buf
handle_size
See also
SOCK_GetOSHandleEx, CSocketAPI::OSHandleSize, SOCK_GetOSHandleSize

Implements CPollable.

Definition at line 946 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_GetOSHandleEx().

Referenced by CNetCacheReader::SocketRead(), CNetScheduleHandler::x_SetQuickAcknowledge(), and CNetStorageHandler::x_SetQuickAcknowledge().

◆ GetOSHandle() [3/4]

EIO_Status CListeningSocket::GetOSHandle ( void *  handle_buf,
size_t  handle_size,
EOwnership  ownership = eNoOwnership 
) const
inlinevirtual

Access to the system-specific socket handle.

Parameters
handle_buf
handle_size

Implements CPollable.

Definition at line 1152 of file ncbi_socket.hpp.

References LSOCK_GetOSHandleEx(), and CListeningSocket::m_Socket.

◆ GetOSHandle() [4/4]

virtual EIO_Status CPollable::GetOSHandle ( void *  handle_buf,
size_t  handle_size,
EOwnership  ownership = eNoOwnership 
) const
pure virtual

Implemented in CListeningSocket, CSocket, and CTrigger.

◆ GetPeerAddress() [1/2]

string CSocket::GetPeerAddress ( ESOCK_AddressFormat  format = eSAF_Full) const

Get peer address as a text string.

Returns
Text string representing the (parts of) peer's address
See also
SOCK_GetPeerAddress

Definition at line 403 of file ncbi_socket_cxx.cpp.

References buf, format, CSocket::m_Socket, PATH_MAX, SOCK_GetPeerAddressStringEx(), and string.

◆ GetPeerAddress() [2/2]

void CSocket::GetPeerAddress ( unsigned int host,
unsigned short *  port,
ENH_ByteOrder  byte_order 
) const

◆ GetPOLLABLE() [1/4]

virtual POLLABLE CTrigger::GetPOLLABLE ( void  ) const
inlinevirtual

Implements CPollable.

Definition at line 107 of file ncbi_socket.hpp.

References CTrigger::m_Trigger, and POLLABLE_FromTRIGGER().

◆ GetPOLLABLE() [2/4]

virtual POLLABLE CSocket::GetPOLLABLE ( void  ) const
inlinevirtual

Implements CPollable.

Definition at line 491 of file ncbi_socket.hpp.

References CSocket::m_Socket, and POLLABLE_FromSOCK().

◆ GetPOLLABLE() [3/4]

virtual POLLABLE CListeningSocket::GetPOLLABLE ( void  ) const
inlinevirtual

Implements CPollable.

Definition at line 707 of file ncbi_socket.hpp.

References CListeningSocket::m_Socket, and POLLABLE_FromLSOCK().

◆ GetPOLLABLE() [4/4]

virtual POLLABLE CPollable::GetPOLLABLE ( void  ) const
pure virtual

Implemented in CListeningSocket, CSocket, and CTrigger.

◆ GetPort()

unsigned short CListeningSocket::GetPort ( ENH_ByteOrder  byte_order) const
inline

Return port which the server listens on.

Definition at line 1162 of file ncbi_socket.hpp.

References LSOCK_GetPort(), and CListeningSocket::m_Socket.

◆ GetPosition()

TNCBI_BigCount CSocket::GetPosition ( EIO_Event  direction) const
inline

Positions and stats (direction is either eIO_Read or eIO_Write).

Definition at line 1024 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_GetPosition().

◆ GetRemotePort()

unsigned short CSocket::GetRemotePort ( ENH_ByteOrder  byte_order) const
inline

Get socket remote port number.

Parameters
byte_order
See also
SOCK_GetRemotePort

Definition at line 940 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_GetRemotePort().

◆ GetSOCK()

SOCK CSocket::GetSOCK ( void  ) const
inline

Access to the underlying "SOCK".

Definition at line 1050 of file ncbi_socket.hpp.

References CSocket::m_Socket.

Referenced by CSocketAPI::Poll(), s_GrabSOCK(), and CServer_Monitor::SetSocket().

◆ GetStatus() [1/3]

EIO_Status CSocket::GetStatus ( EIO_Event  direction) const
inline

Return status of *last* I/O operation without making any actual I/O.

Parameters
directionis one of
  • eIO_Open - return eIO_Success if CSocket has been opened, eIO_Timeout if CSocket is still pending connect, eIO_Closed if closed by Close() or not yet open;
  • eIO_Read - status of last read operation;
  • eIO_Write - status of last write operation. Directions eIO_Close and eIO_ReadWrite generate eIO_InvalidArg error.
See also
SOCK_Status

Definition at line 890 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_Status().

Referenced by CNetCacheWriter::AbortConnection(), SNetServerConnectionImpl::DeleteThis(), CServer_Monitor::IsMonitorActive(), CNetStorageHandler::OnRead(), CSocketAPI::Poll(), and SGridWorkerNodeImpl::x_AreMastersBusy().

◆ GetStatus() [2/3]

EIO_Status CTrigger::GetStatus ( void  ) const
inline

Definition at line 841 of file ncbi_socket.hpp.

References eIO_Success, and CTrigger::m_Trigger.

◆ GetStatus() [3/3]

EIO_Status CListeningSocket::GetStatus ( void  ) const
inline

Return eIO_Closed if not yet bound or Close()'d.

Definition at line 1146 of file ncbi_socket.hpp.

References eIO_Success, and CListeningSocket::m_Socket.

Referenced by CServer_Listener::Activate().

◆ GetTimeout()

const STimeout * CSocket::GetTimeout ( EIO_Event  event) const

◆ GetTotalCount()

TNCBI_BigCount CSocket::GetTotalCount ( EIO_Event  direction) const
inline

Definition at line 1036 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_GetTotalCount().

◆ GetTRIGGER()

TRIGGER CTrigger::GetTRIGGER ( void  ) const
inline

Access to the underlying "TRIGGER".

Definition at line 871 of file ncbi_socket.hpp.

References CTrigger::m_Trigger.

Referenced by CSocketAPI::Poll().

◆ HostPortToString()

string CSocketAPI::HostPortToString ( unsigned int  host,
unsigned short  port 
)
static

◆ HostToNetLong()

unsigned int CSocketAPI::HostToNetLong ( unsigned int  value)
inlinestatic

Definition at line 1262 of file ncbi_socket.hpp.

References SOCK_HostToNetLong(), and rapidjson::value.

◆ HostToNetShort()

unsigned short CSocketAPI::HostToNetShort ( unsigned short  value)
inlinestatic

◆ Initialize()

EIO_Status CSocketAPI::Initialize ( void  )
inlinestatic

Generic.

CSocketAPI::

Definition at line 1187 of file ncbi_socket.hpp.

References SOCK_InitializeAPI().

◆ IsClientSide()

bool CSocket::IsClientSide ( void  ) const
inline

Definition at line 1000 of file ncbi_socket.hpp.

References CSocket::m_Socket, SOCK_IsClientSide(), and true.

◆ IsDatagram()

bool CSocket::IsDatagram ( void  ) const
inline

Definition at line 994 of file ncbi_socket.hpp.

References CSocket::m_Socket, SOCK_IsDatagram(), and true.

◆ IsEmpty() [1/2]

bool CSocket::IsEmpty ( void  ) const
inline

Definition at line 488 of file ncbi_socket.hpp.

References CSocket::m_Socket.

◆ IsEmpty() [2/2]

bool CListeningSocket::IsEmpty ( void  ) const
inline

Definition at line 704 of file ncbi_socket.hpp.

References CListeningSocket::m_Socket.

◆ isip()

bool CSocketAPI::isip ( const string host,
bool  fullquad = false 
)
inlinestatic

◆ IsSecure()

bool CSocket::IsSecure ( void  ) const
inline

Definition at line 1018 of file ncbi_socket.hpp.

References CSocket::m_Socket, SOCK_IsSecure(), and true.

◆ IsServerSide()

bool CSocket::IsServerSide ( void  ) const
inline

Definition at line 1006 of file ncbi_socket.hpp.

References CSocket::m_Socket, SOCK_IsServerSide(), and true.

◆ IsSet()

EIO_Status CTrigger::IsSet ( void  )
inline

Definition at line 853 of file ncbi_socket.hpp.

References eIO_Unknown, CTrigger::m_Trigger, and TRIGGER_IsSet().

◆ IsUNIX()

bool CSocket::IsUNIX ( void  ) const
inline

Definition at line 1012 of file ncbi_socket.hpp.

References CSocket::m_Socket, SOCK_IsUNIX(), and true.

◆ Listen() [1/2]

EIO_Status CUNIXListeningSocket::Listen ( const string filename,
unsigned short  backlog = 64,
TSOCK_Flags  flags = fSOCK_LogDefault 
)
inline

◆ Listen() [2/2]

EIO_Status CListeningSocket::Listen ( unsigned short  port,
unsigned short  backlog = 64,
TSOCK_Flags  flags = fSOCK_LogDefault 
)
inline
Note
"port" ought to be in host byte order
Parameters
port
backlog
flags

Definition at line 1137 of file ncbi_socket.hpp.

References eIO_Unknown, flags, LSOCK_CreateEx(), and CListeningSocket::m_Socket.

Referenced by CServer_Listener::Activate().

◆ LSOCK_Accept()

EIO_Status LSOCK_Accept ( LSOCK  lsock,
const STimeout timeout,
SOCK sock 
)

[SERVER-side] Accept connection from a client.

Same as LSOCK_AcceptEx(.,.,.,fSOCK_LogDefault)

See also
LSOCK_AcceptEx

Definition at line 6538 of file ncbi_socket.c.

References fSOCK_LogDefault, and s_Accept().

◆ LSOCK_AcceptEx()

EIO_Status LSOCK_AcceptEx ( LSOCK  lsock,
const STimeout timeout,
SOCK sock,
TSOCK_Flags  flags 
)

[SERVER-side] Accept connection from a client.

Parameters
lsock[in] handle of a listening socket
timeout[in] timeout (infinite if NULL)
sock[out] handle of the accepted socket
flags[in] properties for the accepted socket to have
Note
The provided "timeout" is for this Accept() only. To set I/O timeout on the resulted socket use SOCK_SetTimeout(); all I/O timeouts are infinite by default.
See also
SOCK_Create, SOCK_Close, TSOCK_Flags

Definition at line 6546 of file ncbi_socket.c.

References flags, and s_Accept().

Referenced by CListeningSocket::Accept(), and x_FTPXfer().

◆ LSOCK_Close()

EIO_Status LSOCK_Close ( LSOCK  lsock)

[SERVER-side] Close the listening socket, destroy relevant internal data.

Parameters
lsock[in] listening socket handle to close The call invalidates the handle, so its further is not allowed.
See also
LSOCK_Create

Definition at line 6555 of file ncbi_socket.c.

References eIO_InvalidArg, free(), s_CloseListening(), LSOCK_tag::sock, and SOCK_INVALID.

Referenced by CListeningSocket::Close(), x_FTPOpenData(), and x_FTPXfer().

◆ LSOCK_Create()

EIO_Status LSOCK_Create ( unsigned short  port,
unsigned short  backlog,
LSOCK lsock 
)

[SERVER-side] Create and initialize the server-side(listening) socket Same as LSOCK_CreateEx() called with the last argument provided as fSOCK_LogDefault.

Parameters
port[in] the port to listen at
backlog[in] maximal # of pending connections
Note
On some systems, "backlog" can be silently limited down to 128 (or even 5), or completely ignored whatsoever.
Parameters
lsock[out] handle of the created listening socket
See also
LSOCK_CreateEx, LSOCK_Close

Definition at line 6507 of file ncbi_socket.c.

References fSOCK_LogDefault, and s_CreateListening().

◆ LSOCK_CreateEx()

EIO_Status LSOCK_CreateEx ( unsigned short  port,
unsigned short  backlog,
LSOCK lsock,
TSOCK_Flags  flags 
)

[SERVER-side] Create and initialize the server-side(listening) socket (socket() + bind() + listen())

Parameters
port[in] the port to listen at (0 to choose first available)
backlog[in] maximal # of pending connections
Note
On some systems, "backlog" may be silently limited down to 128 (or even 5), or completely ignored whatsoever.
Parameters
lsock[out] handle of the created listening socket
flags[in] special modifiers
See also
LSOCK_Create, LSOCK_Close, LSOCK_GetPort

Definition at line 6516 of file ncbi_socket.c.

References flags, and s_CreateListening().

Referenced by CListeningSocket::CListeningSocket(), CListeningSocket::Listen(), and x_FTPActive().

◆ LSOCK_CreateUNIX()

EIO_Status LSOCK_CreateUNIX ( const char *  path,
unsigned short  backlog,
LSOCK lsock,
TSOCK_Flags  flags 
)

◆ LSOCK_GetOSHandle()

EIO_Status LSOCK_GetOSHandle ( LSOCK  lsock,
void *  handle_buf,
size_t  handle_size 
)

Same as LSOCK_GetOSHandleEx(lsock, handle_buf, handle_size, eNoOwnership).

See also
LSOCK_GetOSHandleEx

Definition at line 6608 of file ncbi_socket.c.

References eNoOwnership, and LSOCK_GetOSHandleEx().

◆ LSOCK_GetOSHandleEx()

EIO_Status LSOCK_GetOSHandleEx ( LSOCK  lsock,
void *  handle_buf,
size_t  handle_size,
EOwnership  owndership 
)

Get an OS-dependent native socket handle to use by platform-specific API.

FYI: on MS-Windows it will be "SOCKET", on other platforms – "int".

Parameters
lsock[in] socket handle
handle_buf[in] pointer to a memory location to store the OS-dependent handle at
handle_sizeThe exact(!) size of the expected OS handle
ownershipeTakeOwnership removes the handle from LSOCK; eNoOwnership retains it
Note
If handle ownership is taken, all operations with this LSOCK (except for LSOCK_Close()) will fail.
See also
SOCK_OSHandleSize, SOCK_GetOSHandle, SOCK_CloseOSHandle, LSOCK_GetOSHandle, LSOCK_Close

Definition at line 6570 of file ncbi_socket.c.

References assert, CORE_LOGF_X, eIO_InvalidArg, eIO_Success, eLOG_Error, eTakeOwnership, LSOCK_tag::id, LSOCK_tag::keep, s_CloseListening(), s_Initialized, LSOCK_tag::sock, and SOCK_INVALID.

Referenced by CListeningSocket::GetOSHandle(), and LSOCK_GetOSHandle().

◆ LSOCK_GetPort()

unsigned short LSOCK_GetPort ( LSOCK  lsock,
ENH_ByteOrder  byte_order 
)

Get socket port number, which it listens on.

The returned port is either one specified when the socket was created, or an automatically assigned number if LSOCK_Create() provided the port as 0.

Parameters
lsock[in] socket handle
byte_order[in] byte order for port on return
Returns
Listening port number in requested byte order, or 0 in case of an error.
See also
LSOCK_Create

Definition at line 6616 of file ncbi_socket.c.

References eNH_HostByteOrder, LSOCK_tag::port, LSOCK_tag::sock, and SOCK_INVALID.

Referenced by CListeningSocket::GetPort(), x_FTPActive(), and x_FTPXfer().

◆ NcbiCreateTlsCertCredentials()

NCBI_CRED NcbiCreateTlsCertCredentials ( const void *  cert,
size_t  certsz,
const void *  pkey,
size_t  pkeysz 
)

Build NCBI_CRED from memory buffers containing X.509 certificate and private key, respectively, in either PEM or DER format (independently of each other).

The returned credentials handle must not be deleted while it's in use.

If a size is passed as 0, the corresponding pointer argument is assumed to be a '\0'-terminated string, and the size gets computed internally as strlen(ptr) + 1, to cover the trailing '\0' byte, see below.

To figure out the format of cert / key, the passed buffer gets analyzed to see whether the last byte is '\0' and whether the therefore properly terminated C-string happens to contain a "-----BEGIN " substring: if both conditions are true, then the buffer is considered in PEM format; or DER, otherwise.

Note
that the size value ("certsz" / "pkeysz"), when expliciltly specified, MUST account for the terminating '\0' byte for PEM formatted buffers. It MUST always be specified exact for DER formatted buffers.
Warning
Calling free() on the returned handle will cause memory leaks; so always use NcbiDeleteTlsCertCredentials() when the handle is no longer needed.
See also
NcbiDeleteTlsCertCredentials

Definition at line 120 of file ncbi_tls.c.

References CORE_LOG_X, CORE_LOGF_X, eLOG_Critical, eLOG_Error, eLOG_Warning, eNcbiCred_GnuTls, eNcbiCred_MbedTls, NcbiCreateMbedTlsCertCredentials(), NcbiSetupGnuTls(), NcbiSetupMbedTls(), setup(), SOCK_SSLName(), util::strcmp(), and x_NcbiSetupTls().

Referenced by CTlsCertCredentials::GetNcbiCred().

◆ NcbiCredGnuTls()

NCBI_CRED NcbiCredGnuTls ( void *  xcred)

Convert a native GNUTLS certificate credentials' handle into an abstract toolkit handle.

Note
The returned handle should be free()'d when no longer needed (that is, when it no longer can be accessed and used by any CONNECT API). The underlying GNUTLS certificate (xcred) must be released using the native API.
Warning
The call does not create a copy of xcred, so xcred must remain valid for the entire duration of a session (or sessions) that it is being used with.
See also
NcbiDeleteTlsCertCredentials

Definition at line 911 of file ncbi_gnutls.c.

References calloc(), SNcbiCred::data, eNcbiCred_GnuTls, and SNcbiCred::type.

◆ NcbiCredMbedTls()

NCBI_CRED NcbiCredMbedTls ( void *  xcert,
void *  xpkey 
)

Convert native mbedTLS certificate credentials' handles into an abstract toolkit handle.

Two arguments are _required_: a pointer to a parsed certificate (xcert), and a pointer to a parsed private key (xpkey).

Note
The returned handle should be free()'d when no longer needed (that is, when it no longer can be accessed and used by any CONNECT API). The underlying mbedTLS certificate and private key must be released using an appropriate native API.
Warning
The call does not create a copy of either xcert or xpkey, so they must remain valid for the entire duration of a session (or sessions) that they are being used with.
See also
NcbiDeleteTlsCertCredentials

Definition at line 860 of file ncbi_mbedtls.c.

References ALIGN, calloc(), SNcbiMbedTlsCred::cert, SNcbiCred::data, eNcbiCred_MbedTls, SNcbiMbedTlsCred::pkey, ncbi::grid::netcache::search::fields::size, and SNcbiCred::type.

◆ NcbiDeleteTlsCertCredentials()

void NcbiDeleteTlsCertCredentials ( NCBI_CRED  cred)

Delete a NCBI_CRED handle created by NcbiCreateTlsCertCredentials().

Warning
Do not call this routine while the handle can be potentially in use.
Note
This routine can be safely used for handles returned by NcbiCredMbedTls() and NcbiCredGnuTls(), to avoid having to delete the underlying TLS-provider-specific handles passed to either call, explicitly.
See also
NcbiCreateTlsCertCredentials, NcbiCredMbedTls, NcbiCredGnuTls

Definition at line 180 of file ncbi_tls.c.

References CORE_LOGF_X, SNcbiCred::data, eLOG_Error, eNcbiCred_GnuTls, eNcbiCred_MbedTls, free(), NcbiDeleteMbedTlsCertCredentials(), and SNcbiCred::type.

Referenced by CTlsCertCredentials::~CTlsCertCredentials().

◆ NcbiSetupGnuTls()

SOCKSSL NcbiSetupGnuTls ( void  )

Explicitly setup GNUTLS library to support SSL in ncbi_socket.h[pp].

Note
Do not use this call! Instead, use NcbiSetupTls declared in <connect/ncbi_tls.h>.
See also
NcbiSetupTls

Definition at line 888 of file ncbi_gnutls.c.

References CORE_LOG_X, eLOG_Warning, and s_GnuTlsInit().

Referenced by NcbiCreateTlsCertCredentials(), and x_NcbiSetupTls().

◆ NcbiSetupMbedTls()

SOCKSSL NcbiSetupMbedTls ( void  )

Explicitly setup mbedTLS library to support SSL in ncbi_socket.h[pp].

Note
Do not use this call! Instead use NcbiSetupTls declared in <connect/ncbi_tls.h>.
See also
NcbiSetupTls

Definition at line 833 of file ncbi_mbedtls.c.

References CORE_LOG_X, eLOG_Warning, s_MbedTlsClose(), s_MbedTlsCreate(), s_MbedTlsDelete(), s_MbedTlsError(), s_MbedTlsExit(), s_MbedTlsInit(), s_MbedTlsOpen(), s_MbedTlsRead(), and s_MbedTlsWrite().

Referenced by NcbiCreateTlsCertCredentials(), and x_NcbiSetupTls().

◆ NcbiSetupTls()

SOCKSSL NcbiSetupTls ( void  )

Setup a TLS (Transport Layer Security) provider library to support SSL in ncbi_socket.h[pp].

Currently we support mbedTLS and GNUTLS as the providers. This call selects a library, which is either the default or requested via the registry (aka .ini file), or through the process environment (takes precedence over the registry):

[CONN] USESSL={1,0,MBEDTLS,GNUTLS}

CONN_USESSL={1,0,MBEDTLS,GNUTLS}

"Off", "No", "False", case-insensitively, are also accepted for "0"; and "On", "Yes", "True" – for "1".

If no provider is present in the build, "0" is assumed. "1" selects the default provider as currently configured within the toolkit. With "0", SSL will not be availbale for sockets, and any secure session will fail.

Note
GNUTLS is only available as an external 3-rd party library, and must be so configured –with-gnutls at the configuration stage of the build. mbedTLS can also be used as an external installation, but the toolkit has an embedded private copy of the library, which can be used transparently without any additional dependencies. That embedded copy will be used by default, if no other provider is explicitly pre-set, selected, or disabled.

Definition at line 113 of file ncbi_tls.c.

References setup(), and x_NcbiSetupTls().

Referenced by CConnIniter::CConnIniter(), and CONNECT_Init().

◆ NetToHostLong()

unsigned int CSocketAPI::NetToHostLong ( unsigned int  value)
inlinestatic

Definition at line 1268 of file ncbi_socket.hpp.

References SOCK_NetToHostLong, and rapidjson::value.

Referenced by SNetServerInPool::SNetServerInPool().

◆ NetToHostShort()

unsigned short CSocketAPI::NetToHostShort ( unsigned short  value)
inlinestatic

Definition at line 1280 of file ncbi_socket.hpp.

References SOCK_NetToHostShort, and rapidjson::value.

Referenced by SUv_Tcp::OnConnect().

◆ ntoa()

string CSocketAPI::ntoa ( unsigned int  host)
static

◆ operator=()

CPollable& CPollable::operator= ( const CPollable )
private

◆ OSHandleSize()

size_t CSocketAPI::OSHandleSize ( void  )
inlinestatic

Definition at line 1205 of file ncbi_socket.hpp.

References SOCK_OSHandleSize().

◆ Poll()

EIO_Status CSocketAPI::Poll ( vector< SPoll > &  polls,
const STimeout timeout,
size_t *  n_ready = 0 
)
static

Poll a vector of CPollable objects for I/O readiness.

Note
If possible, please consider using lower-level SOCK_Poll() for performance reasons (the code may still use a vector to prepare the array of elements, then pass vector::data() and vector::size() when making the SOCK_Poll() call).
Use CSocket::Wait() to wait for I/O event(s) in a single socket.

Definition at line 590 of file ncbi_socket_cxx.cpp.

References eIO_Close, eIO_Open, eIO_Unknown, SPOLLABLE_Poll::event, CListeningSocket::GetLSOCK(), CSocket::GetSOCK(), CSocket::GetStatus(), CTrigger::GetTRIGGER(), i, SPOLLABLE_Poll::poll, POLLABLE_FromLSOCK(), POLLABLE_FromSOCK(), POLLABLE_FromTRIGGER(), POLLABLE_Poll(), and SPOLLABLE_Poll::revent.

Referenced by CConnTest::CheckFWConnections(), CNetCacheWriter::TransmitImpl(), and CServer::x_DoRun().

◆ POLLABLE_FromLSOCK()

POLLABLE POLLABLE_FromLSOCK ( LSOCK  lsock)

Definition at line 8620 of file ncbi_socket.c.

References assert, eSOCK_Listening, and LSOCK_tag::type.

Referenced by CListeningSocket::GetPOLLABLE(), and CSocketAPI::Poll().

◆ POLLABLE_FromSOCK()

POLLABLE POLLABLE_FromSOCK ( SOCK  sock)

Conversion utilities from handles to POLLABLEs, and back.

Returns
Return 0 if conversion cannot be made; otherwise the converted handle.

Definition at line 8627 of file ncbi_socket.c.

References assert, eSOCK_Socket, and SOCK_tag::type.

Referenced by CSocket::GetPOLLABLE(), and CSocketAPI::Poll().

◆ POLLABLE_FromTRIGGER()

POLLABLE POLLABLE_FromTRIGGER ( TRIGGER  trigger)

Definition at line 8613 of file ncbi_socket.c.

References assert, eSOCK_Trigger, and TRIGGER_tag::type.

Referenced by CTrigger::GetPOLLABLE(), and CSocketAPI::Poll().

◆ POLLABLE_Poll()

EIO_Status POLLABLE_Poll ( size_t  n,
SPOLLABLE_Poll  polls[],
const STimeout timeout,
size_t *  n_ready 
)

Poll for I/O readiness.

Parameters
n[in] how many elements to scan in the "polls" array parameter
polls[][in/out] array of handles and event masks to check for I/O, and return
timeout[in] how long to wait for at least one handle to get ready.
n_ready[out] how many elements of the "polls" array returned with their I/O marked ready
Returns
eIO_Success if at least one element was found ready, eIO_Timeout if none and the specified time interval had elapsed, other error code for some other error condition (in which case the "revent" fields in the array may not have been updated with valid values).
See also
SOCK_Wait, SOCK_Poll

Definition at line 8597 of file ncbi_socket.c.

References n, and SOCK_Poll().

Referenced by CSocketAPI::Poll().

◆ POLLABLE_ToLSOCK()

LSOCK POLLABLE_ToLSOCK ( POLLABLE  poll)

Definition at line 8641 of file ncbi_socket.c.

References eSOCK_Listening, poll, and LSOCK_tag::type.

◆ POLLABLE_ToSOCK()

SOCK POLLABLE_ToSOCK ( POLLABLE  poll)

Definition at line 8648 of file ncbi_socket.c.

References eSOCK_Socket, poll, and SOCK_tag::type.

◆ POLLABLE_ToTRIGGER()

TRIGGER POLLABLE_ToTRIGGER ( POLLABLE  poll)

Definition at line 8634 of file ncbi_socket.c.

References eSOCK_Trigger, poll, and TRIGGER_tag::type.

◆ POLLABLE_What()

ESOCK_Type POLLABLE_What ( POLLABLE  poll)

Identifies a non-NULL POLLABLE.

Definition at line 8606 of file ncbi_socket.c.

References assert, and poll.

◆ Pushback()

EIO_Status CSocket::Pushback ( const void *  buf,
size_t  size 
)
inline

Push back data to socket (to be read out first).

Parameters
buf
size
See also
SOCK_Pushback

Definition at line 914 of file ncbi_socket.hpp.

References buf, CSocket::m_Socket, ncbi::grid::netcache::search::fields::size, and SOCK_Pushback().

Referenced by CSocketReaderWriter::Pushback().

◆ Read()

EIO_Status CSocket::Read ( void *  buf,
size_t  size,
size_t *  n_read = 0,
EIO_ReadMethod  how = eIO_ReadPlain 
)

◆ ReadLine() [1/2]

EIO_Status CSocket::ReadLine ( char *  buf,
size_t  size,
size_t *  n_read = 0 
)
inline

Read a line from socket (up to CR-LF, LF, or null character, discarding any of the EOLs).

Parameters
buf
size
n_read
See also
SOCK_ReadLine

Definition at line 908 of file ncbi_socket.hpp.

References buf, CSocket::m_Socket, ncbi::grid::netcache::search::fields::size, and SOCK_ReadLine().

◆ ReadLine() [2/2]

EIO_Status CSocket::ReadLine ( string str)

Read a line from socket (up to CR-LF, LF, or null character, discarding any of the EOLs).

Parameters
str
See also
SOCK_ReadLine

Definition at line 358 of file ncbi_socket_cxx.cpp.

References buf, eIO_Success, CSocket::m_Socket, ncbi::grid::netcache::search::fields::size, SOCK_ReadLine(), and str().

Referenced by SNetServerConnectionImpl::ReadCmdOutputLine(), CNetCacheWriter::TransmitImpl(), and SGridWorkerNodeImpl::x_AreMastersBusy().

◆ Reconnect() [1/2]

EIO_Status CDatagramSocket::Reconnect ( const STimeout timeout)
protected
Note
The call is not valid with datagram sockets.

◆ Reconnect() [2/2]

EIO_Status CSocket::Reconnect ( const STimeout timeout = kDefaultTimeout)

Reconnect to the same address.

Note
The socket must not be closed by the time this call is made;
Not for the sockets created by CListeningSocket::Accept();
Timeout from the argument becomes new eIO_Open timeout.
Parameters
timeoutmaximal time to reconnect
See also
SOCK_Reconnect

Definition at line 247 of file ncbi_socket_cxx.cpp.

References kDefaultTimeout, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, and SOCK_Reconnect().

◆ Recv()

EIO_Status CDatagramSocket::Recv ( void *  buf,
size_t  buflen,
size_t *  msglen = 0,
string sender_host = 0,
unsigned short *  sender_port = 0,
size_t  maxmsglen = 0 
)
Parameters
buf
buflen
msglen
sender_host
sender_port
maxmsglen

Definition at line 487 of file ncbi_socket_cxx.cpp.

References buf, DSOCK_RecvMsg(), CSocket::m_Socket, and CSocketAPI::ntoa().

Referenced by SNetScheduleNotificationReceiver::operator()().

◆ Reset() [1/2]

void CSocket::Reset ( SOCK  sock,
EOwnership  if_to_own,
ECopyTimeout  whence 
)

Close the current underlying "SOCK" (if any, and if owned), and from now on use "sock" as the underlying "SOCK" instead.

Note
"if_to_own" applies to the (new) "sock"
Parameters
sock
if_to_own
whence

Definition at line 414 of file ncbi_socket_cxx.cpp.

References CSocket::c_timeout, CSocket::cc_timeout, eCopyTimeoutsFromSOCK, eIO_Close, eIO_Read, eIO_Write, eNoOwnership, CSocket::m_IsOwned, CSocket::m_Socket, CSocket::r_timeout, CSocket::rr_timeout, SOCK_Close(), SOCK_GetTimeout(), SOCK_SetTimeout(), CSocket::w_timeout, and CSocket::ww_timeout.

Referenced by CListeningSocket::Accept(), CConn_IOStream::Close(), CConn_IOStream::GetSocket(), s_GrabSOCK(), and CServer_Monitor::SetSocket().

◆ Reset() [2/2]

EIO_Status CTrigger::Reset ( void  )
inline

Definition at line 859 of file ncbi_socket.hpp.

References eIO_Unknown, CTrigger::m_Trigger, and TRIGGER_Reset().

Referenced by CServer::x_DoRun().

◆ Send()

EIO_Status CDatagramSocket::Send ( const void *  data,
size_t  datalen,
const string host = string(),
unsigned short  port = 0 
)
inline

◆ Set()

EIO_Status CTrigger::Set ( void  )
inline

◆ SetBroadcast()

EIO_Status CDatagramSocket::SetBroadcast ( bool  do_broadcast = true)
inline
Parameters
do_broadcast

Definition at line 1104 of file ncbi_socket.hpp.

References DSOCK_SetBroadcast(), and CSocket::m_Socket.

◆ SetCork()

void CSocket::SetCork ( bool  on_off = true)
inline
Note
See comments for SOCK_SetCork() in "ncbi_socket.h".
Parameters
on_off
See also
SOCK_SetCork

Definition at line 974 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_SetCork().

Referenced by CNetCacheWriter::Close(), and CNetCacheWriter::EstablishConnection().

◆ SetDataLogging() [1/2]

ESwitch CSocketAPI::SetDataLogging ( ESwitch  log)
inlinestatic
Parameters
log

Definition at line 1250 of file ncbi_socket.hpp.

References log, and SOCK_SetDataLoggingAPI().

◆ SetDataLogging() [2/2]

ESwitch CSocket::SetDataLogging ( ESwitch  log = eOn)
inline
Note
Use CSocketAPI::SetDataLogging() to set the default value.
Parameters
log
See also
SOCK_SetDataLogging

Definition at line 988 of file ncbi_socket.hpp.

References eDefault, log, CSocket::m_Socket, and SOCK_SetDataLogging().

Referenced by SNetScheduleNotificationReceiver::SNetScheduleNotificationReceiver().

◆ SetInterruptOnSignal() [1/2]

ESwitch CSocketAPI::SetInterruptOnSignal ( ESwitch  interrupt)
inlinestatic
Parameters
interrupt

Definition at line 1238 of file ncbi_socket.hpp.

References SOCK_SetInterruptOnSignalAPI().

◆ SetInterruptOnSignal() [2/2]

ESwitch CSocket::SetInterruptOnSignal ( ESwitch  interrupt = eOn)
inline
Note
Use CSocketAPI::SetInterruptOnSignal() to set the default value.
Parameters
interrupt
See also
SOCK_SetInterruptOnSignal

Definition at line 961 of file ncbi_socket.hpp.

References eDefault, CSocket::m_Socket, and SOCK_SetInterruptOnSignal().

◆ SetIOWaitSysAPI()

ESOCK_IOWaitSysAPI CSocketAPI::SetIOWaitSysAPI ( ESOCK_IOWaitSysAPI  api)
inlinestatic

Definition at line 1225 of file ncbi_socket.hpp.

References SOCK_SetIOWaitSysAPI().

◆ SetOwnership() [1/2]

EOwnership CSocket::SetOwnership ( EOwnership  if_to_own)
inline

Specify if this "CSocket" is to own the underlying "SOCK".

Returns
Previous ownership mode.
Parameters
if_to_own

Definition at line 1042 of file ncbi_socket.hpp.

References CSocket::m_IsOwned.

Referenced by s_GrabSOCK(), and CServer_Monitor::SetSocket().

◆ SetOwnership() [2/2]

EOwnership CListeningSocket::SetOwnership ( EOwnership  if_to_own)
inline

Specify if this "CListeningSocket" is to own the underlying "LSOCK".

Parameters
if_to_own
Returns
Previous ownership mode.

Definition at line 1168 of file ncbi_socket.hpp.

References CListeningSocket::m_IsOwned.

◆ SetReadOnWrite() [1/2]

ESwitch CSocketAPI::SetReadOnWrite ( ESwitch  read_on_write)
inlinestatic

Defaults (see also per-socket CSocket::SetReadOnWrite, etc.)

Parameters
read_on_write

Definition at line 1232 of file ncbi_socket.hpp.

References SOCK_SetReadOnWriteAPI().

◆ SetReadOnWrite() [2/2]

ESwitch CSocket::SetReadOnWrite ( ESwitch  read_on_write = eOn)
inline
Note
Use CSocketAPI::SetReadOnWrite() to set the default value.
Parameters
read_on_write
See also
SOCK_SetReadOnWrite

Definition at line 955 of file ncbi_socket.hpp.

References eDefault, CSocket::m_Socket, and SOCK_SetReadOnWrite().

◆ SetReuseAddress() [1/2]

ESwitch CSocketAPI::SetReuseAddress ( ESwitch  reuse)
inlinestatic
Parameters
reuse

Definition at line 1244 of file ncbi_socket.hpp.

References SOCK_SetReuseAddressAPI().

◆ SetReuseAddress() [2/2]

void CSocket::SetReuseAddress ( ESwitch  reuse = eOff)
inline
Note
See comments for SOCK_SetReuseAddress() in "ncbi_socket.h".
Parameters
reuse
See also
SOCK_SetReuseAddress

Definition at line 967 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_SetReuseAddress().

◆ SetSelectInternalRestartTimeout()

const STimeout * CSocketAPI::SetSelectInternalRestartTimeout ( const STimeout timeout)
inlinestatic

Utility.

Definition at line 1218 of file ncbi_socket.hpp.

References SOCK_SetSelectInternalRestartTimeout().

◆ SetTimeout()

EIO_Status CSocket::SetTimeout ( EIO_Event  event,
const STimeout timeout 
)

Set timeout for I/O in the specified direction.

Note
Initially all timeouts are infinite by default;
SetTimeout(..., kDefaultTimeout) has no effect;
GetTimeout(eIO_ReadWrite) returns the least of eIO_Read and eIO_Write ones.
Parameters
eventeither of eIO_Open, eIO_Read, eUI_Write, eIO_ReadWrite, or eIO_Close
timeoutnew value to set (including special kInfiniteTimeout)
See also
CSocket::GetTimeout, SOCK_SetTimeout, SOCK_GetTimeout

Definition at line 261 of file ncbi_socket_cxx.cpp.

References CSocket::c_timeout, CSocket::cc_timeout, eIO_Close, eIO_InvalidArg, eIO_Open, eIO_Read, eIO_ReadWrite, eIO_Success, eIO_Write, kDefaultTimeout, CSocket::m_Socket, CSocket::o_timeout, CSocket::oo_timeout, CSocket::r_timeout, CSocket::rr_timeout, SOCK_SetTimeout(), CSocket::w_timeout, and CSocket::ww_timeout.

Referenced by CTimeoutKeeper::CTimeoutKeeper(), CNetScheduleHandler::OnOpen(), CNetStorageHandler::OnOpen(), CSocketReaderWriter::PendingCount(), CSocketReaderWriter::SetTimeout(), SNetScheduleNotificationReceiver::SNetScheduleNotificationReceiver(), SNetServerConnectionImpl::SNetServerConnectionImpl(), CServer_Connection::~CServer_Connection(), and CTimeoutKeeper::~CTimeoutKeeper().

◆ Shutdown() [1/3]

EIO_Status CSocket::Shutdown ( EIO_Event  how)
inline

Shutdown socket I/O in the specified direction.

Parameters
howeither of eIO_Read, eIO_Write, or eIO_ReadWrite
See also
SOCK_Shutdown

Definition at line 896 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_Shutdown().

Referenced by CNetScheduleHandler::OnClose(), and CNetStorageHandler::OnClose().

◆ Shutdown() [2/3]

EIO_Status CDatagramSocket::Shutdown ( EIO_Event  how)
protected
Note
The call is not valid with datagram sockets.

◆ Shutdown() [3/3]

EIO_Status CSocketAPI::Shutdown ( void  )
inlinestatic

Definition at line 1193 of file ncbi_socket.hpp.

References SOCK_ShutdownAPI().

◆ SOCK_Abort()

EIO_Status SOCK_Abort ( SOCK  sock)

If there is outstanding connection or output data pending, cancel it.

Mark the socket as if it has been shut down for both reading and writing. Break actual connection if any was established. Do not attempt to send anything upon SOCK_Close(). This call is available for stream sockets only.

Note
Even though the underlying OS socket handle may have been marked for preservation via fSOCK_KeepOnClose, this call always and unconditionally closes and destroys the actual OS handle.
Parameters
sock[in] socket handle

Definition at line 7557 of file ncbi_socket.c.

References assert, CORE_LOGF_X, eIO_InvalidArg, eLOG_Error, eLOG_Warning, eSOCK_Datagram, fSOCK_KeepNone, MAXIDLEN, s_Close_(), s_ID(), SOCK_tag::sock, SOCK_INVALID, and SOCK_tag::type.

Referenced by CSocket::Abort(), CListeningSocket::Accept(), s_Connect(), s_DropConnection(), s_SocketConnectorBuilder(), s_VT_Close(), s_VT_Open(), x_FTPCloseCntl(), x_FTPCloseData(), and x_URLConnectErrorReturn().

◆ SOCK_AllowSigPipeAPI()

void SOCK_AllowSigPipeAPI ( void  )

By default (on UNIX platforms) the SOCK API functions automagically call "signal(SIGPIPE, SIG_IGN)" on initialization.

To prohibit this feature you must call SOCK_AllowSigPipeAPI() before you call any other function from the SOCK API.

Definition at line 1060 of file ncbi_socket.c.

References s_AllowSigPipe.

Referenced by CSocketAPI::AllowSigPipe().

◆ SOCK_Close()

EIO_Status SOCK_Close ( SOCK  sock)

Close the SOCK handle, and destroy all relevant internal data.

The "sock" handle goes invalid after this function call, regardless of whether the call was successful or not. If eIO_Close timeout was specified (or NULL) then it blocks until either all unsent data are sent, an error flagged, or the timeout expires; if there was any output pending, that output will be flushed. Connection may remain in the system if SOCK was created with the fSOCK_KeepOnClose flag set; otherwise, it gets closed as well.

Warning
On MS-Windows closing a SOCK whose OS handle has been used elsewhere (e.g. in SOCK_CreateOnTop()) may render the OS handle unresponsive, so always make sure to close the current SOCK first (assuming fSOCK_KeepOnClose), and only then use the extracted handle to build another socket.
Parameters
sock[in] socket handle to close(if not yet closed) and destroy(always)
See also
SOCK_Create, SOCK_CreateOnTop, DSOCK_Create, SOCK_SetTimeout, SOCK_CloseEx

Definition at line 6851 of file ncbi_socket.c.

References SOCK_CloseEx().

Referenced by CListeningSocket::Accept(), CUNIXSocket::Connect(), CSocket::Connect(), CORE_SendMailEx(), LBSM_SubmitPenaltyOrRerate(), ProcessOverflow(), CDBLB_ServiceMapper::RecordServer(), CSocket::Reset(), s_DropConnection(), s_SocketConnectorBuilder(), s_VT_Close(), s_VT_Open(), x_FTPCloseCntl(), x_FTPCloseData(), x_URLConnectErrorReturn(), and CSocket::~CSocket().

◆ SOCK_CloseEx()

EIO_Status SOCK_CloseEx ( SOCK  sock,
int  destroy 
)

Close the SOCK handle, and conditionally destroy relevant internal data.

If eIO_Close timeout was specified (or NULL) then it blocks until either all unsent data are sent, an error flagged, or the timeout expires; if there is any output pending, that output will be flushed. Connection may remain in the system if the socket was created with the fSOCK_KeepOnClose flag set; otherwise, it gets closed as well.

Note
On MS-Windows closing a SOCK whose OS handle has been used elsewhere (e.g. in SOCK_CreateOnTop()) may render the OS handle unresponsive, so always make sure to close the current SOCK first (assuming fSOCK_KeepOnClose), and only then use the extracted handle to build another socket.
Parameters
sock[in] handle of the socket to close
destroy[in] =1 to destroy the SOCK handle; =0 to keep the handle
Note
The kept SOCK handle can be freed/destroyed by SOCK_Destroy().
SOCK_CloseEx(sock, 1) is equivalent to SOCK_Destroy(sock).
See also
SOCK_Close, SOCK_Create, SOCK_CreateOnTop, DSOCK_Create, SOCK_SetTimeout

Definition at line 6857 of file ncbi_socket.c.

References assert, BUF_Destroy(), BUF_Erase(), destroy(), eIO_InvalidArg, eIO_Success, free(), fSOCK_KeepNone, SNcbiSSLctx::host, SOCK_tag::r_buf, s_Close(), s_Initialized, SNcbiSSLctx::sess, SOCK_tag::sock, SOCK_INVALID, SOCK_tag::sslctx, and SOCK_tag::w_buf.

Referenced by CSocket::Close(), and SOCK_Close().

◆ SOCK_CloseOSHandle()

EIO_Status SOCK_CloseOSHandle ( const void *  handle,
size_t  handle_size 
)

Close socket OS handle (ungracefully aborting the connection if necessary).

The call retries repeatedly if interrupted by a singal (so no eIO_Interrupt should be expected). Return eIO_Success when the handle has been closed successfully, eIO_Closed if the handle has been passed already closed, eIO_InvalidArg if passed arguments are not valid, eIO_Unknown if the handle cannot be closed (per an error returned by the system, see errno).

Warning
Using this call on a handle that belongs to an active [LD]SOCK object is undefined.
See also
SOCK_GetOSHandleEx

Definition at line 6890 of file ncbi_socket.c.

References eIO_InvalidArg, eIO_Success, eIO_Timeout, eIO_Unknown, s_Initialized, SOCK_CLOSE, SOCK_ECONNABORTED, SOCK_ECONNRESET, SOCK_EINTR, SOCK_ENETRESET, SOCK_ENOTCONN, SOCK_ERRNO, SOCK_ETIMEDOUT, and SOCK_INVALID.

Referenced by CSocketAPI::CloseOSHandle().

◆ SOCK_Create()

EIO_Status SOCK_Create ( const char *  host,
unsigned short  port,
const STimeout timeout,
SOCK sock 
)

[CLIENT-side] Connect client to another(server-side, listening) socket (socket() + connect() [+ select()]) Equivalent to SOCK_CreateEx(host, port, timeout, sock, 0, 0, fSOCK_LogDefault).

Parameters
host[in] host to connect to
port[in] port to connect to
timeout[in] the connect timeout (infinite if NULL)
sock[out] handle of the created socket
See also
SOCK_CreateEx, SOCK_Reconnect, SOCK_Close

Definition at line 6664 of file ncbi_socket.c.

References fSOCK_LogDefault, and SOCK_CreateInternal().

◆ SOCK_CreateEx()

EIO_Status SOCK_CreateEx ( const char *  host,
unsigned short  port,
const STimeout timeout,
SOCK sock,
const void *  data,
size_t  size,
TSOCK_Flags  flags 
)

[CLIENT-side] Connect client to another(server-side, listening) socket (socket() + connect() [+ select()])

Note
SOCK_Close[Ex]() will not close the underlying OS handle if fSOCK_KeepOnClose is set in "flags".
Parameters
host[in] host to connect to
port[in] port to connect to
timeout[in] the connect timeout (infinite if NULL)
sock[out] handle of socket created
data[in] initial output data block (may be NULL)
size[in] size of the initial data block (may be 0)
flags[in] additional socket requirements
See also
SOCK_Create, SOCK_Reconnect, SOCK_Close

Definition at line 6648 of file ncbi_socket.c.

References data, flags, init(), ncbi::grid::netcache::search::fields::size, and SOCK_CreateInternal().

Referenced by CSocket::Connect(), CORE_SendMailEx(), CSocket::CSocket(), s_VT_Open(), and x_FTPPassive().

◆ SOCK_CreateOnTop()

EIO_Status SOCK_CreateOnTop ( const void *  handle,
size_t  handle_size,
SOCK sock 
)

[SERVER-side] Create a socket on top of a "handle".

Equivalent to SOCK_CreateOnTopEx(handle, handle_size, sock, 0, 0, fSOCK_LogDefault|fSOCK_CloseOnClose).

Parameters
handle[in] OS-dependent "handle" or "SOCK" to be converted
handle_size[in] "handle" size (0 if a "SOCK" passed in "handle")
sock[out] SOCK built on top of the OS "handle"
See also
SOCK_GetOSHandleEx, SOCK_CreateOnTopEx, SOCK_Close

Definition at line 6730 of file ncbi_socket.c.

References fSOCK_LogDefault, and SOCK_CreateOnTopInternal().

◆ SOCK_CreateOnTopEx()

EIO_Status SOCK_CreateOnTopEx ( const void *  handle,
size_t  handle_size,
SOCK sock,
const void *  data,
size_t  size,
TSOCK_Flags  flags 
)

[SERVER-side] Create a SOCKet on top of either an OS-dependent "handle" (file descriptor on Unix, SOCKET on MS-Windows) or an existing SOCK object.

In the former case, the returned socket is not reopenable to its default peer (SOCK_Reconnect() may not specify zeros for the connection point). In the latter case, the returned socket is reopenable to its default peer only if the original existing socket is a client-side one (connected to a remote server end), not a server-side socket (accepted at the server end). All timeouts are set to default [infinite] values. The call does *not* destroy either the OS handle or the SOCK passed in the arguments, regardless of the return status code. When a socket is being created on top of a SOCK handle, the original SOCK gets emptied (and the underlying OS handle removed from it) upon the call return (whether successfully or not), yet it will still need SOCK_Destroy() in the caller's code to free up the memory it occupies. Any secure session that may have existed in the original SOCK will have been migrated to the new socket iff "flags" indicate fSOCK_Secure (if no session existed, a new session may have been initiated in the new SOCK). Otherwise, the original secure session (if any) will have been closed. Any pending output will have been flushed (if switching secure / insecure contexts; otherwise, it will have simply migrated to the created SOCK), and any pending input still in the original SOCK will migrate to the new socket object returned. If this behavior is undesireable, one can use SOCK_GetOSHandleEx() on the original socket, taking the ownership of the underlying OS handle, and then create a SOCK on top of the bare "handle", specifying its (non-zero) "handle_size".

Warning
It is not recommended to use this call on not fully connected sockets (either bare OS handle or SOCK) in native MS-Windows builds (e.g. Cygwin is okay).
Note
SOCK_Close[Ex]() on the resultant socket will not close the underlying OS handle if fSOCK_KeepOnClose is set in "flags".
(SOCK_IsClientSide() | SOCK_IsServerSide()) can be used to determine if the original SOCK was stripped off the underlying handle: the expression would evaluate to 0(false) iff the SOCK object does no longer have the OS handle.
Warning
If a new SOCK is being built from an existing SOCK, then it is assumed that the underlying OS handle's properies have not been modified outside that old SOCK object (as all system calls to adjust the handle will be skipped).
Parameters
handle[in] OS-dependent "handle" or SOCK to be converted
handle_size[in] "handle" size (or 0 if a SOCK passed in "handle")
sock[out] SOCK built on top of the "handle"
data[in] initial output data block (may be NULL)
size[in] size of the initial data block (may be 0)
flags[in] additional socket requirements
Returns
Return eIO_Success on success; otherwise: eIO_InvalidArg if the "handle" does not refer to an open socket [but e.g. to a normal file or a pipe]; eIO_Closed when the original socket is not connected; other error codes in case of other errors.
See also
SOCK_GetOSHandleEx, SOCK_CreateOnTop, SOCK_Reconnect, SOCK_Close

Definition at line 6714 of file ncbi_socket.c.

References data, flags, init(), ncbi::grid::netcache::search::fields::size, and SOCK_CreateOnTopInternal().

Referenced by CDBLB_ServiceMapper::RecordServer().

◆ SOCK_CreateUNIX()

EIO_Status SOCK_CreateUNIX ( const char *  path,
const STimeout timeout,
SOCK sock,
const void *  data,
size_t  size,
TSOCK_Flags  flags 
)

◆ SOCK_DisableOSSendDelay()

void SOCK_DisableOSSendDelay ( SOCK  sock,
int  on_off 
)

Control OS-defined send strategy by disabling/enabling the TCP Nagle algorithm (which is on by default) that packs multiple requests into a single packet and thus transfers the data in fewer transactions, miminizing the network traffic and generally bursting the throughput.

However, some applications may find it useful to disable this default behavior for the sake of their performance increase (like in case of short transactions otherwise held off by the system in anticipation of coalescing into larger chunks – a typical example is an interactive transmission of keystrokes). Disabling the Nagle algorithm causes all internally pending yet untransmitted data to flush down to the hardware.

Note
The setting is overridden by SOCK_SetCork() but it still performs the flush, if set to disable.
Parameters
sock[in] socket handle [stream socket only]
on_off[in] 1 to disable the send delay; 0 to enable the send delay
See also
SOCK_Write, SOCK_SetCork

Definition at line 7815 of file ncbi_socket.c.

References assert, CORE_LOGF_ERRNO_EXX, CORE_LOGF_X, eLOG_Error, eLOG_Warning, eSOCK_Datagram, MAXIDLEN, s_ID(), SOCK_tag::sock, SOCK_ERRNO, SOCK_INVALID, SOCK_STRERROR, SOCK_tag::type, and UTIL_ReleaseBuffer.

Referenced by CORE_SendMailEx(), CSocket::DisableOSSendDelay(), s_VT_Open(), and URL_ConnectEx().

◆ SOCK_GetCount()

TNCBI_BigCount SOCK_GetCount ( SOCK  sock,
EIO_Event  direction 
)

Get counts of read or written bytes.

Parameters
sock[in] socket handle
direction[in] either eIO_Read or eIO_Write
Returns
Count of bytes actually read or written through this socket in the current session. For datagram sockets the count applies for the last message only; for stream sockets it counts only since last accept or connect event.

Definition at line 8492 of file ncbi_socket.c.

References assert, eIO_Read, eIO_Write, eSOCK_Datagram, SOCK_tag::n_read, SOCK_tag::n_written, SOCK_tag::r_len, SOCK_tag::type, and SOCK_tag::w_len.

Referenced by CSocket::GetCount(), and x_FTPCloseData().

◆ SOCK_gethostbyaddr()

const char* SOCK_gethostbyaddr ( unsigned int  addr,
char *  name,
size_t  namelen 
)

◆ SOCK_gethostbyaddrEx()

const char* SOCK_gethostbyaddrEx ( unsigned int  addr,
char *  name,
size_t  namelen,
ESwitch  log 
)

Take IPv4 host address (in network byte order) or 0 for current host, and fill out the provided buffer with the name, which the address corresponds to (in case of multiple names the primary name is used).

Parameters
addr[in] IPv4 host address (0 means current host) in network byte order
name[out] buffer to store the name to
namelen[in] size (bytes) of the buffer above
log[in] whether to log failures
Returns
Value 0 means error; success is denoted by the 'name' argument returned. Note that on error the name gets emptied (name[0] == '\0').
See also
SOCK_gethostbyaddr, SOCK_gethostname

Definition at line 8796 of file ncbi_socket.c.

References assert, buf, bufsize, eDefault, eIO_Success, log, s_gethostbyaddr(), s_InitAPI(), and s_Log.

Referenced by CSocketAPI::gethostbyaddr(), and SOCK_gethostbyaddr().

◆ SOCK_gethostbyname()

unsigned int SOCK_gethostbyname ( const char *  hostname)

Same as SOCK_gethostbynameEx(,<current API data logging>)

See also
SOCK_gethostbynameEx, SOCK_SetDataLoggingAPI

Definition at line 8790 of file ncbi_socket.c.

References s_Log, and SOCK_gethostbynameEx().

Referenced by DBLB_GetServer(), NcbiParseIPRange(), s_ParseHeader(), SERV_LBDNS_Open(), x_ClientAddress(), x_RedirectOK(), x_SameProxyHost(), and x_StringToAddr().

◆ SOCK_gethostbynameEx()

unsigned int SOCK_gethostbynameEx ( const char *  hostname,
ESwitch  log 
)

Find and return IPv4 address of a named host.

The call also accepts dotted IPv4 notation, in which case the conversion is done without consulting the name resolver (DNS).

Parameters
hostname[in] specified host, or the current host if hostname is either 0 or ""
log[in] whether to log failures
Returns
IPv4 host address (in network byte order) of the specified host (or of the local host, if hostname is passed as NULL / empty), which can be specified as either a domain name or an IPv4 address in the dotted notation (e.g. "123.45.67.89\0"). Return 0 on error.
Note
"0.0.0.0" and "255.255.255.255" are both considered invalid
See also
SOCK_gethostbyname, SOCK_gethostname, NcbiStringToIPv4

Definition at line 8780 of file ncbi_socket.c.

References eDefault, eIO_Success, log, s_gethostbyname(), s_InitAPI(), and s_Log.

Referenced by CSocketAPI::gethostbyname(), s_Resolve(), and SOCK_gethostbyname().

◆ SOCK_gethostname()

int SOCK_gethostname ( char *  name,
size_t  namelen 
)

Same as SOCK_gethostnameEx(,,<current API data logging>)

See also
SOCK_gethostnameEx, SOCK_gethostbyaddrEx, SOCK_SetDataLoggingAPI

Definition at line 8774 of file ncbi_socket.c.

References buf, bufsize, s_Log, and SOCK_gethostnameEx().

Referenced by ConnNetInfo_SetupStandardArgs(), CORE_SendMailEx(), s_MakeFrom(), and x_SetDefaultReferer().

◆ SOCK_gethostnameEx()

int SOCK_gethostnameEx ( char *  name,
size_t  namelen,
ESwitch  log 
)

Get the local host name.

Parameters
name[out] (guaranteed to be '\0'-terminated)
namelen[in] max # of bytes allowed to put into "name"
log[in] whether to log failures
Returns
Zero on success, non-zero on error. See BSD gethostname(). On error (incl. insufficient room) "name" returned empty (name[0] == '\0').
See also
SOCK_gethostname, SOCK_gethostbyaddr

Definition at line 8760 of file ncbi_socket.c.

References assert, buf, bufsize, eDefault, eIO_Success, log, s_gethostname(), s_InitAPI(), and s_Log.

Referenced by CSocketAPI::gethostname(), and SOCK_gethostname().

◆ SOCK_GetLocalHostAddress()

unsigned int SOCK_GetLocalHostAddress ( ESwitch  reget)

Get (and cache for faster follow-up retrievals) IPv4 address of local host.

Parameters
regeteOn to forcibly re-cache and return the address; eDefault to re-cache only if unknown, return the [new] cached value; eOff not to re-cache even if unknown, return whatever is available.
Returns
Local address (in network byte order).
See also
SOCK_gethostname

Definition at line 8827 of file ncbi_socket.c.

References eIO_Success, s_getlocalhostaddress(), s_InitAPI(), and s_Log.

Referenced by g_NCBI_ConnectSrandAddend(), CSocketAPI::GetLocalHostAddress(), LBSMD_GetLocalHostAddress(), s_IsSkipHost(), s_LoadSingleService(), SERV_ServerPort(), x_ClientAddress(), x_FTPActive(), and x_Open().

◆ SOCK_GetLocalPort()

unsigned short SOCK_GetLocalPort ( SOCK  sock,
ENH_ByteOrder  byte_order 
)

Get local port of the socket.

The returned port number is also cached within "sock" so any further inquires for the local port do not cause any system calls to occur. The call is exactly equavalent to SOCK_GetLocalPortEx(sock, 0, byte_order).

Parameters
sock[in] socket handle
byte_order[in] byte order for port on return
Returns
Local port number in requested byte order, or 0 in case of an error.
See also
SOCK_GetLocalPortEx

Definition at line 7605 of file ncbi_socket.c.

References SOCK_GetLocalPortEx().

◆ SOCK_GetLocalPortEx()

unsigned short SOCK_GetLocalPortEx ( SOCK  sock,
int  trueport,
ENH_ByteOrder  byte_order 
)

Get local port of the socket (true or cached / stored).

For most users, a simpler SOCK_GetLocalPort() call is going to be the most suitable. This call allows to inquire the network level about a temporary port number assigned when a socket was created as a result of accepting the connection (otherwise, the listening socket port number gets returned as the local port). For connecting sockets, both "trueport" and no "trueport" results are identical (with the exception that "trueport" causes an additional system call, and the result is not stored).

Parameters
sock[in] socket handle
trueport[in] non-zero causes to refetch / no-cache port from the network layer
byte_order[in] byte order for port on return
Returns
The port number in requested byte order, or 0 in case of an error.
See also
SOCK_GetLocalPort

Definition at line 7581 of file ncbi_socket.c.

References eNH_HostByteOrder, SOCK_tag::myport, SOCK_tag::path, s_GetLocalPort(), SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::GetLocalPort(), and SOCK_GetLocalPort().

◆ SOCK_GetLoopbackAddress()

unsigned int SOCK_GetLoopbackAddress ( void  )

Get loopback IPv4 address.

Returns
Loopback address (in network byte order).

Definition at line 8821 of file ncbi_socket.c.

References SOCK_LOOPBACK.

Referenced by DBLB_GetServer(), and CSocketAPI::GetLoopbackAddress().

◆ SOCK_GetOSHandle()

EIO_Status SOCK_GetOSHandle ( SOCK  sock,
void *  handle_buf,
size_t  handle_size 
)

Same as SOCK_GetOSHandleEx(sock, handle_buf, handle_size, eNoOwnership).

See also
SOCK_GetOSHandleEx

Definition at line 7744 of file ncbi_socket.c.

References eNoOwnership, and SOCK_GetOSHandleEx().

Referenced by CRPCClient< TRequest, TReply >::AsyncConnect().

◆ SOCK_GetOSHandleEx()

EIO_Status SOCK_GetOSHandleEx ( SOCK  sock,
void *  handle_buf,
size_t  handle_size,
EOwnership  ownership 
)

Get an OS-dependent native socket handle to use by platform-specific API.

FYI: on MS-Windows it will be "SOCKET", on other platforms – "int".

Parameters
sock[in] socket handle
handle_buf[out] pointer to a memory area to put the OS handle at
handle_size[in] the exact(!) size of the expected OS handle
ownershipeTakeOwnership removes the handle from SOCK; eNoOwnership retains it
Note
If handle ownership is taken, all operations with this SOCK (except for SOCK_Close[Ex]()) will fail.
See also
SOCK_OSHandleSize, SOCK_GetOSHandle, SOCK_CloseOSHandle, SOCK_CloseEx

Definition at line 7706 of file ncbi_socket.c.

References assert, CORE_LOGF_X, eIO_InvalidArg, eIO_Success, eLOG_Error, eTakeOwnership, fSOCK_KeepNone, SOCK_tag::keep, MAXIDLEN, s_Close(), s_ID(), s_Initialized, SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::GetOSHandle(), and SOCK_GetOSHandle().

◆ SOCK_GetPeerAddress()

void SOCK_GetPeerAddress ( SOCK  sock,
unsigned int host,
unsigned short *  port,
ENH_ByteOrder  byte_order 
)

Get host and port of the socket's peer (remote end).

Parameters
sock[in] socket handle
host[out] the peer's host (can be NULL, then not filled in)
port[out] the peer's port (can be NULL, then not filled in)
byte_order[in] byte order for either host or port, or both, on return
Returns
Host/port addresses in requested byte order, or 0 in case of an error.
See also
SOCK_GetLocalPort

Definition at line 7612 of file ncbi_socket.c.

References eNH_HostByteOrder, SOCK_tag::host, and SOCK_tag::port.

Referenced by CSocket::GetPeerAddress(), CDBLB_ServiceMapper::RecordServer(), s_Init(), and SOCK_GetRemotePort().

◆ SOCK_GetPeerAddressString()

char* SOCK_GetPeerAddressString ( SOCK  sock,
char *  buf,
size_t  bufsize 
)

Equivalent to SOCK_GetPeerAddressStringEx(.,.,.,eSAF_Full)

Definition at line 7644 of file ncbi_socket.c.

References buf, bufsize, eSAF_Full, and SOCK_GetPeerAddressStringEx().

◆ SOCK_GetPeerAddressStringEx()

char* SOCK_GetPeerAddressStringEx ( SOCK  sock,
char *  buf,
size_t  bufsize,
ESOCK_AddressFormat  format 
)

◆ SOCK_GetPosition()

TNCBI_BigCount SOCK_GetPosition ( SOCK  sock,
EIO_Event  direction 
)

Get current read or write position within a socket.

Parameters
sock[in] socket handle
direction[in] either eIO_Read or eIO_Write
Returns
Current read or write logical position, which takes any pending (i.e. still unwritten or yet unread) data into account, by reporting / not reporting that, respectively, in the position returned. For datagram sockets, the position is always relative to the beginning of the current message, and gets reset with every new message (i.e. does not span across the messages).

Definition at line 8471 of file ncbi_socket.c.

References assert, BUF_Size(), eIO_Read, eIO_Write, eSOCK_Datagram, SOCK_tag::n_read, SOCK_tag::n_written, SOCK_tag::r_buf, SOCK_tag::r_len, SOCK_tag::type, SOCK_tag::w_buf, and SOCK_tag::w_len.

Referenced by CSocket::GetPosition().

◆ SOCK_GetRemotePort()

unsigned short SOCK_GetRemotePort ( SOCK  sock,
ENH_ByteOrder  byte_order 
)

Get remote port of the socket (the port it is connected to).

The call is provided as a counterpart for SOCK_GetLocalPort(), and is equivalent to calling SOCK_GetPeerAddress(sock, 0, &port, byte_order).

Parameters
sock[in] socket handle
byte_order[in] byte order for port on return
Returns
Remote port number in requested byte order, or 0 in case of an error.
See also
SOCK_GetPeerAddress, SOCK_GetLocalPort

Definition at line 7635 of file ncbi_socket.c.

References SOCK_GetPeerAddress().

Referenced by CSocket::GetRemotePort(), and CDBLB_ServiceMapper::RecordServer().

◆ SOCK_GetTimeout()

const STimeout* SOCK_GetTimeout ( SOCK  sock,
EIO_Event  event 
)

Get the connection's i/o timeout (or NULL, if the timeout is infinite).

Note
The returned timeout is guaranteed to be pointing to a valid structure in memory at least until the SOCK is closed or SOCK_SetTimeout() is called for this "sock".
eIO_ReadWrite timeout is the least of eIO_Read and eIO_Write ones.
Parameters
sock[in] socket handle
event[in] one of: eIO_[Read/Write/Close]
See also
SOCK_Read, SOCK_Write, SOCK_Close

Definition at line 7230 of file ncbi_socket.c.

References assert, SOCK_tag::c_to, SOCK_tag::c_tv, SOCK_tag::c_tv_set, CORE_LOGF_X, eIO_Close, eIO_Read, eIO_ReadWrite, eIO_Write, eLOG_Error, MAXIDLEN, SOCK_tag::r_to, SOCK_tag::r_tv, SOCK_tag::r_tv_set, s_ID(), s_tv2to(), SOCK_tag::w_to, SOCK_tag::w_tv, and SOCK_tag::w_tv_set.

Referenced by CSocket::Reset(), s_ReadHeader(), and x_DrainData().

◆ SOCK_GetTotalCount()

TNCBI_BigCount SOCK_GetTotalCount ( SOCK  sock,
EIO_Event  direction 
)

Get the total volume of data transferred by a socket.

Parameters
sock[in] socket handle
direction[in] either eIO_Read or eIO_Write
Returns
Total number of bytes transferred through the socket in its lifetime.

Definition at line 8509 of file ncbi_socket.c.

References assert, eIO_Read, eIO_Write, eSOCK_Datagram, SOCK_tag::n_in, SOCK_tag::n_out, SOCK_tag::n_read, SOCK_tag::n_written, and SOCK_tag::type.

Referenced by CSocket::GetTotalCount().

◆ SOCK_HostPortToString()

size_t SOCK_HostPortToString ( unsigned int  host,
unsigned short  port,
char *  buf,
size_t  bufsize 
)

Print numeric string "host:port" into a buffer provided, not to exceed 'bufsize' bytes (including the teminating '\0' character).

Suppress printing the "host" if the 'host' parameter is zero. Suppress printing the ":port" part if 'port' passed as zero, but if both the 'host' and the 'port' parameters are zero, output is the literal ":0".

Parameters
hostIPv4 in network byte order
portin host byte order
bufmust not be NULL
bufsizemust be large enough
Returns
Number of bytes printed, or 0 on error (e.g. buffer is too small).
See also
SOCK_StringToHostPort, SOCK_ntoa, SOCK_gethostbyaddr

Definition at line 8945 of file ncbi_socket.c.

References buf, ncbi::grid::netcache::search::fields::size, and SOCK_HostPortToStringEx().

Referenced by DBLB_GetServer(), DSOCK_Connect(), CSocketAPI::HostPortToString(), LB_Select(), LBSM_SubmitPenaltyOrRerate(), s_CP(), s_CreateListening(), s_DoLog(), s_ID(), LbsmLookup::s_Resolve(), s_Resolve(), s_SendMsg(), SERV_LBDNS_Open(), SERV_Print(), SERV_WriteInfo(), and SOCK_GetPeerAddressStringEx().

◆ SOCK_HostToNetLong()

unsigned int SOCK_HostToNetLong ( unsigned int  value)

See man for the BSDisms, htonl() and htons().

Parameters
valueThe value to convert from host to network byte order.

Definition at line 8736 of file ncbi_socket.c.

References rapidjson::value.

Referenced by CSocketAPI::HostToNetLong(), NcbiParseIPRange(), s_Init(), s_LoadLocalIPs(), s_ParseHeader(), SERV_ReadInfoEx(), SERV_WriteInfo(), x_FTPPasv(), x_SetHostPort(), and xx_LoadLocalIPs().

◆ SOCK_HostToNetShort()

unsigned short SOCK_HostToNetShort ( unsigned short  value)

See man for the BSDisms, htonl() and htons().

Parameters
valueThe value to convert from host to network byte order.

Definition at line 8742 of file ncbi_socket.c.

References rapidjson::value.

Referenced by CSocketAPI::HostToNetShort(), x_FTPPort(), and x_StringToIPv6().

◆ SOCK_htonl()

unsigned int SOCK_htonl ( unsigned int  value)

Definition at line 8748 of file ncbi_socket.c.

References rapidjson::value.

◆ SOCK_htons()

unsigned short SOCK_htons ( unsigned short  value)

Definition at line 8754 of file ncbi_socket.c.

References rapidjson::value.

◆ SOCK_InitializeAPI()

EIO_Status SOCK_InitializeAPI ( void  )

Initialize all internal/system data & resources to be used by the SOCK API.

Note
You can safely call it more than once; just, all calls after the first one will have no result.
Usually, SOCK API does not require an explicit initialization – as it is guaranteed to initialize itself automagically, in one of API functions, when necessary. Yet, see the "Multi Thread safety" remark above.
This call, when used for the very first time in the application, enqueues SOCK_ShutdownAPI() to be called upon application exit on plaftorms that provide this functionality. In any case, the application can opt for explicit SOCK_ShutdownAPI() call when it is done with all sockets.
See also
SOCK_ShutdownAPI

Definition at line 991 of file ncbi_socket.c.

References eIO_Success, eSOCK_ErrInit, info, s_ErrHook, s_ErrorCallback(), and s_Init().

Referenced by CNetScheduleDApp::Init(), CNetStorageDApp::Init(), and CSocketAPI::Initialize().

◆ SOCK_IsClientSide()

int SOCK_IsClientSide ( SOCK  sock)

Check whether a socket is client-side.

Parameters
sock[in] socket handle
Returns
Non-zero value if socket "sock" was created by SOCK_Create[Ex](). Return zero otherwise.

Definition at line 8439 of file ncbi_socket.c.

References eSOCK_Client, SOCK_tag::side, SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::IsClientSide().

◆ SOCK_IsDatagram()

int SOCK_IsDatagram ( SOCK  sock)

Check whether a socket is a datagram one.

Parameters
sock[in] socket handle
Returns
Non-zero value if socket "sock" was created by DSOCK_Create[Ex](). Return zero otherwise.

Definition at line 8432 of file ncbi_socket.c.

References eSOCK_Datagram, SOCK_tag::sock, SOCK_INVALID, and SOCK_tag::type.

Referenced by CSocket::IsDatagram().

◆ SOCK_isip()

int SOCK_isip ( const char *  host)

Equivalent of SOCK_isip(host, 0)

Parameters
host[in] '\0'-terminated string to check against being a plain IPv4 address
Returns
Non-zero (true) if given string is an IPv4 address, zero (false) otherwise.

Definition at line 8712 of file ncbi_socket.c.

References SOCK_isipEx(), and str().

Referenced by NcbiParseIPRange(), s_ApproveCallback(), s_Connect_(), s_Create(), s_CreateOnTop(), s_gethostbyname_(), s_SendMsg(), SERV_ReadInfoEx(), and x_IsSufficientAddress().

◆ SOCK_isipEx()

int SOCK_isipEx ( const char *  host,
int  fullquad 
)

Check whether the given string represents a valid IPv4 address.

Parameters
host[in] '\0'-terminated string to check against being a plain IPv4 address
fullquad[in] non-zero to only accept "host" if it is a full-quad IPv4 notation
Returns
Non-zero (true) if given string is an IPv4 address, zero (false) otherwise.
Note
Unless "fullquad" is requested, valid IPv4 addresses may have various formats (e.g. legal to be 32-bit integers, or have fewer than 3 dots).

Definition at line 8680 of file ncbi_socket.c.

References isdigit(), str(), and val.

Referenced by CSocketAPI::isip(), NcbiParseIPRange(), s_gethostbyname_(), SERV_ReadInfoEx(), SOCK_isip(), and x_RedirectOK().

◆ SOCK_IsLoopbackAddress()

int SOCK_IsLoopbackAddress ( unsigned int  ip)

Check whether an address is a loopback one.

Return non-zero (true) if the IPv4 address (in network byte order) given in the agrument, is a loopback one; zero otherwise.

Definition at line 8718 of file ncbi_socket.c.

References IN_LOOPBACKNET, INADDR_LOOPBACK, and ip.

Referenced by NcbiGetHostIfConfEx(), s_gethostbyname(), and x_ChooseSelfIP().

◆ SOCK_IsSecure()

int SOCK_IsSecure ( SOCK  sock)

Check whether a socket is using SSL (Secure Socket Layer).

Parameters
sock[in] socket handle
Returns
Non-zero value if socket "sock" is using Secure Socket Layer (SSL). Return zero otherwise.

Definition at line 8464 of file ncbi_socket.c.

References SOCK_tag::sock, SOCK_INVALID, and SOCK_tag::sslctx.

Referenced by CSocket::IsSecure(), and s_Connect().

◆ SOCK_IsServerSide()

int SOCK_IsServerSide ( SOCK  sock)

Check whether a socket is server-side.

Parameters
sock[in] socket handle
Returns
Non-zero value if socket "sock" was created by LSOCK_Accept(). Return zero otherwise.

Definition at line 8446 of file ncbi_socket.c.

References eSOCK_Server, SOCK_tag::side, SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::IsServerSide().

◆ SOCK_IsUNIX()

int SOCK_IsUNIX ( SOCK  sock)

Check whether a socket is UNIX type.

Parameters
sock[in] socket handle
Returns
Non-zero value if socket "sock" is a UNIX family named socket Return zero otherwise.

Definition at line 8453 of file ncbi_socket.c.

References SOCK_tag::path, SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::IsUNIX().

◆ SOCK_ntoa()

int SOCK_ntoa ( unsigned int  addr,
char *  buf,
size_t  bufsize 
)

Convert IP address to a string in dotted notation.

Parameters
addr[in] must be in the network byte-order
buf[out] to be filled by smth. like "123.45.67.89\0"
bufsize[in] max # of bytes to put into "buf" (including the terminating '\0')
Returns
Zero on success, non-zero on error. Vaguely related to BSD's inet_ntoa(). On error (including insufficient room in "buf" to store the result) "buf" is returned empty (buf[0] == '\0').

Definition at line 8661 of file ncbi_socket.c.

References assert, b, buf, bufsize, and len.

Referenced by CConnTest::CheckFWConnections(), CSocket::Connect(), CDatagramSocket::Connect(), CSocket::CSocket(), dns_a(), DSOCK_RecvMsg(), DSOCK_SendMsg(), DSOCK_WaitMsg(), NcbiDumpIPRange(), CSocketAPI::ntoa(), s_Close(), s_Connect(), s_CreateListening(), s_gethostbyaddr_(), s_gethostbyname(), s_gethostbyname_(), s_GetSysinfo(), s_Init(), s_LookupHost(), s_Open(), s_Read(), s_WaitConnected(), s_Write(), SOCK_GetPeerAddressStringEx(), SOCK_HostPortToStringEx(), SOCK_Shutdown(), SOCK_Wait(), x_ClientAddress(), x_FTPEprt(), x_FTPPassive(), x_IPv6ToString(), and x_SetHostPort().

◆ SOCK_OSHandleSize()

size_t SOCK_OSHandleSize ( void  )

Get size of OS-dependent native socket handle.

Returns
OS-dependent handle size or 0 in case of an error
See also
SOCK_GetOSHandle

Definition at line 1069 of file ncbi_socket.c.

Referenced by CSocketAPI::OSHandleSize().

◆ SOCK_Poll()

EIO_Status SOCK_Poll ( size_t  n,
SSOCK_Poll  polls[],
const STimeout timeout,
size_t *  n_ready 
)

Block until at least one of the sockets enlisted in "polls" array (of size "n") becomes available for requested operation (SSOCK_Poll::event), or until timeout expires (wait indefinitely if timeout is passed as NULL).

Note
To lower overhead, use SOCK_Wait() to wait for I/O on a single socket.

Return eIO_Success if at least one socket was found ready; eIO_Timeout if timeout expired; eIO_Unknown if underlying system call(s) failed.

Note
NULL sockets (without any verification for the contents of the "event" field) as well as non-NULL sockets with eIO_Open requested in their "event" do not get polled (yet the corresponding "revent" gets updated to indicate eIO_Open, for no I/O event ready);
For a socket found not ready for an operation, eIO_Open gets returned in its "revent"; for a failing / closed socket – eIO_Close;
This call may return eIO_InvalidArg if:
  • parameters to the call are incomplete / inconsistent;
  • a non-NULL socket polled with a bad "event" (e.g. eIO_Close). With this return code, the caller cannot rely on "revent" fields in the "polls" array as they might not have been updated properly.
If either both "n" and "polls" are NULL, or all sockets in the "polls" array are either NULL or without any events requested (eIO_Open), then the returned status is either:
  • eIO_Timeout (after the specified amount of time was spent idle), or
  • eIO_Interrupt (if a signal came while the waiting was in progress).
For datagram sockets, the readiness for reading is determined by the message data latched since the last message receive call, DSOCK_RecvMsg().
This call allows the intermixture of stream, datagram, and listening sockets (cast to SOCK), as well as triggers (also cast to SOCK), but for the sake of readability, it is recommended to use POLLABLE_Poll() in such circumstances.
This call may cause some socket I/O in those sockets marked for read-on-write and those with pending connection or output data.
Parameters
n[in] # of SSOCK_Poll elems in "polls"
polls[][in|out] array of query/result structures
timeout[in] max time to wait (infinite if NULL)
n_ready[out] # of ready sockets (may be NULL)
See also
SOCK_Wait, POLLABLE_Poll

Definition at line 7083 of file ncbi_socket.c.

References assert, BUF_Size(), eIO_Close, eIO_InvalidArg, eIO_Open, eIO_Read, eIO_ReadWrite, eIO_Success, eIO_Write, SOCK_tag::eof, eSOCK_Socket, eSOCK_Trigger, SSOCK_Poll::event, free(), i, n, SOCK_tag::r_buf, SOCK_tag::r_status, SSOCK_Poll::revent, s_SelectStallsafe(), s_to2tv(), SOCK_tag::sock, SOCK_INVALID, SOCK_tag::type, and SOCK_tag::w_status.

Referenced by SNetServerInPool::GetConnectionFromPool(), and POLLABLE_Poll().

◆ SOCK_Pushback()

EIO_Status SOCK_Pushback ( SOCK  sock,
const void *  data,
size_t  size 
)

Push the specified data back to the socket's input queue (in the socket's internal read buffer).

These can be any data, not necessarily the data previously read from the socket. The most recently pushed back data are the data that will be read from the socket first (by either SOCK_ReadLine() or SOCK_Read()). The presence of pushed back data makes the socket ready for read immediately (SOCK_Wait(sock, eIO_Read) succeeds without waiting).

Parameters
sock[in] socket handle
data[in] data to push back to the socket's local buffer
size[in] # of bytes (starting at "data") to push back
See also
SOCK_Read, SOCK_ReadLine, SOCK_Wait

Definition at line 7439 of file ncbi_socket.c.

References assert, CORE_LOGF_X, data, eIO_InvalidArg, eIO_Success, eIO_Unknown, eLOG_Error, MAXIDLEN, s_ID(), s_Pushback, ncbi::grid::netcache::search::fields::size, SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::Pushback(), s_SOCK_IO(), and x_PushbackBuf().

◆ SOCK_Read()

EIO_Status SOCK_Read ( SOCK  sock,
void *  buf,
size_t  size,
size_t *  n_read,
EIO_ReadMethod  how 
)

Read/peek up to "size" bytes from "sock" to a buffer pointed to by "buf".

In "*n_read", return the number of successfully read bytes. Read method "how" can be either of the following: eIO_ReadPlain – read as many as "size" bytes and return (eIO_Success); if no data are readily available then wait at most read timeout and return (eIO_Timeout) if no data still could be got; eIO_Success if some data were obtained. eIO_ReadPeek – same as "eIO_ReadPlain" but do not extract the data from the socket (so that the next read operation will see the data again), with one important exception noted below. eIO_ReadPersist – read exactly "size" bytes and return eIO_Success; if less data received then return an error condition (including eIO_Timeout).

If there is no data available to read (also, if eIO_ReadPersist and cannot read exactly "size" bytes) and the timeout(see SOCK_SetTimeout()) is expired then return eIO_Timeout.

Both eIO_ReadPlain and eIO_ReadPeek return eIO_Success iff some data have been actually read (within the time allotted by the eIO_Read timeout). Both methods return any other code when no data at all were available. In that respect, eIO_ReadPersist differs from the other two methods as it can return an error condition even if some (but not all) data were actually obtained from the socket.

Hence, as the *rule of thumb*, an application should always check the number of read bytes BEFORE checking the return status, which merely advises as to whether it is okay to read again.

As a special case, "buf" may passed as NULL: eIO_ReadPeek – read up to "size" bytes and store them in internal buffer; eIO_Read[Persist] – discard up to "size" bytes from internal buffer and socket (check "*n_read" to know how many).

Note
"Read" and "peek" methods differ: when "read" is performed and not enough but only some data are available immediately from the internal buffer, then the call still completes with the eIO_Success status. For "peek", if not all requested data were available right away, the real I/O occurs to try to pick up additional data from the system. Keep this difference in mind when programming loops that heavily use "peek"s without "read"s.
If on input "size" == 0, then "*n_read" is set to 0 on return, and the return status value can be either of eIO_Success, eIO_Closed, eIO_Timeout (if still connecting), or eIO_Unknown depending on the _current_ state of the socket regardless of any pending read data.
Parameters
sock[in] socket handle
buf[out] data buffer to read to
size[in] max # of bytes to read to "buf"
n_read[out] # of bytes read (can be NULL)
how[in] how to read the data
See also
SOCK_SetTimeout, SOCK_PushBack

Definition at line 7270 of file ncbi_socket.c.

References assert, buf, CORE_LOGF_X, eIO_NotSupported, eIO_ReadPeek, eIO_ReadPersist, eIO_ReadPlain, eIO_Success, eIO_Unknown, eLOG_Error, MAXIDLEN, s_ID(), s_Read(), ncbi::grid::netcache::search::fields::size, SOCK_tag::sock, and SOCK_INVALID.

Referenced by CSocket::Read(), s_Read(), s_ReadData(), s_SOCK_IO(), s_SockRead(), s_VT_Read(), and x_DrainData().

◆ SOCK_ReadLine()

EIO_Status SOCK_ReadLine ( SOCK  sock,
char *  line,
size_t  size,
size_t *  n_read 
)

Read a line from SOCK.

A line is terminated by either '
' (with an optional preceding '\r') or '\0', and is stored in the buffer "line" of "size" characters long. "*n_read" (if "n_read" passed non-NULL) receives the number of characters written into "line", not counting the terminating '\0'. Returned result is '\0'-terminated (and has '\r'(if any)'
' stripped) but only if "size" is big enough to contain the entire line. Otherwise, all "size" bytes are filled, and "*n_read" == "size" upon return, and there is no terminating '\0' in this (and the only!) case, which the caller can easily distinguish. The remainder of the line can be read with successive call(s) to SOCK_ReadLine() until the '\0' terminator is received in the buffer.

Parameters
sock[in] socket handle
line[out] line buffer to read to, non-NULL
size[in] max # of bytes to read to "line", non-0
n_read[out] # of bytes read (optional, can be NULL)
Returns
Return eIO_Success upon successful completion: either a line separator is encountered or the buffer is filled up completely, and any excess read has been successfully saved for further I/O. Other code, otherwise.
Note
that "*n_read" should be analyzed prior to the return status, because the buffer could have received some contents before the indicated error occurred (e.g. when the connection closes before a line separator is seen).
See also
SOCK_SetTimeout, SOCK_PushBack

Definition at line 7329 of file ncbi_socket.c.

References assert, BUF_Size(), CORE_LOGF_X, done, eIO_InvalidArg, eIO_Success, eIO_Unknown, eLOG_Critical, eLOG_Error, SOCK_tag::eof, i, len, MAXIDLEN, SOCK_tag::r_buf, SOCK_tag::r_status, s_ID(), s_Pushback, s_Read(), ncbi::grid::netcache::search::fields::size, SOCK_tag::sock, SOCK_INVALID, and x_size().

Referenced by CSocket::ReadLine(), and x_FTPParseReply().

◆ SOCK_Reconnect()

EIO_Status SOCK_Reconnect ( SOCK  sock,
const char *  host,
unsigned short  port,
const STimeout timeout 
)

[CLIENT-side] Close the socket referred to by "sock" and then connect it to another "host:port"; fail if it takes more than "timeout" (close() + connect() [+ select()])

HINT: if "host" is NULL then connect to the same host address as before; if "port" is zero then connect to the same port # as before.

Note
The "new" socket inherits old I/O timeouts;
The call is only applicable to stream [not datagram] sockets.
"timeout"==NULL is infinite (also as kInfiniteTimeout); "timeout"=={0,0} causes no wait for connection to be established, and to return immediately.
UNIX sockets can only be reconnected to the same file, thus both host and port have to be passed as 0s.
Parameters
sock[in] handle of the socket to reconnect
host[in] host to connect to (can be NULL)
port[in] port to connect to (can be 0)
timeout[in] the connect timeout (infinite if NULL)

Definition at line 6739 of file ncbi_socket.c.

References assert, BUF_Erase(), CORE_LOGF_X, eIO_InvalidArg, eLOG_Error, eSOCK_Client, eSOCK_Datagram, eSOCK_Server, free(), fSOCK_KeepNone, SNcbiSSLctx::host, SOCK_tag::id, MAXIDLEN, SOCK_tag::n_read, SOCK_tag::n_written, SOCK_tag::path, SOCK_tag::r_buf, s_Close(), s_Connect(), s_ID(), SOCK_tag::side, SOCK_tag::sock, SOCK_INVALID, SOCK_tag::sslctx, SOCK_tag::type, and SOCK_tag::w_buf.

Referenced by CSocket::Reconnect().

◆ SOCK_SetApproveHookAPI()

void SOCK_SetApproveHookAPI ( FSOCK_ApproveHook  hook,
void *  data 
)

The hook is installed when non-NULL, and de-installed otherwise.

optional user data

Parameters
hookthe hook function

Definition at line 1623 of file ncbi_socket.c.

References CORE_LOCK_WRITE, CORE_UNLOCK, data, s_ApproveData, and s_ApproveHook.

◆ SOCK_SetCork()

void SOCK_SetCork ( SOCK  sock,
int  on_off 
)

Control OS-defined send strategy by disabling/enabling the TCP layer to send incomplete network frames (packets).

With the "cork" set on, data gets always buffered until a complete hardware packet is full (or connection is about to close), and only then is sent out to the wire.

Note
The setting cancels the effects of SOCK_DisableOSSendDelay().
Parameters
sock[in] socket handle [stream socket only]
on_off[in] 1 to set the cork; 0 to remove the cork
See also
SOCK_Write, SOCK_DisableOSSendDelay

Definition at line 7773 of file ncbi_socket.c.

References assert, CORE_LOGF_ERRNO_EXX, CORE_LOGF_X, eLOG_Error, eLOG_Warning, eSOCK_Datagram, MAXIDLEN, s_ID(), SOCK_tag::sock, SOCK_ERRNO, SOCK_INVALID, SOCK_STRERROR, SOCK_tag::type, and UTIL_ReleaseBuffer.

Referenced by CORE_SendMailEx(), CSocket::SetCork(), and x_FTPXfer().

◆ SOCK_SetDataLogging()

ESwitch SOCK_SetDataLogging ( SOCK  sock,
ESwitch  log 
)

Control the data logging for socket "sock" individually.

Parameters
sock[in] socket handle
log[in] requested data logging To reset to the global default behavior (as set by SOCK_SetDataLoggingAPI), call this function with "log" == eDefault.
Returns
Prior setting
See also
SOCK_SetDataLoggingAPI, SOCK_Create, DSOCK_Create

Definition at line 8583 of file ncbi_socket.c.

References log, and SOCK_tag::log.

Referenced by s_FTPCommandEx(), CSocket::SetDataLogging(), x_DrainData(), x_FTPCloseData(), x_FTPPassive(), and x_FTPXfer().

◆ SOCK_SetDataLoggingAPI()

ESwitch SOCK_SetDataLoggingAPI ( ESwitch  log)

By default data are not logged.

Parameters
logTo start logging the data, call this func with "log" == eOn. To stop logging the data, call this func with "log" == eOff. To get current log switch, call this func with "log" == eDefault.
Returns
Prior (or current, if "log" is eDefault) setting
See also
SOCK_SetDataLogging

Definition at line 8574 of file ncbi_socket.c.

References eDefault, log, and s_Log.

Referenced by s_FTPCommandEx(), and CSocketAPI::SetDataLogging().

◆ SOCK_SetErrHookAPI()

void SOCK_SetErrHookAPI ( FSOCK_ErrHook  hook,
void *  data 
)

Definition at line 384 of file ncbi_socket.c.

References CORE_LOCK_WRITE, CORE_UNLOCK, data, s_ErrData, and s_ErrHook.

◆ SOCK_SetInterruptOnSignal()

ESwitch SOCK_SetInterruptOnSignal ( SOCK  sock,
ESwitch  on_off 
)

Control restartability of I/O interrupted by signals on a per-socket basis.

eDefault causes the use of global API flag.

Parameters
sock[in] socket handle
on_off[in] per-socket I/O restart behavior on signals
Returns
Prior setting
See also
SOCK_SetInterruptOnSignalAPI, SOCK_Create, DSOCK_Create

Definition at line 8541 of file ncbi_socket.c.

References SOCK_tag::i_on_sig.

Referenced by CSocket::SetInterruptOnSignal().

◆ SOCK_SetInterruptOnSignalAPI()

ESwitch SOCK_SetInterruptOnSignalAPI ( ESwitch  on_off)

Control restartability of I/O interrupted by signals.

By default I/O is restartable if interrupted. Pass "on_off" as eDefault to get the current setting.

Parameters
on_off[in] eOn to cancel I/O on signals; eOff to restart
Returns
Prior setting
See also
SOCK_SetInterruptOnSignal

Definition at line 8532 of file ncbi_socket.c.

References eDefault, and s_InterruptOnSignal.

Referenced by CSocketAPI::SetInterruptOnSignal().

◆ SOCK_SetIOWaitSysAPI()

ESOCK_IOWaitSysAPI SOCK_SetIOWaitSysAPI ( ESOCK_IOWaitSysAPI  api)

This is a helper call that can improve I/O performance (ignored for MSVC).

Parameters
api[in] Default behavior is to wait for I/O such a way that accomodates the requested sockets accordingly. There is a known limitation of the select() API that requires all sockets to have numeric values of their low-level I/O handles less than (as little as) 1024, but works faster than the poll() API that does not have limits on the number or numeric values of the handles. Either API can be enforced here.
Returns
Previous value of the API selector
See also
SOCK_Wait, SOCK_Poll

Definition at line 1086 of file ncbi_socket.c.

References CORE_LOG_X, eLOG_Critical, eSOCK_IOWaitSysAPIPoll, and s_IOWaitSysAPI.

Referenced by CNetScheduleDApp::Run(), CNetStorageDApp::Run(), and CSocketAPI::SetIOWaitSysAPI().

◆ SOCK_SetReadOnWrite()

ESwitch SOCK_SetReadOnWrite ( SOCK  sock,
ESwitch  on_off 
)

Control the reading-while-writing feature for socket "sock" individually.

To reset to the global default behavior (as set by SOCK_SetReadOnWriteAPI()), call this function with "on_off" == eDefault.

Parameters
sock[in] socket handle
on_off[in] R-on-W setting for this socket
Returns
Prior setting
See also
SOCK_Read

Definition at line 7761 of file ncbi_socket.c.

References eDefault, eSOCK_Datagram, SOCK_tag::r_on_w, and SOCK_tag::type.

Referenced by CSocket::SetReadOnWrite().

◆ SOCK_SetReadOnWriteAPI()

ESwitch SOCK_SetReadOnWriteAPI ( ESwitch  on_off)

By default, sockets will not try to read data from inside SOCK_Write().

If you want to automagically upread the data (and cache it in the internal socket buffer) when the write operation is not immediately available, call this func with "on_off" == eOn. Pass "on_off" as eDefault to get current setting.

Parameters
on_off
Returns
Prior setting

Definition at line 7752 of file ncbi_socket.c.

References eDefault, and s_ReadOnWrite.

Referenced by CSocketAPI::SetReadOnWrite().

◆ SOCK_SetReuseAddress()

void SOCK_SetReuseAddress ( SOCK  sock,
int  on_off 
)

Control reuse of socket addresses on per-socket basis Note: only a boolean parameter value is can be used here.

Parameters
sock[in] socket handle
on_off[in] whether to reuse the address (true, non-zero) or not (false, zero)
See also
SOCK_SetReuseAddressAPI, SOCK_Create, DSOCK_Create

Definition at line 8558 of file ncbi_socket.c.

References CORE_LOGF_ERRNO_EXX, eLOG_Warning, MAXIDLEN, s_ID(), s_SetReuseAddress(), SOCK_tag::sock, SOCK_ERRNO, SOCK_INVALID, SOCK_STRERROR, and UTIL_ReleaseBuffer.

Referenced by CSocket::SetReuseAddress().

◆ SOCK_SetReuseAddressAPI()

ESwitch SOCK_SetReuseAddressAPI ( ESwitch  on_off)

Control address reuse for socket addresses taken by the API.

By default address is not marked for reuse in either SOCK or DSOCK, but is always reused for LSOCK (upon socket closure). Pass "on_off" as eDefault to get the current setting.

Parameters
on_off[in] whether to turn on (eOn), turn off (eOff) or get current (eDefault)
Returns
Prior setting
See also
SOCK_SetReuseAddress

Definition at line 8549 of file ncbi_socket.c.

References eDefault, and s_ReuseAddress.

Referenced by CSocketAPI::SetReuseAddress().

◆ SOCK_SetSelectInternalRestartTimeout()

const STimeout* SOCK_SetSelectInternalRestartTimeout ( const STimeout timeslice)

This is a helper call that can improve I/O behavior.

Parameters
timeslice[in] Break down long waits for I/O into smaller intervals of at most "timeslice" duration each. This can help recover "hanging" sockets from indefinite wait and allow them to report an exceptional I/O condition.
Returns
Previous value of the timeslice
See also
SOCK_Wait, SOCK_Poll

Definition at line 1075 of file ncbi_socket.c.

References s_SelectTimeout, s_to2tv(), s_tv2to(), and t.

Referenced by CSocketAPI::SetSelectInternalRestartTimeout().

◆ SOCK_SetTimeout()

EIO_Status SOCK_SetTimeout ( SOCK  sock,
EIO_Event  event,
const STimeout timeout 
)

Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()).

If "timeout" is NULL then set the timeout to be infinite;

Note
The default timeout is infinite (to wait indefinitely).
Parameters
sock[in] socket handle
event[in] one of: eIO_[Read/Write/ReadWrite/Close]
timeout[in] new timeout value to set (kDefaultTimeout is not accepted)
See also
SOCK_Read, SOCK_Write, SOCK_Close

Definition at line 7194 of file ncbi_socket.c.

References assert, SOCK_tag::c_tv, SOCK_tag::c_tv_set, CORE_LOGF_X, eIO_Close, eIO_InvalidArg, eIO_Read, eIO_ReadWrite, eIO_Success, eIO_Write, eLOG_Error, kDefaultTimeout, MAXIDLEN, SOCK_tag::r_tv, SOCK_tag::r_tv_set, s_ID(), s_to2tv(), SOCK_tag::w_tv, and SOCK_tag::w_tv_set.

Referenced by CUNIXSocket::Connect(), CSocket::Connect(), CORE_SendMailEx(), CSocket::Reset(), s_ConnectAndSend(), s_DropConnection(), s_FTPExecute(), s_PreRead(), s_ReadHeader(), s_VT_Close(), s_VT_Open(), s_VT_Read(), s_VT_Write(), CSocket::SetTimeout(), URL_ConnectEx(), x_Close(), x_DrainData(), x_FTPAbort(), x_FTPCloseCntl(), x_FTPCloseData(), x_FTPCompleteUpload(), x_FTPPollCntl(), and x_FTPSyncCntl().

◆ SOCK_SetupSSL()

void SOCK_SetupSSL ( FSSLSetup  setup)

Store SSL setup callback until actual initialization.

Parameters
setupnon-NULL SSL setup routine, or NULL to shut the SSL down
Warning
Do _not_ use this function unless you know what you're doing. Use other means of initialization such as CONNECT_Init() or CConnIniter.
See also
SOCK_SetupSSLEx, CONNECT_Init, CConnIniter

Definition at line 8998 of file ncbi_socket.c.

References setup(), and SOCK_SetupSSLInternal().

Referenced by s_Fini().

◆ SOCK_SetupSSLEx()

EIO_Status SOCK_SetupSSLEx ( FSSLSetup  setup)

Take SSL setup callback, and then init the entire API (SOCK + SSL).

Parameters
setupnon-NULL SSL setup routine, or NULL to shut the SSL down
Returns
eIO_Success if successful, other code on error.
Warning
Do _not_ use this function unless you know what you're doing. Use other means of initialization such as CONNECT_Init() or CConnIniter.
See also
SOCK_SetupSSL, CONNECT_Init, CConnIniter

Definition at line 9011 of file ncbi_socket.c.

References setup(), and SOCK_SetupSSLInternalEx().

◆ SOCK_Shutdown()

EIO_Status SOCK_Shutdown ( SOCK  sock,
EIO_Event  how 
)

Shutdown the connection in only one direction (specified by "direction").

Later attempts to I/O (or to wait) in the shutdown direction will do nothing, and immediately return with "eIO_Closed" status. Pending data output can cause data transfer to the remote end (subject for eIO_Close timeout as previously set by SOCK_SetTimeout()). Cannot be applied to datagram sockets (eIO_InvalidArg results).

Parameters
sock[in] handle of the socket to shutdown
how[in] one of: eIO_Read, eIO_Write, eIO_ReadWrite
See also
SOCK_SetTimeout

Definition at line 6797 of file ncbi_socket.c.

References assert, CORE_LOGF_X, eIO_Close, eIO_InvalidArg, eIO_ReadWrite, eIO_Success, eLOG_Error, eSOCK_Datagram, eSOCK_ErrIO, SOCK_tag::host, info, MAXIDLEN, SOCK_tag::path, SOCK_tag::port, s_ErrHook, s_ErrorCallback(), s_ID(), s_Shutdown(), SOCK_tag::sock, SOCK_GET_TIMEOUT, SOCK_INVALID, SOCK_ntoa(), and SOCK_tag::type.

Referenced by CSocket::Shutdown().

◆ SOCK_ShutdownAPI()

EIO_Status SOCK_ShutdownAPI ( void  )

Cleanup; destroy all internal/system data & resources used by the SOCK API.

Attention
No function from the SOCK API should be called after this call!
Note
You can safely call it more than once; just, all calls after the first one will have no effect.
Warning
Once the API has been shut down with this call, it cannot be reactivated with SOCK_InitializeAPI() – it will always return eIO_NotSupported.
See also
SOCK_InitializeAPI

Definition at line 1019 of file ncbi_socket.c.

References CORE_LOCK_WRITE, CORE_LOG_ERRNO_EXX, CORE_TRACE, CORE_UNLOCK, eIO_NotSupported, eIO_Success, eLOG_Warning, s_Initialized, SOCK_ERRNO, SOCK_STRERROR, UTIL_ReleaseBuffer, and x_ShutdownSSL().

Referenced by CId2FetchApp::Exit(), s_Init(), and CSocketAPI::Shutdown().

◆ SOCK_SSLName()

const char* SOCK_SSLName ( void  )

Return an SSL provider name (in a const static storage), with special considerations: return NULL if SSL has not been set up (yet), and return "" if SSL has not been (properly) initialized for use.

Note
"NONE" is returned as a name if SSL has been explicitly disabled.
See also
SOCK_SetupSSL, SOCK_SetupSSLEx

Definition at line 9017 of file ncbi_socket.c.

References SOCKSSL_struct::Name, s_SSL, and s_SSLSetup.

Referenced by NcbiCreateTlsCertCredentials().

◆ SOCK_Status()

EIO_Status SOCK_Status ( SOCK  sock,
EIO_Event  direction 
)

Return low-level socket I/O status of *last* socket operation.

This call does not perform any I/O or socket-related system calls.

Parameters
sock[in] socket handle
direction[in] one of: eIO_Open, eIO_Read, eIO_Write
Returns
  • eIO_Closed - if either the connection has been closed / shut down (in corresponding direction for eIO_Read or eIO_Write), or the socket does not exist (for eIO_Open);
  • eIO_Timeout - if connection request has been submitted but not completed (i.e. it was still pending during last I/O);
  • eIO_Interrupt - if last data I/O was interrupted by a signal (applicable only to eIO_Read or eIO_Write);
  • eIO_Unknown - if an error has been detected during last data I/O (applicable only to eIO_Read or eIO_Write);
  • eIO_InvalidArg - if "direction" is not one of the allowed above;
  • eIO_Success - otherwise.
Note
eIO_Open merely checks whether the socket still exists (i.e. open as a system object), and that SOCK_CloseEx() has not been called on it.
SOCK_Read(eIO_ReadPeek) and SOCK_Wait(eIO_Read) will not return any error as long as there is unread buffered data left. Thus, when you are "peeking" data (instead of reading it out), then the only "non-destructive" way to check whether an EOF or an error has actually occurred, it is to use this call.

Definition at line 7459 of file ncbi_socket.c.

References SOCK_tag::connected, eIO_InvalidArg, eIO_Open, eIO_Read, eIO_Success, eIO_Timeout, eIO_Unknown, eIO_Write, SOCK_tag::eof, eSOCK_Socket, SOCK_tag::pending, SOCK_tag::r_status, SOCK_tag::sock, SOCK_INVALID, SOCK_tag::type, and SOCK_tag::w_status.

Referenced by CUNIXSocket::Connect(), CSocket::Connect(), CSocket::GetStatus(), s_Read(), s_VT_Status(), s_VT_Wait(), x_FTPAbort(), x_FTPParseReply(), and x_RetryStatus().

◆ SOCK_StringToHostPort()

const char* SOCK_StringToHostPort ( const char *  str,
unsigned int host,
unsigned short *  port 
)

Read (skipping leading blanks) "[host][:port]" from a string stopping at either EOL or a blank character.

Parameters
strmust not be NULL
hostmay be NULL for no assignment
portmay be NULL for no assignment
Returns
On success, return the advanced pointer past the host/port read. If no host/port detected, return 'str'. On format error, return 0. If either host or port fragment is missing, then the corresponding 'host'/ 'port' parameters get a value of 0.
Note
"0.0.0.0" for the host part gets the host returned as 0 as well.
'host' gets returned in network byte order, unlike 'port', which always comes out in host (native) byte order.
":0" is accepted to denote no-host:zero-port.
See also
SOCK_HostPortToString, SOCK_isip, SOCK_gethostbyname

Definition at line 8901 of file ncbi_socket.c.

References SOCK_StringToHostPortEx(), and str().

Referenced by CDatagramSocket::Connect(), CSocket::Connect(), CSocket::CSocket(), DBLB_GetServer(), and CSocketAPI::StringToHostPort().

◆ SOCK_Wait()

EIO_Status SOCK_Wait ( SOCK  sock,
EIO_Event  event,
const STimeout timeout 
)

Block on the socket until either the specified "event" is available or "timeout" expires (if "timeout" is NULL then assume it infinite).

eIO_Open (as "event") can be used to check whether the socket has been connected. When eIO_Read is requested as an "event" for a datagram socket, then eIO_Closed results if the internally latched message has been entirely read out. Either of eIO_Open, eIO_Write and eIO_ReadWrite always succeeds immediately for a datagram socket.

Parameters
sock[in] socket handle
event[in] one of: eIO_Open, eIO_Read, eIO_Write, eIO_ReadWrite
timeout[in] maximal time to wait for the event to occur (not kDefaultTimeout!)
Returns
eIO_Closed – if the socket has been closed (in the specified direction when a read/write "event" requested); eIO_Success – if the socket is ready; eIO_Unknown – if partially closed with eIO_Open requested, or an I/O error occurred; eIO_Timeout – if socket is not ready for the "event" and the allotted timeout has expired (for eIO_Open means the socket is still connecting); eIO_Interrupt – if the call had been interrupted by a signal before any other verifiable status was available; eIO_InvalidArg – if the "event" is not one of those mentioned above.
Note
It is allowed to use a non-NULL zeroed STimeout to poll on the socket for the immediately available event and return it (or eIO_Timeout, otherwise) without blocking.
See also
SOCK_Poll, POLLABLE_Poll

Definition at line 6953 of file ncbi_socket.c.

References assert, BUF_Size(), SOCK_tag::connected, CORE_LOGF_X, eIO_InvalidArg, eIO_Open, eIO_Read, eIO_ReadWrite, eIO_Success, eIO_Timeout, eIO_Unknown, eIO_Write, eLOG_Error, eLOG_Warning, SOCK_tag::eof, eSOCK_Datagram, eSOCK_ErrIO, eSOCK_Socket, SOCK_tag::host, info, kDefaultTimeout, MAXIDLEN, SOCK_tag::path, SOCK_tag::pending, SOCK_tag::port, SOCK_tag::r_buf, SOCK_tag::r_status, s_ErrHook, s_ErrorCallback(), s_ID(), s_to2tv(), s_Wait(), s_WaitConnected(), SOCK_tag::sock, SOCK_INVALID, SOCK_ntoa(), SOCK_tag::type, and SOCK_tag::w_status.

Referenced by CORE_SendMailEx(), s_VT_Wait(), CSocket::Wait(), and x_FTPPollCntl().

◆ SOCK_Write()

EIO_Status SOCK_Write ( SOCK  sock,
const void *  data,
size_t  size,
size_t *  n_written,
EIO_WriteMethod  how 
)

Write "size" bytes of "data" to "sock".

Parameters
sock[in] socket handle
data[in] data to write to the socket
size[in] # of bytes (starting at "data") to write
n_written[out] # of written bytes (can be NULL)
how[in] either eIO_WritePlain or eIO_WritePersist
Returns
In "*n_written", return the number of bytes actually written. eIO_WritePlain – write as many bytes as possible at once and return immediately; if no bytes can be written then wait at most WRITE timeout, try again and return. eIO_WritePersist – write all data (doing an internal retry loop if necessary); if any single write attempt times out or fails then stop writing and return (error code). Return status: eIO_Success – some bytes were written successfully [Plain] – all bytes were written successfully [Persist] other code denotes an error, but some bytes might have been sent nevertheless (always check "*n_written" to know).
Note
With eIO_WritePlain the call returns eIO_Success if and only if some data were actually written to the socket. If no data could be written (and perhaps timeout expired) this call always returns an error.
eIO_WritePlain and eIO_WritePersist differ that the latter can flag an error condition even if some data were actually written (see "the rule of thumb" in the comments for SOCK_Read() above).
If "size"==0, return value can be eIO_Success if no pending data left in the socket, or eIO_Timeout if there are still data pending. In either case, "*n_written" is set to 0 on return.
See also
SOCK_SetTimeout

Definition at line 7486 of file ncbi_socket.c.

References assert, CORE_LOGF_X, data, eIO_InvalidArg, eIO_NotSupported, eIO_Success, eIO_WriteOutOfBand, eIO_WritePersist, eIO_WritePlain, eLOG_Error, eSOCK_Datagram, MAXIDLEN, s_ID(), s_Write(), ncbi::grid::netcache::search::fields::size, SOCK_tag::sock, SOCK_INVALID, and SOCK_tag::type.

Referenced by s_ConnectAndSend(), s_FTPCommandEx(), s_SockWrite(), s_VT_Write(), CSocket::Write(), x_FTPTelnetSynch(), and x_WriteBuf().

◆ SPoll()

CSocketAPI::SPoll::SPoll ( CPollable pollable = 0,
EIO_Event  event = eIO_Open 
)
inline

Definition at line 767 of file ncbi_socket.hpp.

◆ StringToHostPort()

SIZE_TYPE CSocketAPI::StringToHostPort ( const string str,
unsigned int host,
unsigned short *  port 
)
static

Return position past the end of the parsed portion, NPOS on error.

Definition at line 694 of file ncbi_socket_cxx.cpp.

References NPOS, SOCK_StringToHostPort(), and str().

Referenced by COSGServiceMapper::GetServersList(), NcbiOpenURL(), and CConnTest::x_GetFirewallConfiguration().

◆ TRIGGER_Close()

EIO_Status TRIGGER_Close ( TRIGGER  trigger)

Close an event trigger.

Parameters
trigger[in] a handle returned by TRIGGER_Create()
Returns
eIO_Success on success; other status on error
See also
TRIGGER_Create

Definition at line 6341 of file ncbi_socket.c.

References close(), CORE_LOGF_X, eDefault, eIO_InvalidArg, eIO_NotSupported, eIO_Success, eLOG_Note, eOn, TRIGGER_tag::fd, free(), TRIGGER_tag::id, TRIGGER_tag::log, TRIGGER_tag::out, and s_Log.

Referenced by CTrigger::~CTrigger().

◆ TRIGGER_Create()

EIO_Status TRIGGER_Create ( TRIGGER trigger,
ESwitch  log 
)

Create an event trigger.

Parameters
trigger[in|out] a pointer to a location where to store handle of the new trigger
Returns
eIO_Success on success; other status on error
See also
TRIGGER_Close, TRIGGER_Set

Definition at line 6180 of file ncbi_socket.c.

References assert, calloc(), close(), CORE_LOGF_ERRNO_EXX, CORE_LOGF_ERRNO_X, CORE_LOGF_X, eDefault, eIO_InvalidArg, eIO_NotSupported, eIO_Success, eIO_Unknown, eLOG_Error, eLOG_Note, eLOG_Warning, eOn, eSOCK_Trigger, FD_SETSIZE, HANDLE, log, s_InitAPI(), s_Log, s_SetCloexec(), s_SetNonblock(), s_WinStrerror(), UTIL_ReleaseBufferOnHeap(), and x_ID_Counter().

Referenced by CTrigger::CTrigger().

◆ TRIGGER_IsSet()

EIO_Status TRIGGER_IsSet ( TRIGGER  trigger)

Check whether the trigger has been set.

Should not be used from multiple threads concurrently at a time, including along with TRIGGER_Reset().

Parameters
trigger[in] a handle returned by TRIGGER_Create()
Returns
eIO_Success if the trigger has been set; eIO_Closed if the trigger has not yet been set; other status on error
See also
TRIGGER_Create, TRIGGER_Set, TRIGGER_Reset

Definition at line 6452 of file ncbi_socket.c.

References eIO_InvalidArg, eIO_Success, eIO_Timeout, TRIGGER_tag::isset, TRIGGER_tag::ptr, and x_TriggerRead().

Referenced by CTrigger::IsSet().

◆ TRIGGER_Reset()

EIO_Status TRIGGER_Reset ( TRIGGER  trigger)

Reset the trigger.

Should not be used from multiple threads concurrently, including along with TRIGGER_IsSet().

Parameters
trigger[in] a handle returned by TRIGGER_Create()
Returns
eIO_Success if the trigger has been reset; other status on error
See also
TRIGGER_Create, TRIGGER_Set, TRIGGER_IsSet

Definition at line 6477 of file ncbi_socket.c.

References eIO_InvalidArg, eIO_Success, eIO_Timeout, eIO_Unknown, TRIGGER_tag::fd, TRIGGER_tag::isset, TRIGGER_tag::ptr, and x_TriggerRead().

Referenced by CTrigger::Reset().

◆ TRIGGER_Set()

EIO_Status TRIGGER_Set ( TRIGGER  trigger)

Set an event trigger.

Can be used from many threads concurrently.

Parameters
trigger[in] a handle returned by TRIGGER_Create()
Returns
eIO_Success on success; other status on error
See also
TRIGGER_Create, TRIGGER_IsSet

Definition at line 6377 of file ncbi_socket.c.

References CORE_Once, eIO_InvalidArg, eIO_NotSupported, eIO_Success, eIO_Unknown, TRIGGER_tag::fd, TRIGGER_tag::isset, TRIGGER_tag::out, and TRIGGER_tag::ptr.

Referenced by CTrigger::Set().

◆ Wait() [1/2]

EIO_Status CDatagramSocket::Wait ( const STimeout timeout = kInfiniteTimeout)
inline

◆ Wait() [2/2]

EIO_Status CSocket::Wait ( EIO_Event  event,
const STimeout timeout 
)
inline

Wait for I/O availability in the socket.

Note
Use CSocketAPI::Poll() to wait for multiple sockets at once.
Parameters
eventeither of eIO_Read, eIO_Write or eIO_ReadWrite
timeoutmaximal time to wait for I/O to become ready
See also
SOCK_Wait

Definition at line 902 of file ncbi_socket.hpp.

References CSocket::m_Socket, and SOCK_Wait().

◆ Write()

EIO_Status CSocket::Write ( const void *  buf,
size_t  size,
size_t *  n_written = 0,
EIO_WriteMethod  how = eIO_WritePersist 
)

◆ ~CListeningSocket()

CListeningSocket::~CListeningSocket ( void  )
virtual

Call Close(), then self-destruct.

Definition at line 520 of file ncbi_socket_cxx.cpp.

References CListeningSocket::Close().

◆ ~CPollable()

virtual CPollable::~CPollable ( )
inlinevirtual

Definition at line 67 of file ncbi_socket.hpp.

◆ ~CSocket()

CSocket::~CSocket ( void  )
virtual

Call Close(), then self-destruct.

Definition at line 137 of file ncbi_socket_cxx.cpp.

References eNoOwnership, CSocket::m_IsOwned, CSocket::m_Socket, and SOCK_Close().

◆ ~CTrigger()

CTrigger::~CTrigger ( )
virtual

Definition at line 50 of file ncbi_socket_cxx.cpp.

References CTrigger::m_Trigger, and TRIGGER_Close().

Variable Documentation

◆ addr

unsigned int SSOCK_ApproveInfo::addr

IPv4 (or -1 if unknown / broadcast), never 0.

Definition at line 345 of file ncbi_socket.h.

◆ c_timeout

STimeout* CSocket::c_timeout
protected

◆ cc_timeout

STimeout CSocket::cc_timeout
protected

storage for c_timeout

Definition at line 514 of file ncbi_socket.hpp.

Referenced by CSocket::Reset(), and CSocket::SetTimeout().

◆ event [1/3]

EIO_Event SSOCK_Poll::event

[in] SOCK to poll (NULL if not to poll)

Definition at line 968 of file ncbi_socket.h.

Referenced by s_Select(), and SOCK_Poll().

◆ event [2/3]

EIO_Event SSOCK_ErrInfo::event

Meaningful only for the eSOCK_ErrIO type.

Definition at line 1955 of file ncbi_socket.h.

◆ event [3/3]

EIO_Event SPOLLABLE_Poll::event

Definition at line 1980 of file ncbi_socket.h.

Referenced by CSocketAPI::Poll().

◆ host [1/2]

const char* SSOCK_ApproveInfo::host

Textual hostname if provided for outgoing.

Definition at line 344 of file ncbi_socket.h.

◆ host [2/2]

const char* SSOCK_ErrInfo::host

Host name/IP (or path for non-IP SOCK)

Definition at line 1953 of file ncbi_socket.h.

◆ m_Event

EIO_Event CSocketAPI::SPoll::m_Event

[in] event inqury (or eIO_Open for none)

Definition at line 764 of file ncbi_socket.hpp.

◆ m_IsOwned [1/2]

EOwnership CSocket::m_IsOwned
protected

◆ m_IsOwned [2/2]

EOwnership CListeningSocket::m_IsOwned
protected

Definition at line 711 of file ncbi_socket.hpp.

Referenced by CListeningSocket::Close(), and CListeningSocket::SetOwnership().

◆ m_Pollable

CPollable* CSocketAPI::SPoll::m_Pollable

[in] object pointer (or NULL not to poll)

Definition at line 763 of file ncbi_socket.hpp.

◆ m_REvent

EIO_Event CSocketAPI::SPoll::m_REvent

[out] event ready (eIO_Open if not ready)

Definition at line 765 of file ncbi_socket.hpp.

◆ m_Socket [1/2]

SOCK CSocket::m_Socket
protected

◆ m_Socket [2/2]

LSOCK CListeningSocket::m_Socket
protected

◆ m_Trigger

TRIGGER CTrigger::m_Trigger
protected

◆ o_timeout

STimeout* CSocket::o_timeout
protected

◆ oo_timeout

STimeout CSocket::oo_timeout
protected

◆ poll

POLLABLE SPOLLABLE_Poll::poll

Definition at line 1979 of file ncbi_socket.h.

Referenced by CSocketAPI::Poll().

◆ port [1/2]

unsigned short SSOCK_ApproveInfo::port

Port number, host byte order, never 0.

Definition at line 346 of file ncbi_socket.h.

◆ port [2/2]

unsigned short SSOCK_ErrInfo::port

Port (host byte order), 0 for non-IP SOCK.

Definition at line 1954 of file ncbi_socket.h.

◆ r_timeout

STimeout* CSocket::r_timeout
protected

◆ revent [1/2]

EIO_Event SSOCK_Poll::revent

[in] one of: eIO_Open/Read/Write/ReadWrite

Definition at line 969 of file ncbi_socket.h.

Referenced by SNetServerInPool::GetConnectionFromPool(), s_Select(), s_SelectStallsafe(), and SOCK_Poll().

◆ revent [2/2]

EIO_Event SPOLLABLE_Poll::revent

Definition at line 1981 of file ncbi_socket.h.

Referenced by CSocketAPI::Poll().

◆ rr_timeout

STimeout CSocket::rr_timeout
protected

storage for r_timeout

Definition at line 510 of file ncbi_socket.hpp.

Referenced by CSocket::Reset(), and CSocket::SetTimeout().

◆ side

ESOCK_Side SSOCK_ApproveInfo::side

eSOCK_Client (out) / eSOCK_Server (in)

Definition at line 347 of file ncbi_socket.h.

◆ sock [1/2]

SOCK SSOCK_Poll::sock

Definition at line 967 of file ncbi_socket.h.

Referenced by s_Select(), and s_SelectStallsafe().

◆ sock [2/2]

SOCK SSOCK_ErrInfo::sock

Non-NULL when SOCK-related.

Definition at line 1952 of file ncbi_socket.h.

◆ status

EIO_Status SSOCK_ErrInfo::status

Status code about to be returned (if known)

Definition at line 1956 of file ncbi_socket.h.

◆ type [1/2]

ESOCK_Type SSOCK_ApproveInfo::type

eSOCK_Socket (conn) / eSOCK_Datagram (packet)

Definition at line 348 of file ncbi_socket.h.

◆ type [2/2]

ESOCK_ErrType SSOCK_ErrInfo::type

See ESOCK_ErrType.

Definition at line 1951 of file ncbi_socket.h.

◆ w_timeout

STimeout* CSocket::w_timeout
protected

◆ ww_timeout

STimeout CSocket::ww_timeout
protected

storage for w_timeout

Definition at line 512 of file ncbi_socket.hpp.

Referenced by CSocket::Reset(), and CSocket::SetTimeout().

Modified on Fri Apr 12 17:23:27 2024 by modify_doxy.py rev. 669887