313
338
typedef unsigned int TLSCE_Flags;
315
/* [SERVER-side] Create and initialize the server-side(listening) socket
340
/** [SERVER-side] Create and initialize the server-side(listening) socket
316
341
* (socket() + bind() + listen())
317
* NOTE: on some systems, "backlog" can be silently limited down to 128 (or 5).
342
* @li <b>NOTE:</b> on some systems, "backlog" can be silently limited down to 128 (or 5).
344
* [in] the port to listen at
346
* [in] maximal # of pending connections
348
* [out] handle of the created listening socket
350
* [in] special modifiers
319
352
extern NCBI_XCONNECT_EXPORT EIO_Status LSOCK_CreateEx
320
(unsigned short port, /* [in] the port to listen at */
321
unsigned short backlog, /* [in] maximal # of pending connections */
322
LSOCK* lsock, /* [out] handle of the created listening socket */
323
TLSCE_Flags flags /* [in] special modifiers */
353
(unsigned short port,
354
unsigned short backlog,
361
* [in] the port to listen at
363
* [in] maximal # of pending connections
365
* [out] handle of the created listening socket
326
367
extern NCBI_XCONNECT_EXPORT EIO_Status LSOCK_Create
327
(unsigned short port, /* [in] the port to listen at */
328
unsigned short backlog, /* [in] maximal # of pending connections */
329
LSOCK* lsock /* [out] handle of the created listening socket */
368
(unsigned short port,
369
unsigned short backlog,
333
/* [SERVER-side] Accept connection from a client.
334
* NOTE: the "*timeout" is for this accept() only. To set I/O timeout,
374
/** [SERVER-side] Accept connection from a client.
375
* @li <b>NOTE:</b> the "*timeout" is for this accept() only. To set I/O timeout,
335
376
* use SOCK_SetTimeout(); all I/O timeouts are infinite by default.
378
* [in] handle of a listening socket
380
* [in] timeout (infinite if NULL)
382
* [out] handle of the created socket
337
384
extern NCBI_XCONNECT_EXPORT EIO_Status LSOCK_Accept
338
(LSOCK lsock, /* [in] handle of a listening socket */
339
const STimeout* timeout, /* [in] timeout (infinite if NULL) */
340
SOCK* sock /* [out] handle of the created socket */
386
const STimeout* timeout,
344
/* [SERVER-side] Close the listening socket, destroy relevant internal data.
391
/** [SERVER-side] Close the listening socket, destroy relevant internal data.
346
395
extern NCBI_XCONNECT_EXPORT EIO_Status LSOCK_Close(LSOCK lsock);
349
398
/* Get an OS-dependent native socket handle to use by platform-specific API.
350
399
* FYI: on MS-Windows it will be "SOCKET", on other platforms -- "int".
403
* Pointer to a memory area to put the socket's native OS handle at
405
* The exact(!) size of the expected OS handle
352
407
extern NCBI_XCONNECT_EXPORT EIO_Status LSOCK_GetOSHandle
354
void* handle_buf, /* pointer to a memory area to put the OS handle at */
355
size_t handle_size /* the exact(!) size of the expected OS handle */
365
/* [CLIENT-side] Connect client to another(server-side, listening) socket
420
/** [CLIENT-side] Connect client to another(server-side, listening) socket
366
421
* (socket() + connect() [+ select()])
422
* Equivalent to SOCK_CreateEx(host, port, timeout, sock, 0, 0, eDefault).
425
* [in] host to connect to
427
* [in] port to connect to
429
* [in] the connect timeout (infinite if NULL)
431
* [out] handle of the created socket
432
* @sa SOCK_CreateEx()
368
/* SOCK_CreateEx(host, port, timeout, sock, 0, 0, eDefault) */
369
434
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Create
370
(const char* host, /* [in] host to connect to */
371
unsigned short port, /* [in] port to connect to */
372
const STimeout* timeout, /* [in] the connect timeout (infinite if NULL) */
373
SOCK* sock /* [out] handle of the created socket */
437
const STimeout* timeout,
442
/** [CLIENT-side] Connect client to another(server-side, listening) socket
443
* (socket() + connect() [+ select()])
446
* [in] Host to connect to
448
* [in] port to connect to
450
* [in] the connect timeout (infinite if NULL)
452
* [out] handle of the created socket
454
* [in] initial output data segment (may be NULL)
456
* [in] size of initial data segment (may be 0)
458
* [in] whether to do logging on this socket
376
461
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_CreateEx
377
(const char* host, /* [in] host to connect to */
378
unsigned short port, /* [in] port to connect to */
379
const STimeout* timeout, /* [in] the connect timeout (infinite if NULL) */
380
SOCK* sock, /* [out] handle of the created socket */
381
const void* init_data,/* [in] initial output data segment (may be NULL)*/
382
size_t init_size,/* [in] size of initial data segment (may be 0) */
383
ESwitch log /* [in] whether to do logging on this socket */
387
/* [SERVER-side] Create a socket on top of OS-dependent "handle"
388
* (file descriptor on Unix). Returned socket is not reopenable to its
389
* default peer (SOCK_Reconnect may not specify zeros for the connection
390
* point). All timeouts are set to its default [infinite] values.
464
const STimeout* timeout,
466
const void* init_data,
472
* @sa SOCK_CreateOnTopEx()
475
eSCOT_KeepOnClose, /** Do not close "handle" on SOCK_Close() */
476
eSCOT_CloseOnClose /** Do close "handle" on SOCK_Close() */
480
/** [SERVER-side] Create a socket on top of OS-dependent "handle".
482
* Equivalent of SOCK_CreateOnTopEx(handle, handle_size, sock,
483
* 0, 0, eDefault, eSCOT_CloseOnClose).
485
* [in] OS-dependent "handle" to be converted
489
* [out] SOCK built on top of OS "handle"
490
* @sa SOCK_CreateOnTopEx()
492
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_CreateOnTop
499
/** [SERVER-side] Create a socket on top of OS-dependent "handle"
500
* (file descriptor on Unix, SOCKET on MS-Windows). Returned socket
501
* is not reopenable to its default peer (SOCK_Reconnect may not specify
502
* zeros for the connection point).
503
* All timeouts are set to default [infinite] values.
391
504
* SOCK_Close() will close the "handle" only if the "close_on_close"
392
505
* parameter is passed non-zero (eSCOT_CloseOnClose).
393
* Return eIO_Success on success; otherwise: eIO_Closed if the "handle" does
394
* not refer to an open socket [but e.g. to a normal file or a pipe];
395
* other error codes in case of other errors.
507
* [in] OS-dependent "handle" to be converted
511
* [out] SOCK built on top of OS "handle"
513
* [in] initial output data segment (ok NULL)
515
* [in] size of initial data segment (ok 0)
517
* [in] data logging for the resulting SOCK
519
* [in] if to keep "handle" in SOCK_Close()
521
* Return eIO_Success on success; otherwise: eIO_Closed if the "handle" does
522
* not refer to an open socket [but e.g. to a normal file or a pipe];
523
* other error codes in case of other errors.
524
* @sa SOCK_CreateOnTop()
398
eSCOT_KeepOnClose, /* Do not close "handle" on SOCK_Close() */
399
eSCOT_CloseOnClose /* Do close "handle" on SOCK_Close() */
402
/* SOCK_CreateOnTopEx(handle, handle_size, sock,
403
0, 0, eDefault, eSCOT_CloseOnClose) */
404
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_CreateOnTop
405
(const void* handle, /* [in] OS-dependent "handle" to be converted */
406
size_t handle_size, /* [in] "handle" size */
407
SOCK* sock /* [out] SOCK built on top of OS "handle" */
410
526
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_CreateOnTopEx
411
(const void* handle, /* [in] OS-dependent "handle" to be converted */
412
size_t handle_size, /* [in] "handle" size */
413
SOCK* sock, /* [out] SOCK built on top of OS "handle" */
414
const void* init_data, /* [in] initial output data segment (ok NULL) */
415
size_t init_size, /* [in] size of initial data segment (ok 0) */
416
ESwitch log, /* [in] data logging for the resulting SOCK */
417
ESCOT_OnClose on_close /* [in] if to keep "handle" in SOCK_Close() */
530
const void* init_data,
533
ESCOT_OnClose on_close
421
/* [CLIENT-side] Close the socket referred to by "sock" and then connect
537
/** [CLIENT-side] Close the socket referred to by "sock" and then connect
422
538
* it to another "host:port"; fail if it takes more than "timeout"
423
539
* (close() + connect() [+ select()])
425
541
* HINT: if "host" is NULL then connect to the same host address as before;
426
542
* if "port" is zero then connect to the same port # as before.
428
* NOTE1: "new" socket inherits the old I/O timeouts.
429
* NOTE2: the call is applicable to stream [not datagram] sockets only.
430
* NOTE3: "timeout"==NULL is infinite; "timeout"=={0,0} causes no wait for
544
* @li <b>NOTE 1:</b> "new" socket inherits the old I/O timeouts.
545
* @li <b>NOTE 2:</b> the call is applicable to stream [not datagram] sockets only.
546
* @li <b>NOTE 3:</b> "timeout"==NULL is infinite; "timeout"=={0,0} causes no wait for
431
547
* connection to be established and to return immediately.
432
* NOTE4: UNIX sockets can only be reconnected to the same file thus both
548
* @li <b>NOTE 4:</b> UNIX sockets can only be reconnected to the same file thus both
433
549
* host and port have to be passed as 0s.
551
* [in] handle of the socket to reconnect
553
* [in] host to connect to (can be NULL)
555
* [in] port to connect to (can be 0)
557
* [in] the connect timeout (infinite if NULL)
435
559
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Reconnect
436
(SOCK sock, /* [in] handle of the socket to reconnect */
437
const char* host, /* [in] host to connect to (can be NULL) */
438
unsigned short port, /* [in] port to connect to (can be 0) */
439
const STimeout* timeout /* [in] the connect timeout (infinite if NULL) */
563
const STimeout* timeout
443
/* Shutdown the connection in only one direction (specified by "direction").
567
/** Shutdown the connection in only one direction (specified by "direction").
444
568
* Later attempts to I/O (or to wait) in the shutdown direction will
445
569
* do nothing, and immediately return with "eIO_Closed" status.
446
570
* Pending data output can cause data transfer to the remote end (subject
447
571
* for eIO_Close timeout as previously set by SOCK_SetTimeout()).
448
572
* Cannot be applied to datagram sockets (eIO_InvalidArg results).
574
* [in] handle of the socket to shutdown
576
* [in] one of: eIO_Read, eIO_Write, eIO_ReadWrite
450
578
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Shutdown
451
(SOCK sock, /* [in] handle of the socket to shutdown */
452
EIO_Event how /* [in] one of: eIO_Read, eIO_Write, eIO_ReadWrite */
456
/* Close the connection, destroy relevant internal data.
584
/** Close the connection, destroy relevant internal data.
457
585
* The "sock" handle goes invalid after this function call, regardless
458
586
* of whether the call was successful or not.
459
* NOTE1: if eIO_Close timeout was specified (or NULL) then it blocks until
587
* @li <b>NOTE 1:</b> if eIO_Close timeout was specified (or NULL) then it blocks until
460
588
* either all unsent data are sent, error flagged, or the timeout
462
* NOTE2: if there is output pending, that output will be flushed.
590
* @li <b>NOTE 2:</b> if there is output pending, that output will be flushed.
464
594
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Close(SOCK sock);
467
/* Close the connection, and conditionally destroy relevant internal data.
468
* NOTE1: if eIO_Close timeout was specified (or NULL) then it blocks until
597
/** Close the connection, and conditionally destroy relevant internal data.
598
* @li <b>NOTE 1:</b> if eIO_Close timeout was specified (or NULL) then it blocks until
469
599
* either all unsent data are sent, error flagged, or the timeout
471
* NOTE2: if there is output pending, that output will be flushed.
472
* NOTE3: SOCK_CloseEx(sock, 1) is equivalent to SOCK_Close(sock);
601
* @li <b>NOTE 2:</b> if there is output pending, that output will be flushed.
602
* @li <b>NOTE 3:</b> SOCK_CloseEx(sock, 1) is equivalent to SOCK_Close(sock);
604
* [in] handle of the socket to close
606
* [in] =1 to destroy handle; =0 to keep handle
474
608
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_CloseEx
475
(SOCK sock, /* [in] handle of the socket to close */
476
int/*bool*/ destroy /* [in] =1 to destroy handle; =0 to keep handle */
480
/* Block on the socket until either read/write (dep. on the "event" arg) is
614
/** Block on the socket until either read/write (dep. on the "event" arg) is
481
615
* available or timeout expires (if "timeout" is NULL then assume it infinite).
482
616
* For a datagram socket, eIO_Closed is returned if the internally latched
483
617
* message was entirely read out, and eIO_Read was requested as the "event".
484
618
* Both eIO_Write and eIO_ReadWrite events always immediately succeed for
485
619
* the datagram socket.
623
* [in] one of: eIO_Read, eIO_Write, eIO_ReadWrite
625
* [in] Maximum time to wait for an event
487
627
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Wait
489
EIO_Event event, /* [in] one of: eIO_Read, eIO_Write, eIO_ReadWrite */
490
630
const STimeout* timeout
494
/* Block until at least one of the sockets enlisted in "polls" array
638
SOCK sock; /** [in] SOCK to poll (NULL if not to poll) */
639
EIO_Event event; /** [in] one of: eIO_Read, eIO_Write, eIO_ReadWrite */
640
EIO_Event revent; /** [out] one of: eIO_Open/Read/Write/ReadWrite/Close */
644
/** Block until at least one of the sockets enlisted in "polls" array
495
645
* (of size "n") becomes available for requested operation (event),
496
646
* or until timeout expires (wait indefinitely if timeout is passed NULL).
497
647
* Return eIO_Success if at least one socket was found ready; eIO_Timeout
498
648
* if timeout expired; eIO_Unknown if underlying system call(s) failed.
499
* NOTE1: For a socket found not ready for an operation, eIO_Open is returned
649
* @li <b>NOTE 1:</b> For a socket found not ready for an operation, eIO_Open is returned
500
650
* in its "revent"; for a failing socket, eIO_Close is returned;
501
* NOTE2: This call may return eIO_InvalidArg if
651
* @li <b>NOTE 2:</b> This call may return eIO_InvalidArg if
502
652
* - parameters to the call are inconsistent;
503
653
* - a non-NULL socket polled with a bad "event" (eIO_Open, eIO_Close).
504
654
* With this return code, the calling program cannot rely on "revent"
505
655
* fields the "polls" array as they might not be properly updated.
506
* NOTE3: If either both "n" and "polls" are NULL, or all sockets in "polls"
656
* @li <b>NOTE 3:</b> If either both "n" and "polls" are NULL, or all sockets in "polls"
507
657
* are NULL, then the returned result is either
508
658
* eIO_Timeout (after the specified amount of time was spent idle), or
509
659
* eIO_Interrupted (if signal came while the waiting was in progress).
510
* NOTE4: For datagram sockets, the readiness for reading is determined by
660
* @li <b>NOTE 4:</b> For datagram sockets, the readiness for reading is determined by
511
661
* message data latched since last message receive call (DSOCK_RecvMsg).
512
* NOTE5: This call allows intermixture of stream and datagram sockets.
513
* NOTE6: This call can cause some socket I/O in those sockets marked for
662
* @li <b>NOTE 5:</b> This call allows intermixture of stream and datagram sockets.
663
* @li <b>NOTE 6:</b> This call can cause some socket I/O in those sockets marked for
514
664
* read-on-write and those with pending connection or output data.
666
* [in] # of SSOCK_Poll elems in "polls"
668
* [in|out] array of query/result structures
670
* [in] max time to wait (infinite if NULL)
672
* [out] # of ready sockets (may be NULL)
518
SOCK sock; /* [in] SOCK to poll (NULL if not to poll) */
519
EIO_Event event; /* [in] one of: eIO_Read, eIO_Write, eIO_ReadWrite */
520
EIO_Event revent; /* [out] one of: eIO_Open/Read/Write/ReadWrite/Close */
523
674
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Poll
524
(size_t n, /* [in] # of SSOCK_Poll elems in "polls" */
525
SSOCK_Poll polls[], /* [in|out] array of query/result structures */
526
const STimeout* timeout, /* [in] max time to wait (infinite if NULL) */
527
size_t* n_ready /* [out] # of ready sockets (may be NULL) */
677
const STimeout* timeout,
532
/* GENERIC POLLABLE INTERFACE, please see above for explanations
683
/** GENERIC POLLABLE INTERFACE, please see above for explanations
534
685
struct SPOLLABLE_tag;
535
686
typedef struct SPOLLABLE_tag* POLLABLE;
682
887
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Status
684
EIO_Event direction /* [in] one of: eIO_Open, eIO_Read, eIO_Write */
688
/* Write "size" bytes from buffer "buf" to "sock".
689
* In "*n_written", return the number of bytes actually written.
690
* eIO_WritePlain -- write as many bytes as possible at once and return
893
/** Write "size" bytes from buffer "buf" to "sock".
897
* [in] data to write to the socket
899
* [in] # of bytes (starting at "buf") to write
901
* [out] # of written bytes (can be NULL)
903
* [in] eIO_WritePlain | eIO_WritePersist
905
* In "*n_written", return the number of bytes actually written.
906
* eIO_WritePlain -- write as many bytes as possible at once and return
691
907
* immediately; if no bytes can be written then wait
692
908
* at most WRITE timeout, try again and return.
693
* eIO_WritePersist -- write all data (doing an internal retry loop
909
* eIO_WritePersist -- write all data (doing an internal retry loop
694
910
* if necessary); if any single write attempt times out
695
911
* or fails then stop writing and return (error code).
696
* Return status: eIO_Success -- some bytes were written successfully [Plain]
912
* Return status: eIO_Success -- some bytes were written successfully [Plain]
697
913
* -- all bytes were written successfully [Persist]
698
914
* other code denotes an error, but some bytes might have
699
915
* been sent nevertheless (always check *n_written to know).
701
* NOTE1: With eIO_WritePlain the call returns eIO_Success iff some data
917
* @li <b>NOTE 1:</b> With eIO_WritePlain the call returns eIO_Success iff some data
702
918
* were actually written to the socket. If no data could be written
703
919
* (and perhaps timeout expired) this call always returns an error.
704
* NOTE2: eIO_WritePlain and eIO_WritePersist differs that the latter can
920
* @li <b>NOTE 2:</b> eIO_WritePlain and eIO_WritePersist differs that the latter can
705
921
* flag an error condition even if some data were actually written
706
922
* (see "the rule of thumb" in the comments for SOCK_Read() above).
707
* NOTE3: if "size"==0, return value can be eIO_Success if no pending data
923
* @li <b>NOTE 3:</b> if "size"==0, return value can be eIO_Success if no pending data
708
924
* left in the socket, or eIO_Timeout if there are still data pending.
709
925
* In either case, "*n_written" is set to 0 on return.
711
927
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Write
713
const void* buf, /* [in] data to write to the socket */
714
size_t size, /* [in] # of bytes (starting at "buf") to write */
715
size_t* n_written, /* [out] # of written bytes (can be NULL) */
716
EIO_WriteMethod how /* [in] eIO_WritePlain | eIO_WritePersist */
720
/* If there is outstanding connection or output data pending, cancel it.
936
/** If there is outstanding connection or output data pending, cancel it.
721
937
* Mark the socket as if it has been shut down for both reading and writing.
722
938
* Break actual connection if any was established.
723
939
* Do not attempt to send anything upon SOCK_Close().
724
940
* This call is available for stream sockets only.
726
944
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_Abort
731
/* Get host and port of the socket's peer.
732
* If "network_byte_order" is true(non-zero) then return the host/port in the
733
* network byte order; otherwise return them in the local host byte order.
949
/** Get host and port of the socket's peer.
953
* [out] the peer's host (can be NULL)
955
* [out] the peer's port (can be NULL)
957
* [in] host/port byte order
959
* If "network_byte_order" is true(non-zero) then return the host/port in the
960
* network byte order; otherwise return them in the local host byte order.
735
962
extern NCBI_XCONNECT_EXPORT void SOCK_GetPeerAddress
737
unsigned int* host, /* [out] the peer's host (can be NULL) */
738
unsigned short* port, /* [out] the peer's port (can be NULL) */
739
ENH_ByteOrder byte_order /* [in] host/port byte order */
965
unsigned short* port,
966
ENH_ByteOrder byte_order
743
/* Get textual representation of the socket's peer.
970
/** Get textual representation of the socket's peer.
744
971
* For INET domain sockets, the result is of the form "aaa.bbb.ccc.ddd:ppppp";
745
972
* for UNIX domain socket, the result is the name of the socket's file.
746
* On success, return its "buf" argument; return 0 on error.
976
* [out] pointer to provided buffer to store the text to
978
* [in] usable size of the buffer above
980
* On success, return its "buf" argument; return 0 on error.
748
982
extern NCBI_XCONNECT_EXPORT char* SOCK_GetPeerAddressString
750
char* buf, /* [out] pointer to provided buffer to store the text to */
751
size_t buflen /* [in] usable size of the buffer above */
755
/* Get an OS-dependent native socket handle to use by platform-specific API.
989
/** Get an OS-dependent native socket handle to use by platform-specific API.
756
990
* FYI: on MS-Windows it will be "SOCKET", on other platforms -- "int".
994
* pointer to a memory area to put the OS handle at
996
* the exact(!) size of the expected OS handle
758
998
extern NCBI_XCONNECT_EXPORT EIO_Status SOCK_GetOSHandle
760
void* handle_buf, /* pointer to a memory area to put the OS handle at */
761
size_t handle_size /* the exact(!) size of the expected OS handle */
765
/* By default ("on_off" == eDefault,eOff), sockets will not try to read data
1005
/** By default ("on_off" == eDefault,eOff), sockets will not try to read data
766
1006
* from inside SOCK_Write(). If you want to automagically upread the data
767
1007
* (and cache it in the internal socket buffer) when the write operation
768
1008
* is not immediately available, call this func with "on_off" == eOn.
769
* Return prior setting.
771
1014
extern NCBI_XCONNECT_EXPORT ESwitch SOCK_SetReadOnWriteAPI
776
/* Control the reading-while-writing feature for socket "sock" individually.
1019
/** Control the reading-while-writing feature for socket "sock" individually.
777
1020
* To reset to the global default behavior (as set by
778
1021
* SOCK_SetReadOnWriteAPI), call this function with "on_off" == eDefault.
779
* Return prior setting.
1023
* [in] socket handle
781
1029
extern NCBI_XCONNECT_EXPORT ESwitch SOCK_SetReadOnWrite
842
1095
* buffers correspondingly.
1100
* [out] socket created
846
1102
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_Create
847
(SOCK* sock /* [out] socket created */
1108
* [out] socket created
1110
* [in] whether to log data activity
851
1112
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_CreateEx
852
(SOCK* sock, /* [out] socket created */
853
ESwitch log /* [in] whether to log data activity*/
1119
* [in] SOCK from DSOCK_Create[Ex]()
1121
* [in] port to bind to (!=0)
857
1123
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_Bind
858
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
859
unsigned short port /* [in] port to bind to (!=0) */
1130
* [in] SOCK from DSOCK_Create[Ex]()
863
1136
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_Connect
864
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
865
const char* host, /* [in] peer host */
866
unsigned short port /* [in] peer port */
1144
* [in] SOCK from DSOCK_Create[Ex]()
1146
* [in] time to wait for message
870
1148
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_WaitMsg
871
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
872
const STimeout* timeout /* [in] time to wait for message */
1150
const STimeout* timeout
1155
* [in] SOCK from DSOCK_Create[Ex]()
1157
* [in] hostname or dotted IP
1159
* [in] port number, host byte order
1161
* [in] additional data to send
1163
* [in] size of additional data (bytes)
876
1165
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_SendMsg
877
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
878
const char* host, /* [in] hostname or dotted IP */
879
unsigned short port, /* [in] port number, host byte order*/
880
const void* data, /* [in] additional data to send */
881
size_t datalen /* [in] size of addtl data (bytes) */
1168
unsigned short port,
1175
* [in] SOCK from DSOCK_Create[Ex]()
1177
* [in] buf to store msg at,m.b.NULL
1179
* [in] buf length provided
1181
* [in] maximal expected message len
1183
* [out] actual msg size, may be NULL
1184
* @param sender_addr
1185
* [out] net byte order, may be NULL
1186
* @param sender_port
1187
* [out] host byte order, may be NULL
885
1189
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_RecvMsg
886
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
887
void* buf, /* [in] buf to store msg at,m.b.NULL*/
888
size_t buflen, /* [in] buf length provided */
889
size_t maxmsglen, /* [in] maximal expected message len*/
890
size_t* msglen, /* [out] actual msg size, may be NULL*/
891
unsigned int* sender_addr, /* [out] net byte order, may be NULL */
892
unsigned short* sender_port /* [out] host byte order, may be NULL*/
1195
unsigned int* sender_addr,
1196
unsigned short* sender_port
1201
* [in] SOCK from DSOCK_Create[Ex]()
1203
* [in] either of eIO_Read|eIO_Write
896
1205
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_WipeMsg
897
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
898
EIO_Event direction /* [in] either of eIO_Read|eIO_Write*/
1212
* [in] SOCK from DSOCK_Create[Ex]()
1214
* [in] set(1)/unset(0) bcast capab
902
1216
extern NCBI_XCONNECT_EXPORT EIO_Status DSOCK_SetBroadcast
903
(SOCK sock, /* [in] SOCK from DSOCK_Create[Ex]()*/
904
int/*bool*/ broadcast /* [in] set(1)/unset(0) bcast capab.*/
1218
int/**bool*/ broadcast
969
1315
#define SOCK_NetToHostLong SOCK_HostToNetLong
971
1321
extern NCBI_XCONNECT_EXPORT unsigned short SOCK_HostToNetShort
972
1322
(unsigned short value
975
1325
#define SOCK_NetToHostShort SOCK_HostToNetShort
978
#define SOCK_htonl SOCK_HostToNetLong
979
#define SOCK_ntohl SOCK_NetToHostLong
980
#define SOCK_htons SOCK_HostToNetShort
981
#define SOCK_ntohs SOCK_NetToHostShort
984
/* Return INET host address (in network byte order) of the
985
* specified host (or local host, if hostname is passed as NULL),
986
* which can be either domain name or an IP address in
987
* dotted notation (e.g. "123.45.67.89\0"). Return 0 on error.
988
* NOTE: "0.0.0.0" and "255.255.255.255" are considered invalid.
1328
/* Deprecated: Use SOCK_{Host|Net}To{Net|Host}{Long|Short}() instead */
1329
#ifndef NCBI_DEPRECATED
1330
# define NCBI_SOCK_DEPRECATED
1332
# define NCBI_SOCK_DEPRECATED NCBI_DEPRECATED
1334
extern NCBI_XCONNECT_EXPORT NCBI_SOCK_DEPRECATED
1335
unsigned int SOCK_htonl(unsigned int);
1336
#define SOCK_ntohl SOCK_htonl
1337
extern NCBI_XCONNECT_EXPORT NCBI_SOCK_DEPRECATED
1338
unsigned short SOCK_htons(unsigned short);
1339
#define SOCK_ntohs SOCK_htons
1344
* [in] return current host address if hostname is 0
1346
* INET host address (in network byte order) of the
1347
* specified host (or local host, if hostname is passed as NULL),
1348
* which can be either domain name or an IP address in
1349
* dotted notation (e.g. "123.45.67.89\0"). Return 0 on error.
1350
* @li <b>NOTE:</b> "0.0.0.0" and "255.255.255.255" are considered invalid.
990
1352
extern NCBI_XCONNECT_EXPORT unsigned int SOCK_gethostbyname
991
(const char* hostname /* [in] return current host address if hostname is 0 */
1353
(const char* hostname \
995
/* Take INET host address (in network byte order) and fill out the
1357
/** Take INET host address (in network byte order) and fill out the
996
1358
* the provided buffer with the name, which the address corresponds to
997
* (in case of multiple names the primary name is used). Return value 0
998
* means error, while success is denoted by the 'name' argument returned.
999
* Note that on error the name returned emptied (name[0] == '\0').
1359
* (in case of multiple names the primary name is used).
1361
* [in] host address in network byte order
1363
* [out] buffer to put the name to
1365
* [in] size (bytes) of the buffer above
1368
* means error, while success is denoted by the 'name' argument returned.
1369
* Note that on error the name returned emptied (name[0] == '\0').
1001
1371
extern NCBI_XCONNECT_EXPORT char* SOCK_gethostbyaddr
1002
(unsigned int addr, /* [in] host address in network byte order */
1003
char* name, /* [out] buffer to put the name to */
1004
size_t namelen /* [in] size (bytes) of the buffer above */
1008
/* Return loopback address (in network byte order).
1380
* Loopback address (in network byte order).
1010
1382
extern NCBI_XCONNECT_EXPORT unsigned int SOCK_GetLoopbackAddress(void);
1385
/** Read (skipping leading blanks) "[host][:port]" from a string.
1393
* On success, return the advanced pointer past the host/port read.
1394
* If no host/port detected, return 'str'.
1395
* On format error, return 0.
1396
* If host and/or port fragments are missing,
1397
* then corresponding 'host'/'port' value returned as 0.
1398
* Note that 'host' returned is in network byte order,
1399
* unlike 'port', which always comes out in host (native) byte order.
1401
extern NCBI_XCONNECT_EXPORT const char* SOCK_StringToHostPort
1404
unsigned short* port
1408
/** Print host:port into provided buffer string, not to exceed 'buflen' size.
1409
* Suppress printing host if parameter 'host' is zero.
1419
* Number of bytes printed.
1421
extern NCBI_XCONNECT_EXPORT size_t SOCK_HostPortToString
1423
unsigned short port,
1013
1429
#ifdef __cplusplus
1014
1430
} /* extern "C" */