1 #ifndef CONNECT___NCBI_SOCKET__H
2 #define CONNECT___NCBI_SOCKET__H
527 (
unsigned short port,
528 unsigned short backlog,
549 (
unsigned short port,
550 unsigned short backlog,
875 #define SOCK_Destroy(s) SOCK_Close(s)
1350 unsigned short* port,
1651 unsigned short port,
1681 unsigned int* sender_addr,
1682 unsigned short* sender_port
1975 struct SPOLLABLE_tag;
2096 #define SOCK_NetToHostLong SOCK_HostToNetLong
2103 (
unsigned short value
2106 #define SOCK_NetToHostShort SOCK_HostToNetShort
2110 #ifndef NCBI_DEPRECATED
2111 # define NCBI_SOCK_DEPRECATED
2113 # define NCBI_SOCK_DEPRECATED NCBI_DEPRECATED
2117 #define SOCK_ntohl SOCK_htonl
2120 #define SOCK_ntohs SOCK_htons
2170 (
const char* hostname,
2180 (
const char* hostname
2265 unsigned short* port
2289 unsigned short port,
static const char * str(char *buf, int n)
TRIGGER POLLABLE_ToTRIGGER(POLLABLE)
struct SNcbiCred * NCBI_CRED
Opaque type for credentials.
LSOCK POLLABLE_ToLSOCK(POLLABLE)
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 charac...
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).
char * SOCK_GetPeerAddressStringEx(SOCK sock, char *buf, size_t bufsize, ESOCK_AddressFormat format)
int SOCK_isipEx(const char *host, int fullquad)
Check whether the given string represents a valid IPv4 address.
ESwitch SOCK_SetReadOnWrite(SOCK sock, ESwitch on_off)
Control the reading-while-writing feature for socket "sock" individually.
EIO_Status TRIGGER_Set(TRIGGER trigger)
Set an event trigger.
int SOCK_IsSecure(SOCK sock)
Check whether a socket is using SSL (Secure Socket Layer).
EIO_Status SOCK_SetTimeout(SOCK sock, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()).
void SOCK_DisableOSSendDelay(SOCK sock, int on_off)
Control OS-defined send strategy by disabling/enabling the TCP Nagle algorithm (which is on by defaul...
unsigned short port
Port (host byte order), 0 for non-IP SOCK.
unsigned int SOCK_HostToNetLong(unsigned int value)
See man for the BSDisms, htonl() and htons().
EIO_Status SOCK_Shutdown(SOCK sock, EIO_Event how)
Shutdown the connection in only one direction (specified by "direction").
unsigned short SOCK_GetRemotePort(SOCK sock, ENH_ByteOrder byte_order)
Get remote port of the socket (the port it is connected to).
EIO_Event event
[in] SOCK to poll (NULL if not to poll)
EIO_Status SOCK_Close(SOCK sock)
Close the SOCK handle, and destroy all relevant internal data.
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...
EIO_Status DSOCK_SetBroadcast(SOCK sock, int broadcast)
Set a datagram socket for broadcast.
EIO_Status LSOCK_Accept(LSOCK lsock, const STimeout *timeout, SOCK *sock)
[SERVER-side] Accept connection from a client.
ESOCK_AddressFormat
Get textual representation of the socket's peer.
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.
void(* FSOCK_ErrHook)(const SSOCK_ErrInfo *info, void *data)
const char * SOCK_SSLName(void)
Return an SSL provider name (in a const static storage), with special considerations: return NULL if ...
EIO_Status DSOCK_Connect(SOCK sock, const char *host, unsigned short port)
Associate a datagram socket with a destination address.
ESwitch SOCK_SetReuseAddressAPI(ESwitch on_off)
Control address reuse for socket addresses taken by the API.
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".
ESwitch SOCK_SetInterruptOnSignal(SOCK sock, ESwitch on_off)
Control restartability of I/O interrupted by signals on a per-socket basis.
EIO_Status SOCK_Status(SOCK sock, EIO_Event direction)
Return low-level socket I/O status of *last* socket operation.
EIO_Status SOCK_CloseOSHandle(const void *handle, size_t handle_size)
Close socket OS handle (ungracefully aborting the connection if necessary).
unsigned int SOCK_gethostbynameEx(const char *hostname, ESwitch log)
Find and return IPv4 address of a named host.
EIO_Status POLLABLE_Poll(size_t n, SPOLLABLE_Poll polls[], const STimeout *timeout, size_t *n_ready)
Poll for I/O readiness.
EIO_Status TRIGGER_Reset(TRIGGER trigger)
Reset the trigger.
EIO_Status SOCK_InitializeAPI(void)
Initialize all internal/system data & resources to be used by the SOCK API.
#define NCBI_SOCK_DEPRECATED
unsigned int SOCK_htonl(unsigned int)
int SOCK_gethostname(char *name, size_t namelen)
Same as SOCK_gethostnameEx(,,<current API data logging>)
unsigned short port
Port number, host byte order, never 0.
void SOCK_SetupSSL(FSSLSetup setup)
Store SSL setup callback until actual initialization.
POLLABLE POLLABLE_FromSOCK(SOCK)
Conversion utilities from handles to POLLABLEs, and back.
void SOCK_SetCork(SOCK sock, int on_off)
Control OS-defined send strategy by disabling/enabling the TCP layer to send incomplete network frame...
void SOCK_AllowSigPipeAPI(void)
By default (on UNIX platforms) the SOCK API functions automagically call "signal(SIGPIPE,...
ENH_ByteOrder
Network and host byte order enumeration type.
ESOCK_Type POLLABLE_What(POLLABLE)
Identifies a non-NULL POLLABLE.
EIO_Status SOCK_CloseEx(SOCK sock, int destroy)
Close the SOCK handle, and conditionally destroy relevant internal data.
void SOCK_SetApproveHookAPI(FSOCK_ApproveHook hook, void *data)
The hook is installed when non-NULL, and de-installed otherwise.
ESOCK_IOWaitSysAPI SOCK_SetIOWaitSysAPI(ESOCK_IOWaitSysAPI api)
This is a helper call that can improve I/O performance (ignored for MSVC).
unsigned int SOCK_GetLoopbackAddress(void)
Get loopback IPv4 address.
int SOCK_IsServerSide(SOCK sock)
Check whether a socket is server-side.
unsigned short SOCK_HostToNetShort(unsigned short value)
See man for the BSDisms, htonl() and htons().
ESOCK_Side
Sides of socket.
ESOCK_Type type
eSOCK_Socket (conn) / eSOCK_Datagram (packet)
int SOCK_IsLoopbackAddress(unsigned int ip)
Check whether an address is a loopback one.
TNCBI_BigCount SOCK_GetPosition(SOCK sock, EIO_Event direction)
Get current read or write position within a socket.
unsigned int SOCK_gethostbyname(const char *hostname)
Same as SOCK_gethostbynameEx(,<current API data logging>)
void SOCK_SetErrHookAPI(FSOCK_ErrHook hook, void *data)
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).
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...
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() [+ selec...
ESwitch SOCK_SetDataLoggingAPI(ESwitch log)
By default data are not logged.
EIO_Status SOCK_Abort(SOCK sock)
If there is outstanding connection or output data pending, cancel it.
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.
EIO_Status LSOCK_AcceptEx(LSOCK lsock, const STimeout *timeout, SOCK *sock, TSOCK_Flags flags)
[SERVER-side] Accept connection from a client.
int SOCK_ntoa(unsigned int addr, char *buf, size_t bufsize)
Convert IP address to a string in dotted notation.
EIO_Status TRIGGER_Create(TRIGGER *trigger, ESwitch log)
Create an event trigger.
ESwitch SOCK_SetReadOnWriteAPI(ESwitch on_off)
By default, sockets will not try to read data from inside SOCK_Write().
ESOCK_IOWaitSysAPI
Selector of I/O wait system API: auto, poll(), or select().
EIO_Status DSOCK_Create(SOCK *sock)
Same as DSOCK_CreateEx(, fSOCK_LogDefault)
unsigned int SOCK_GetLocalHostAddress(ESwitch reget)
Get (and cache for faster follow-up retrievals) IPv4 address of local host.
const struct SOCKSSL_struct * SOCKSSL
Opaque type for SSL implementation.
EIO_Status TRIGGER_Close(TRIGGER trigger)
Close an event trigger.
EIO_Status SOCK_ReadLine(SOCK sock, char *line, size_t size, size_t *n_read)
Read a line from SOCK.
int SOCK_IsDatagram(SOCK sock)
Check whether a socket is a datagram one.
EIO_Status LSOCK_GetOSHandle(LSOCK lsock, void *handle_buf, size_t handle_size)
Same as LSOCK_GetOSHandleEx(lsock, handle_buf, handle_size, eNoOwnership).
const char * host
Textual hostname if provided for outgoing.
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".
EIO_Status DSOCK_WaitMsg(SOCK sock, const STimeout *timeout)
Wait for a datagram in a datagram socket.
TNCBI_BigCount SOCK_GetTotalCount(SOCK sock, EIO_Event direction)
Get the total volume of data transferred by a socket.
unsigned int addr
IPv4 (or -1 if unknown / broadcast), never 0.
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...
const char * host
Host name/IP (or path for non-IP SOCK)
int SOCK_gethostnameEx(char *name, size_t namelen, ESwitch log)
Get the local host name.
int SOCK_IsClientSide(SOCK sock)
Check whether a socket is client-side.
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.
ESOCK_ErrType
User-level error hook.
SOCK sock
Non-NULL when SOCK-related.
char * SOCK_GetPeerAddressString(SOCK sock, char *buf, size_t bufsize)
Equivalent to SOCK_GetPeerAddressStringEx(.,.,.,eSAF_Full)
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())
ESOCK_ErrType type
See ESOCK_ErrType.
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.
struct TRIGGER_tag * TRIGGER
EIO_Status TRIGGER_IsSet(TRIGGER trigger)
Check whether the trigger has been set.
unsigned short SOCK_htons(unsigned short)
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 buffe...
int SOCK_IsUNIX(SOCK sock)
Check whether a socket is UNIX type.
EIO_Status SOCK_SetupSSLEx(FSSLSetup setup)
Take SSL setup callback, and then init the entire API (SOCK + SSL).
TNCBI_BigCount DSOCK_GetMessageCount(SOCK sock, EIO_Event direction)
Get message count.
EIO_Status SOCK_ShutdownAPI(void)
Cleanup; destroy all internal/system data & resources used by the SOCK API.
ESwitch SOCK_SetDataLogging(SOCK sock, ESwitch log)
Control the data logging for socket "sock" individually.
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 ...
EIO_Status DSOCK_CreateEx(SOCK *sock, TSOCK_Flags flags)
Create a datagram socket.
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...
unsigned short LSOCK_GetPort(LSOCK lsock, ENH_ByteOrder byte_order)
Get socket port number, which it listens on.
POLLABLE POLLABLE_FromLSOCK(LSOCK)
EIO_Status DSOCK_Bind(SOCK sock, unsigned short port)
Assosiate a datagram socket with a local port.
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() [+ selec...
POLLABLE POLLABLE_FromTRIGGER(TRIGGER)
size_t SOCK_OSHandleSize(void)
Get size of OS-dependent native socket handle.
EIO_Status LSOCK_Close(LSOCK lsock)
[SERVER-side] Close the listening socket, destroy relevant internal data.
struct SPOLLABLE_tag * POLLABLE
EIO_Status SOCK_CreateOnTop(const void *handle, size_t handle_size, SOCK *sock)
[SERVER-side] Create a socket on top of a "handle".
ESwitch SOCK_SetInterruptOnSignalAPI(ESwitch on_off)
Control restartability of I/O interrupted by signals.
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,...
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...
EIO_Status DSOCK_WipeMsg(SOCK sock, EIO_Event direction)
Clear message froma datagram socket.
TNCBI_BigCount SOCK_GetCount(SOCK sock, EIO_Event direction)
Get counts of read or written bytes.
const STimeout * SOCK_GetTimeout(SOCK sock, EIO_Event event)
Get the connection's i/o timeout (or NULL, if the timeout is infinite).
EIO_Event event
Meaningful only for the eSOCK_ErrIO type.
EIO_Event revent
[in] one of: eIO_Open/Read/Write/ReadWrite
ESOCK_Side side
eSOCK_Client (out) / eSOCK_Server (in)
const char * SOCK_gethostbyaddr(unsigned int addr, char *name, size_t namelen)
Same as SOCK_gethostbyaddrEx(,,<current API data logging>)
EIO_Status status
Status code about to be returned (if known)
int SOCK_isip(const char *host)
Equivalent of SOCK_isip(host, 0)
const STimeout * SOCK_SetSelectInternalRestartTimeout(const STimeout *timeslice)
This is a helper call that can improve I/O behavior.
ESOCK_Type
Socket type (internal)
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 ...
SOCKSSL(* FSSLSetup)(void)
SSL setup callback.
SOCK POLLABLE_ToSOCK(POLLABLE)
unsigned short SOCK_GetLocalPort(SOCK sock, ENH_ByteOrder byte_order)
Get local port of the socket.
unsigned short SOCK_GetLocalPortEx(SOCK sock, int trueport, ENH_ByteOrder byte_order)
Get local port of the socket (true or cached / stored).
unsigned int TSOCK_Flags
bitwise "OR" of ESOCK_Flags
EIO_Status SOCK_GetOSHandle(SOCK sock, void *handle_buf, size_t handle_size)
Same as SOCK_GetOSHandleEx(sock, handle_buf, handle_size, eNoOwnership).
@ eSAF_IP
only numeric IP if INET socket, empty otherwise
@ eSAF_Full
address in full, native form
@ eSAF_Port
only numeric port if INET socket, empty otherwise
@ eSOCK_IOWaitSysAPISelect
always use select()
@ eSOCK_IOWaitSysAPIAuto
default; use some heuristics to choose API
@ eSOCK_IOWaitSysAPIPoll
always use poll()
@ eSOCK_ErrDns
DNS-related error (unresolvable hostname)
@ eSOCK_ErrIO
I/O-related error.
@ eSOCK_ErrInit
Socket layer initialization error.
@ fSOCK_CloseOnClose
close OS handle in SOCK_Close[Ex]()
@ fSOCK_KeepAlive
keep socket alive (if supported by OS)
@ fSOCK_BindLocal
bind to 127.0.0.1 only
@ fSOCK_Secure
subsumes CloseOnExec regardless of Keep
@ fSOCK_KeepOnClose
retain OS handle in SOCK_Close[Ex]()
@ fSOCK_BindAny
bind to 0.0.0.0 (i.e.
@ fSOCK_KeepOnExec
can be applied to all sockets
@ fSOCK_CloseOnExec
can be applied to all sockets, default
@ fSOCK_LogOff
NB: logging is inherited in accepted SOCK.
@ fSOCK_InterruptOnSignal
enum ENcbiSwitch ESwitch
Aux.
EIO_ReadMethod
I/O read method.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
EIO_WriteMethod
I/O write method.
EIO_Event
I/O event (or direction).
uint64_t TNCBI_BigCount
Big unsigned integer for file size and position.
#define NCBI_XCONNECT_EXPORT
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
User-level connection approval hook.