Network Sockets

Platform-independent implementation for TCP/UDP network sockets.
Used by agent code and be useful for network clients loader agents.

Constants

Socket types

VALUES

#define NSK_STREAM  
#define NSK_DRAM    

Return values

Each constant represents failed operation

#define NSK_OK  0
#define NSK_ERR_RESOLVE -1
#define NSK_ERR_SOCKET  -2
#define NSK_ERR_CONNECT -3
#define NSK_ERR_BIND    -4
#define NSK_ERR_LISTEN  -5
#define NSK_ERR_ACCEPT  -6
#define NSK_ERR_SETOPT  -7
#define NSK_ERR_SETNB   -8

nsk_poll() return values

VALUES

#define NSK_POLL_OK 0
#define NSK_POLL_NEW_DATA   1
#define NSK_POLL_DISCONNECT 2
#define NSK_POLL_FAILURE    3

nsk_recv() return values

VALUES

#define NSK_RECV_DISCONNECT -1
#define NSK_RECV_NO_DATA    -2
#define NSK_RECV_ERROR  -3

nsk_addr_to_string() flags

VALUES

#define NSK_ADDR_FLAG_DEFAULT   0x00
#define NSK_ADDR_FLAG_SERVICES  0x01

Functions

nsk_resolve

publicplat


Resolve hostname and write result into he

ARGUMENTS

NOTES
On some platforms may lock mutexes, because implementation is not re-enterable

LIBEXPORT PLATAPI int nsk_resolve(const char* host, nsk_host_entry* he)

nsk_setaddr

publicplat


Set up socket address object

ARGUMENTS

LIBEXPORT PLATAPI int nsk_setaddr(nsk_addr* sa, nsk_host_entry* he, unsigned short port)

nsk_addr_to_string

publicplat


Converts socket address into string <IP>:<port>

ARGUMENTS

LIBEXPORT PLATAPI int nsk_addr_to_string(nsk_addr* sa, char* buf, size_t buflen,int default_port, int flags)

nsk_connect

publicplat


Set up socket and connect to remote node

ARGUMENTS

LIBEXPORT PLATAPI int nsk_connect(nsk_socket* clnt_socket, nsk_addr* sa, int type)

nsk_listen

publicplat


Listen on server socket

ARGUMENTS

LIBEXPORT PLATAPI int nsk_listen(nsk_socket* srv_socket, nsk_addr* sa, int type)

nsk_accept

publicplat


Accept clients connection

ARGUMENTS

LIBEXPORT PLATAPI int nsk_accept(nsk_socket* srv_socket, nsk_socket* clnt_socket, nsk_addr* clnt_sa)

nsk_disconnect

publicplat


Shutdown and close connection - both for server and client sockets

ARGUMENTS

LIBEXPORT PLATAPI int nsk_disconnect(nsk_socket* socket)

nsk_setopt

publicplat


Set socket option. Interface for platform setsockopt() or equal function.

LIBEXPORT PLATAPI int nsk_setopt(nsk_socket* socket, int level, int optname,const void* optval, size_t optlen)

nsk_setnb

publicplat


Enable or disable nonblocking operations on socket

ARGUMENTS

LIBEXPORT PLATAPI int nsk_setnb(nsk_socket* socket, boolean_t nonblocking)

nsk_poll

publicplat


Wait on incoming data or disconnect of socket.
Polling of multiple sockets is not supported

RETURN VALUES
One of NSK_POLL_ results

LIBEXPORT PLATAPI int nsk_poll(nsk_socket* socket, ts_time_t timeout)

nsk_send

publicplat


Send data over socket

RETURN VALUES
0 in case of disconnect, -1 on error, or number of bytes sent

LIBEXPORT PLATAPI int nsk_send(nsk_socket* socket, void* data, size_t len)

nsk_recv

publicplat


Receive data from socket

RETURN VALUES
one of NSK_RECV_ value

LIBEXPORT PLATAPI int nsk_recv(nsk_socket* socket, void* data, size_t len)

nsk_init, nsk_fini

publicplat

LIBEXPORT PLATAPI int nsk_init(void)
LIBEXPORT PLATAPI void nsk_fini(void)