38 #if defined(NCBI_OS_MSWIN) && !defined(PATH_MAX)
68 r_timeout(0), w_timeout(0), c_timeout(0)
83 r_timeout(0), w_timeout(0), c_timeout(0)
95 || *end || !x_host || !port
96 ||
SOCK_ntoa(x_host, host,
sizeof(host)) != 0) {
108 r_timeout(0), w_timeout(0), c_timeout(0)
116 if (
SOCK_ntoa(host, x_host,
sizeof(x_host)) != 0)
199 || *end || !x_host || !port
200 ||
SOCK_ntoa(x_host, host,
sizeof(host)) != 0) {
390 unsigned short* port,
480 *end || (x_host &&
SOCK_ntoa(x_host, host,
sizeof(host)) != 0)) {
491 unsigned short* sender_port,
506 msglen, &
addr, sender_port);
594 static const STimeout kZero = {0, 0};
595 size_t x_n = polls.size();
602 for (
size_t i = 0;
i < x_n; ++
i) {
626 polls[
i].m_REvent = revent;
637 x_ready ? &kZero : timeout, &xx_ready);
639 for (
size_t i = 0;
i < x_n; ++
i) {
640 if (x_polls[
i].revent)
641 polls[
i].m_REvent = x_polls[
i].
revent;
645 *n_ready = xx_ready + x_ready;
696 unsigned short* port)
698 const char* s =
str.c_str();
static const char * str(char *buf, int n)
@ eTakeOwnership
An object can take ownership of another.
@ eNoOwnership
No ownership is assumed.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
EIO_Status Connect(const string &filename, const STimeout *timeout=kDefaultTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
EIO_Status Connect(const string &host, unsigned short port, const STimeout *timeout=kDefaultTimeout, TSOCK_Flags flags=fSOCK_LogDefault)
Connect to "host:port".
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)
static SIZE_TYPE StringToHostPort(const string &str, unsigned int *host, unsigned short *port)
Return position past the end of the parsed portion, NPOS on error.
EIO_Status SOCK_SetTimeout(SOCK sock, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()).
static string HostPortToString(unsigned int host, unsigned short port)
See SOCK_HostPortToString()
EIO_Status Accept(CSocket *&sock, const STimeout *timeout=kInfiniteTimeout, TSOCK_Flags flags=fSOCK_LogDefault) const
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...
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.
SOCK GetSOCK(void) const
Access to the underlying "SOCK".
EIO_Status DSOCK_Connect(SOCK sock, const char *host, unsigned short port)
Associate a datagram socket with a destination address.
TRIGGER GetTRIGGER(void) const
Access to the underlying "TRIGGER".
EIO_Status 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 ReadLine(string &str)
Read a line from socket (up to CR-LF, LF, or null character, discarding any of the EOLs).
STimeout * c_timeout
eIO_Close
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".
EIO_Status SOCK_Status(SOCK sock, EIO_Event direction)
Return low-level socket I/O status of *last* socket operation.
const STimeout * GetTimeout(EIO_Event event) const
Get timeout for I/O in the specified direction.
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.
static string gethostname(ESwitch log=eOff)
Return empty string on error.
STimeout oo_timeout
storage for o_timeout
static EIO_Status Poll(vector< SPoll > &polls, const STimeout *timeout, size_t *n_ready=0)
Poll a vector of CPollable objects for I/O readiness.
POLLABLE POLLABLE_FromSOCK(SOCK)
Conversion utilities from handles to POLLABLEs, and back.
static string ntoa(unsigned int host)
BSD-like API. NB: when int, "host" must be in network byte order.
EIO_Status Connect(const string &host, unsigned short port)
ENH_ByteOrder
Network and host byte order enumeration type.
static unsigned int gethostbyname(const string &host, ESwitch log=eOff)
Return 0 on error.
EIO_Status SetTimeout(EIO_Event event, const STimeout *timeout)
Set timeout for I/O in the specified direction.
void 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 underly...
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...
EIO_Status SOCK_Abort(SOCK sock)
If there is outstanding connection or output data pending, cancel it.
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.
STimeout cc_timeout
storage for c_timeout
STimeout * r_timeout
eIO_Read
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.
EIO_Status GetStatus(EIO_Event direction) const
Return status of *last* I/O operation without making any actual I/O.
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 Reconnect(const STimeout *timeout=kDefaultTimeout)
Reconnect to the same address.
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...
void GetPeerAddress(unsigned int *host, unsigned short *port, ENH_ByteOrder byte_order) const
Get peer address.
int SOCK_gethostnameEx(char *name, size_t namelen, ESwitch log)
Get the local host name.
virtual ~CSocket(void)
Call Close(), then self-destruct.
static string gethostbyaddr(unsigned int host, ESwitch log=eOff)
Return empty string on error.
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...
STimeout * o_timeout
eIO_Open
EOwnership m_IsOwned
Timeouts.
POLLABLE POLLABLE_FromLSOCK(LSOCK)
LSOCK GetLSOCK(void) const
Access to the underlying "LSOCK".
POLLABLE POLLABLE_FromTRIGGER(TRIGGER)
STimeout ww_timeout
storage for w_timeout
EIO_Status LSOCK_Close(LSOCK lsock)
[SERVER-side] Close the listening socket, destroy relevant internal data.
const STimeout * SOCK_GetTimeout(SOCK sock, EIO_Event event)
Get the connection's i/o timeout (or NULL, if the timeout is infinite).
virtual ~CListeningSocket(void)
Call Close(), then self-destruct.
EIO_Status SOCK_CreateUNIX(const char *path, const STimeout *timeout, SOCK *sock, const void *data, size_t size, TSOCK_Flags flags)
STimeout rr_timeout
storage for r_timeout
STimeout * w_timeout
eIO_Write
EIO_Status Write(const void *buf, size_t size, size_t *n_written=0, EIO_WriteMethod how=eIO_WritePersist)
Write to socket.
unsigned int TSOCK_Flags
bitwise "OR" of ESOCK_Flags
EIO_Status Read(void *buf, size_t size, size_t *n_read=0, EIO_ReadMethod how=eIO_ReadPlain)
Read from socket.
NCBI_NS_STD::string::size_type SIZE_TYPE
enum ENcbiSwitch ESwitch
Aux.
unsigned int usec
microseconds (modulo 1,000,000)
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).
@ eIO_Success
everything is fine, no error occurred
@ eIO_Unknown
unknown I/O error (likely fatal but can retry)
@ eIO_InvalidArg
bad argument / parameter value(s) supplied
@ eIO_ReadWrite
eIO_Read | eIO_Write (also, eCONN_OnFlush)
@ eIO_Open
also serves as no-event indicator in SOCK_Poll
@ eIO_Close
also serves as an error indicator in SOCK_Poll
const struct ncbi::grid::netcache::search::fields::SIZE size