Sockets functions
=================

accept
------

 -- Loadable Function: [CLIENT, INFO] = accept (S)
     Accept incoming connection on specified socket.

     Accepts an incoming connection on the socket S. The newly created socket is returned in CLIENT, and associated information in a struct info.

     See the accept man pages for further details.

bind
----

 -- Loadable Function: bind (S, PORTNUMBER)
     Bind specific socket to port number.

     See the bind man pages for further details.

connect
-------

 -- Loadable Function: connect (S, SERVERINFO)
     Connect socket.

     Connects the socket S following the information in the struct SERVERINFO which must contain the following fields:

     addr
          a string with the host name to connect to

     port
          the port number to connect to (an integer)

     On successful connect, the returned status is zero.

     See the connect man pages for further details.

disconnect
----------

 -- Loadable Function: disconnect (S)
     Disconnect socket.

     Disconnects the socket S.  If successful, disconnect returns 0, otherwise, it returns -1.

     Since we can't call fclose on the file descriptor directly, use this function to disconnect the socket.

gethostbyname
-------------

 -- Loadable Function: IPADDRES = gethostbyname (HOSTNAME)
     Return IP address for host name.

     For example:

          gethostbyname ("localhost")
          => 127.0.0.1

     See the gethostbyname man pages for details.

getsockopt
----------

 -- Loadable Function: [DATA, STATUS] = getsockopt (S, LEVEL, OPTNAME)
     Get a socket option value from a socket.

     Returns the value of LEVEL OPTNAME from the socket S.

     Data type depends on the option used. STATUS returns as  0 if no error.

     See the getsockopt man pages for further details.

listen
------

 -- Loadable Function: listen (S, BACKLOG)
     Listen on socket for connections.

     Listens on socket S for connections.  BACKLOG specifies how large the queue of incoming connections is allowed to grow.

     On success, zero is returned.

     See the listen man pages for further details.

recv
----

 -- Loadable Function: [DATA, COUNT] = recv (S, LEN)
 -- Loadable Function: [DATA, COUNT] = recv (S, LEN, FLAGS)
     Read data from specified socket.

     Requests reading LEN bytes from the socket S. The optional integer FLAGS parameter can be used to modify the behaviour of recv.

     The read data is returned in the uint8 array DATA.  The number of bytes read is returned in COUNT.

     You can get non-blocking operation by using the flag MSG_DONTWAIT which makes the recv() call return immediately.  If there is no data, -1 is returned in count.

     See the recv man pages for further details.

recvfrom
--------

 -- Loadable Function: [DATA, COUNT, SRC_INFO] = recvfrom (S, LEN)
 -- Loadable Function: [DATA, COUNT, SRC_INFO] = recvfrom (S, LEN, FLAGS)
     Read data from specified socket.

     Requests reading LEN bytes from the socket S. The optional integer FLAGS parameter can be used to modify the behaviour of recvfrom.

     The read data is returned in the uint8 array DATA.  The number of bytes read is returned in COUNT and a structure with fields addr and port contain the source of the data.

     You can get non-blocking operation by using the flag MSG_DONTWAIT which makes the recvfrom() call return immediately.  If there is no data, -1 is returned in count.

     See the recvfrom man pages for further details.

select
------

 -- Loadable Function: [STATUS, RFDSET, WFDSET, EFDSET] = select (NFDS, RFDSET, WFDSET, EFDSET, TIMEOUT)
     Wait for socket activity on selected sockets.

     The fdsets are vectors of fds to check, for example [1 2 3]. Empty vectors equate to null.

     nfds tests file descriptions in the range of 0 - nfds-1.

     Timeout is can be either an real value for number of seconds, a struct with a tm_sec and tm_usec fields, or empty set for null.

     STATUS returns as  0 if timeout, or number of waiting sockets if ok.

     See the select man pages for further details.

send
----

 -- Loadable Function: RETVAL = send (S, DATA)
 -- Loadable Function: RETVAL = send (S, DATA, FLAGS)
     Send data on specified socket.

     Sends data on socket S.  DATA should be an uint8 array or a string.

     See the send man pages for further details.

sendto
------

 -- Loadable Function: RETVAL = sendto (S, DATA, DEST_INFO)
 -- Loadable Function: RETVAL = sendto (S, DATA, FLAGS, DEST_INFO)
     Send data on specified socket.

     Sends data on socket S to destination.  DATA should be an uint8 array or a string.

     The dest_info struct DEST_INFO must contain the following fields:

     addr
          a string with the host name to send to

     port
          the port number to send to (an integer)

     See the sendto man pages for further details.

setsockopt
----------

 -- Loadable Function: STATUS = setsockopt (S, LEVEL, OPTNAME, OPTVALUE)
     Set a socket option value on a socket.

     STATUS returns as  0 if no error.

     See the setsockopt man pages for further details.

shutdown
--------

 -- Loadable Function: shutdown (S, HOW)
     Shutdown all or part of a connection of a socket.

     On success, zero is returned.

     See the shutdown man pages for further details.

socket
------

 -- Loadable Function: SOCK = socket ()
 -- Loadable Function: SOCK = socket (DOMAIN)
 -- Loadable Function: SOCK = socket (DOMAIN, TYPE)
 -- Loadable Function: SOCK = socket (DOMAIN, TYPE, PROTOCOL)
     Creates a socket.

     DOMAIN is an integer, where the value AF_INET can be used to create an IPv4 socket.

     TYPE is an integer describing the socket.  When using IP, specifying SOCK_STREAM gives a TCP socket.

     PROTOCOL is currently not used and should be 0 if specified.

     If no input arguments are given, default values AF_INET and SOCK_STREAM are used.

     See the local socket reference for more details.

Socket constants
================

AF_APPLETALK
------------

Socket constant for AF_APPLETALK

AF_INET
-------

Socket constant for AF_INET

AF_LOCAL
--------

Socket constant for AF_LOCAL

AF_UNIX
-------

Socket constant for AF_UNIX

MSG_DONTWAIT
------------

Socket constant for MSG_DONTWAIT

MSG_PEEK
--------

Socket constant for MSG_PEEK

MSG_WAITALL
-----------

Socket constant for MSG_WAITALL

SHUT_RD
-------

Socket constant for SHUT_RD

SHUT_RDWR
---------

Socket constant for SHUT_RDWR

SHUT_WR
-------

Socket constant for SHUT_WR

SOCK_DGRAM
----------

Socket constant for SOCK_DGRAM

SOCK_RAW
--------

Socket constant for SOCK_RAW

SOCK_RDM
--------

Socket constant for SOCK_RDM

SOCK_SEQPACKET
--------------

Socket constant for SOCK_SEQPACKET

SOCK_STREAM
-----------

Socket constant for SOCK_STREAM

SOL_SOCKET
----------

Socket constant for SOL_SOCKET

SO_BROADCAST
------------

Socket constant for SO_BROADCAST

SO_DONTROUTE
------------

Socket constant for SO_DONTROUTE

SO_KEEPALIVE
------------

Socket constant for SO_KEEPALIVE

SO_REUSEADDR
------------

Socket constant for SO_REUSEADDR