sl@0: /** @file  ../include/sys/socket.h
sl@0: @internalComponent
sl@0: */
sl@0: 
sl@0: /** @fn  accept(int s, struct sockaddr *  addr, socklen_t *  addrlen)
sl@0: @param s
sl@0: @param addr
sl@0: @param addrlen
sl@0: 
sl@0:   The argument s is a socket that has been created with socket, bound to an address with bind and is listening for connections after a listen . The accept system call extracts the first connection request on the queue 
sl@0: of pending connections and creates a new socket which it allocates a new file 
sl@0: descriptor. The new socket inherits the state of the O_NONBLOCK property from the original socket s.
sl@0: 
sl@0:  If no pending connections are present on the queue, and the original socket 
sl@0:   is not marked as non-blocking, accept blocks the caller until a connection is present. If the original 
sl@0:   socket is marked non-blocking and no pending connections are present on the 
sl@0:   queue, accept returns an error as described below.
sl@0: 
sl@0:  The accepted socket may not be used to accept more connections. The original 
sl@0:   socket s remains open.
sl@0: 
sl@0:  The argument addr is a result argument that is filled-in with the address of the 
sl@0:   connecting entity as it is known to the communications layer. The exact format 
sl@0:   of the addr argument is determined by the domain in which the communication 
sl@0:   is occurring. A null pointer may be specified for addr if the address information is not required. In this case addrlen is not used and should also be null. Otherwise, the addrlen argument is a value-result argument: It should initially contain 
sl@0:   the amount of space pointed to by addr and on return will contain the actual length (in bytes) of the 
sl@0:   address returned. This call is used with connection-based socket types, currently 
sl@0:   with SOCK_STREAM.
sl@0: 
sl@0:  It is possible to select a socket for the purposes of doing an accept by selecting it for read.
sl@0: 
sl@0:  For certain protocols, such as ISO or DATAKIT which require an explicit confirmation, accept can be thought of as merely dequeueing the next connection 
sl@0:   request and not implying confirmation. Confirmation can be implied by a normal 
sl@0:   read or write on the new file descriptor, and rejection can be implied by closing 
sl@0:   the new socket.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void GetSockName()
sl@0: {
sl@0:    int sock_fd;
sl@0:    int newsock_fd;
sl@0:    struct sockaddr_in addr;
sl@0:    struct sockaddr_in ss;
sl@0:    struct sockaddr_in new_socket;
sl@0:    unsigned int len;
sl@0:    unsigned int addr_len;
sl@0:    
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:        
sl@0:    addr.sin_family = AF_INET;
sl@0:    addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(sockaddr*)&addr;,sizeof(addr));
sl@0:    listen(sock_fd,1);
sl@0:    newsock_fd = accept(sock_fd,(sockaddr*)&new;_socket,&addr;_len); // Code blocks here
sl@0:    if (newsock_fd <= 0)
sl@0:    {
sl@0:                 perror("accept:");
sl@0:    }
sl@0:    close(newsock_fd);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @return   The call returns -1 on error.
sl@0: If it succeeds, it returns a non-negative
sl@0: integer that is a descriptor for the accepted socket.
sl@0: 
sl@0: @see bind()
sl@0: @see connect()
sl@0: @see getpeername()
sl@0: @see listen()
sl@0: @see select()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  bind(int s, const struct sockaddr *addr, socklen_t addrlen)
sl@0: @param s
sl@0: @param addr
sl@0: @param addrlen
sl@0: 
sl@0:   The bind system call
sl@0: assigns the local protocol address to a socket.
sl@0: When a socket is created
sl@0: with socket it exists in an address family space but has no protocol address assigned.
sl@0: The bind system call requests that addr be assigned to the socket.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: TInt GetSockName()
sl@0: {
sl@0:    int sock_fd;
sl@0:    struct sockaddr_in addr,ss;
sl@0:    unsigned int len;   
sl@0:    
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:        
sl@0:    addr.sin_family = AF_INET;
sl@0:    addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(struct sockaddr*)&addr;,sizeof(addr));
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: 
sl@0: Notes:
sl@0: 
sl@0:  For maximum portability always initialise the socket address structure to 
sl@0:   zero before populating it and passing it to bind.
sl@0:   
sl@0: @return   The bind() function returns the value 0 if successful; otherwise the
sl@0: value -1 is returned and the global variable errno is set to indicate the
sl@0: error.
sl@0: 
sl@0: @see connect()
sl@0: @see getsockname()
sl@0: @see listen()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  connect(int s, const struct sockaddr *name, socklen_t namelen)
sl@0: @param s
sl@0: @param name
sl@0: @param namelen
sl@0:  
sl@0: 
sl@0:  The s argument is a socket. If it is of type SOCK_DGRAM name specifies the peer with which the socket is to be associated. It 
sl@0:   specifiies the address to which datagrams are to be sent and the only address 
sl@0:   from which datagrams are to be received.
sl@0: 
sl@0:  If the socket is of type SOCK_STREAM, this call attempts to make a connection to another socket. 
sl@0:   The other socket is specified by name, which is an address in the communications space of the socket. 
sl@0:   Each communications space interprets the name argument in its own way.
sl@0: 
sl@0:  Generally, stream sockets may successfully connect only once and datagram sockets may use connect multiple times to change their association. Datagram sockets 
sl@0:   may dissolve the association by connecting to an invalid address, such as a 
sl@0:   null address.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void Connect()
sl@0: {
sl@0:    struct sockaddr_in serv_addr;
sl@0:    int sock_fd;
sl@0:    serv_addr.sin_family = AF_INET;
sl@0:    serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sl@0:    serv_addr.sin_port = htons(5000);
sl@0:    sock_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
sl@0:    connect(sock_fd,(struct sockaddr*)&serv;_addr,sizeof(serv_addr));
sl@0:    
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @return   The connect() function returns the value 0 if successful; otherwise it returns 
sl@0: the value -1 and the sets global variable errno to indicate the error.
sl@0: 
sl@0: @see accept()
sl@0: @see getpeername()
sl@0: @see getsockname()
sl@0: @see select()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  getpeername(int s, struct sockaddr *  name, socklen_t *  namelen)
sl@0: @param s
sl@0: @param name
sl@0: @param namelen
sl@0: @return   The getpeername() function returns the value 0 if successful; otherwise
sl@0: the value -1 is returned and the global variable errno is set to indicate
sl@0: the error.
sl@0: 
sl@0:   The getpeername system call
sl@0: returns the name of the peer connected to
sl@0: socket s. The namelen argument should be initialized to indicate
sl@0: the amount of space pointed to by name. On return it contains the actual size of the name
sl@0: returned (in bytes).
sl@0: The name is truncated if the buffer provided is too small.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void GetSockName()
sl@0: {
sl@0:    int sock_fd;
sl@0:    int newsock_fd;
sl@0:    struct sockaddr_in addr;
sl@0:    struct sockaddr_in ss;
sl@0:    struct sockaddr_in new_socket;
sl@0:    unsigned int len;
sl@0:    unsigned int addr_len;
sl@0:     
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:        
sl@0:    addr.sin_family = AF_INET;
sl@0:    addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(struct sockaddr*)&addr;,sizeof(addr));
sl@0:    listen(sock_fd,1);
sl@0:    newsock_fd = accept(sock_fd,(struct sockaddr*)&new;_socket,&addr;_len); // Code blocks here
sl@0:   
sl@0:    // Assuming client has connected to the server. 
sl@0:    len = sizeof(ss);
sl@0:    getpeername(sock_fd,(struct sockaddr*)&ss;,&len;);
sl@0:    close(newsock_fd);
sl@0:    close(sock_fd);
sl@0:  }
sl@0: 
sl@0: @endcode
sl@0: @see accept()
sl@0: @see bind()
sl@0: @see getsockname()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  getsockname(int s, struct sockaddr *  name, socklen_t *  namelen)
sl@0: @param s
sl@0: @param name
sl@0: @param namelen
sl@0: @return   The getsockname() function returns the value 0 if successful; otherwise
sl@0: the value -1 is returned and the global variable errno is set to indicate
sl@0: the error.
sl@0: 
sl@0:   The getsockname system call
sl@0: returns the current name for the specified socket.
sl@0: The namelen argument should be initialized to indicate
sl@0: the amount of space pointed to by name. On return it contains the actual size of the name
sl@0: returned (in bytes).
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: TInt GetSockName()
sl@0: {
sl@0:    int sock_fd;
sl@0:    struct sockaddr_in addr,ss;
sl@0:    unsigned int len;   
sl@0:    
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:        
sl@0:    addr.sin_family = AF_INET;
sl@0:    addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(struct sockaddr*)&addr;,sizeof(addr));
sl@0:  
sl@0:   len=sizeof(ss);
sl@0:   getsockname(sock_fd,(struct sockaddr*)&ss;,&len;);
sl@0:   close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see bind()
sl@0: @see getpeername()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  getsockopt(int s, int level, int optname, void *  optval, socklen_t *  optlen)
sl@0: @param s
sl@0: @param level
sl@0: @param optname
sl@0: @param optval
sl@0: @param optlen
sl@0: Note: This description also covers the following functions -
sl@0:  setsockopt() 
sl@0: 
sl@0: @return   Upon successful completion, the value 0 is returned; otherwise the
sl@0: value -1 is returned and the global variable errno is set to indicate the
sl@0: error.
sl@0: 
sl@0: The getsockopt and setsockopt system calls manipulate the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost "socket" level. 
sl@0: When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP; 
sl@0: 
sl@0: The optval and optlen arguments are used to access option values for setsockopt. For getsockopt they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt, optlen is a value-result argument, initially containing the size of the buffer pointed to by optval, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, optval may be NULL. 
sl@0: 
sl@0: The optname argument and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file   \#include \<sys/socket.h\>contains definitions for socket level options, described below. Options at other protocol levels vary in format and name; consult the appropriate entries in section 4 of the manual. 
sl@0: Most socket-level options utilize an int argument for optval. For setsockopt, the argument should be non-zero to enable a boolean option, or zero if the option is to be disabled. SO_LINGER uses a struct linger argument, defined in 
sl@0:  @code
sl@0:   #include <sys/socket.h,> which specifies the desired state of the option and the linger interval (see below). SO_SNDTIMEO and SO_RCVTIMEO use a struct timeval argument, defined in  
sl@0:   #include <sys/time.h.> 
sl@0: The following options are recognized at the socket level. Except as noted, each may be examined with getsockopt and set with setsockopt. SO_DEBUG            enables recording of debugging information 
sl@0: SO_REUSEADDR       Allows a socket to be bound to an local address that is already in use. 
sl@0: SO_REUSEPORT       enables duplicate address and port bindings 
sl@0: SO_KEEPALIVE       enables keep connections alive 
sl@0: SO_DONTROUTE       enables routing bypass for outgoing messages 
sl@0: SO_BROADCAST       enables permission to transmit broadcast messages (enable only)
sl@0: SO_OOBINLINE       enables reception of out-of-band data in band 
sl@0: SO_SNDBUF          set buffer size for output 
sl@0: SO_RCVBUF          set buffer size for input 
sl@0: SO_SNDLOWAT        set minimum count for output 
sl@0: SO_RCVLOWAT        set minimum count for input 
sl@0: SO_SNDTIMEO        set timeout value for output 
sl@0: SO_RCVTIMEO        set timeout value for input 
sl@0: SO_ACCEPTFILTER            set accept filter on listening socket 
sl@0: SO_TYPE            get the type of the socket (get only) 
sl@0: SO_ERROR           get and clear error on the socket (get only)  
sl@0:    
sl@0: 
sl@0: @endcode
sl@0: 
sl@0: SO_DEBUG enables debugging in the underlying protocol modules. SO_REUSEADDR indicates that the rules used in validating addresses supplied in a bind system call should allow reuse of local addresses. SO_REUSEPORT allows completely duplicate bindings by multiple processes if they all set SO_REUSEPORT before binding the port. This option permits multiple instances of a program to each receive UDP/IP multicast or broadcast datagrams destined for the bound port. SO_KEEPALIVE enables the periodic transmission of messages on a connected socket. SO_DONTROUTE indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address. 
sl@0: 
sl@0: The option SO_BROADCAST requests permission to send broadcast datagrams on the socket. Broadcast was a privileged operation in earlier versions of the system. With protocols that support out-of-band data, the SO_OOBINLINE option requests that out-of-band data be placed in the normal data input queue as received; it will then be accessible with recv or read calls without the MSG_OOB flag. Some protocols always behave as if this option is set. SO_SNDBUF and SO_RCVBUF are options to adjust the normal buffer sizes allocated for output and input buffers, respectively. The buffer size may be increased for high-volume connections, or may be decreased to limit the possible backlog of incoming data. The system places an absolute maximum on these values, which is accessible through the sysctl MIB variable "kern.ipc.maxsockbuf." 
sl@0: 
sl@0: SO_SNDLOWAT is an option to set the minimum count for output operations. Most output operations process all of the data supplied by the call, delivering data to the protocol for transmission and blocking as necessary for flow control. Nonblocking output operations will process as much data as permitted subject to flow control without blocking, but will process no data if flow control does not allow the smaller of the low water mark value or the entire request to be processed. A select operation testing the ability to write to a socket will return true only if the low water mark amount could be processed. The default value for SO_SNDLOWAT is set to a convenient size for network efficiency, often 1024. SO_RCVLOWAT is an option to set the minimum count for input operations. In general, receive calls will block until any (non-zero) amount of data is received, then return with the smaller of the amount available or the amount requested. The default value for SO_RCVLOWAT is 1. If SO_RCVLOWAT is set to a larger value, blocking receive calls normally wait until they have received the smaller of the low water mark value or the requested amount. 
sl@0: 
sl@0: SO_SNDTIMEO is an option to set a timeout value for output operations. It accepts a struct timeval argument with the number of seconds and microseconds used to limit waits for output operations to complete. If a send operation has blocked for this much time, it returns with a partial count or with the error EWOULDBLOCK if no data were sent. In the current implementation, this timer is restarted each time additional data are delivered to the protocol, implying that the limit applies to output portions ranging in size from the low water mark to the high water mark for output. SO_RCVTIMEO is an option to set a timeout value for input operations. It accepts a struct timeval argument with the number of seconds and microseconds used to limit waits for input operations to complete. In the current implementation, this timer is restarted each time additional data are received by the protocol, and thus the limit is in effect an inactivity timer. If a receive operation has been blocked for this much time without receiving additional data, it returns with a short count or with the error EWOULDBLOCK if no data were received. 
sl@0: 
sl@0: SO_ACCEPTFILTER places an accept_filter on the socket, which will filter incoming connections on a listening stream socket before being presented for accept. Once more, listen must be called on the socket before trying to install the filter on it, or else the setsockopt system call will fail. 
sl@0: 
sl@0: SO_LINGER option is not supported by this api.
sl@0: 
sl@0: @code
sl@0: struct  accept_filter_arg {
sl@0:         char    af_name[16];
sl@0:         char    af_arg[256-16];
sl@0: };
sl@0: @endcode
sl@0: 
sl@0: 
sl@0: 
sl@0: The optval argument should point to a struct accept_filter_arg that will select and configure the accept_filter. The af_name argument should be filled with the name of the accept filter that the application wishes to place on the listening socket. The optional argument af_arg can be passed to the accept filter specified by af_name to provide additional configuration options at attach time. Passing in an optval of NULL will remove the filter. 
sl@0: 
sl@0: Finally, SO_TYPE and SO_ERROR are options used only with getsockopt. SO_TYPE returns the type of the socket, such as SOCK_STREAM; it is useful for servers that inherit sockets on startup. SO_ERROR returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors. 
sl@0:  
sl@0: 
sl@0: 
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void SocketOptions()
sl@0: {
sl@0:    int sock_fd;
sl@0:    int optval = 1;
sl@0:    unsigned int optlen = sizeof(optval);
sl@0:    int rdoptval;
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:    setsockopt(sock_fd,SOL_SOCKET,SO_KEEPALIVE,&optval;,optlen);
sl@0:    getsockopt(sock_fd,SOL_SOCKET,SO_KEEPALIVE,(void*)&rdoptval;,&optlen;);
sl@0: close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see ioctl()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  listen(int fd, int n)
sl@0: @param fd
sl@0: @param n
sl@0: @return   The listen() function returns the value 0 if successful; otherwise the
sl@0: value -1 is returned and the global variable errno is set to indicate the
sl@0: error.
sl@0: 
sl@0:   To accept connections a socket is first created with socket . A willingness to accept incoming connections 
sl@0: and a queue limit for incoming connections are specified with listen and then the connections are accepted with accept . The listen system call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET.
sl@0: 
sl@0:  The n argument defines the maximum length the queue of pending connections 
sl@0:   may grow to. The real maximum queue length will be 1.5 times more than the value 
sl@0:   specified in the n argument. A subsequent listen system call on the listening socket allows the caller to change 
sl@0:   the maximum queue length using a new n argument. If a connection request arrives with the queue full 
sl@0:   the client may receive an error with an indication of ECONNREFUSED , or, in the case of TCP, the connection will be silently 
sl@0:   dropped.
sl@0: 
sl@0:  Note that before BSD 4.5 and the introduction of the syncache the n argument also determined the length of the incomplete connection 
sl@0:   queue, which held TCP sockets in the process of completing TCP's 3-way 
sl@0:   handshake. These incomplete connections are now held entirely in the syncache, 
sl@0:   which is unaffected by queue lengths. Inflated n values to help handle denial of service attacks are no longer 
sl@0:   necessary.
sl@0: 
sl@0: 
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void listen_example()
sl@0: {
sl@0:    int sock_fd;
sl@0:    int newsock_fd;
sl@0:    struct sockaddr_in addr;
sl@0:    struct sockaddr_in ss;
sl@0:    struct sockaddr_in new_socket;
sl@0:    unsigned int len;
sl@0:    unsigned int addr_len;
sl@0:    
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:        
sl@0:    addr.sin_family = AF_INET;
sl@0:    addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(struct sockaddr*)&addr;,sizeof(addr));
sl@0:    listen(sock_fd,1);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see accept()
sl@0: @see connect()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  recv(int fd, void *buf, size_t cnt, int flags)
sl@0: @param fd
sl@0: @param buf
sl@0: @param cnt
sl@0: @param flags
sl@0: 
sl@0: Note: This description also covers the following functions -
sl@0:  recvfrom()  recvmsg() 
sl@0: 
sl@0: @return   These calls return the number of bytes received, or -1
sl@0: if an error occurred.
sl@0: 
sl@0: @code
sl@0:  MSG_OOB                process out-of-band data
sl@0: @endcode
sl@0: 
sl@0:   The recvfrom and recvmsg system calls
sl@0: are used to receive messages from a socket,
sl@0: and may be used to receive data on a socket whether or not
sl@0: it is connection-oriented.
sl@0: 
sl@0:  If from is not a null pointer
sl@0: and the socket is not connection-oriented,
sl@0: the source address of the message is filled in.
sl@0: The fromlen argument
sl@0: is a value-result argument, initialized to the size of
sl@0: the buffer associated with from, and modified on return to indicate the actual size of the
sl@0: address stored there.
sl@0: 
sl@0:  The recv function is normally used only on a connected socket (see connect )
sl@0: and is identical to recvfrom with a
sl@0: null pointer passed as its from argument.
sl@0: As it is redundant, it may not be supported in future releases.
sl@0: 
sl@0:  All three routines return the length of the message on successful
sl@0: completion.
sl@0: If a message is too long to fit in the supplied buffer,
sl@0: excess bytes may be discarded depending on the type of socket
sl@0: the message is received from (see socket )
sl@0: 
sl@0:  If no messages are available at the socket, the
sl@0: receive call waits for a message to arrive, unless
sl@0: the socket is nonblocking (see fcntl )
sl@0: in which case the value
sl@0: -1 is returned and the external variable errno set to EAGAIN. The receive calls normally return any data available,
sl@0: up to the requested amount,
sl@0: rather than waiting for receipt of the full amount requested;
sl@0: this behavior is affected by the socket-level options SO_RCVLOWAT and SO_RCVTIMEO described in getsockopt .
sl@0: 
sl@0:  The select system call may be used to determine when more data arrive.
sl@0: 
sl@0:  The flags argument to a recv function is formed by or Ap ing one or more of the values: MSG_OOB                process out-of-band data MSG_PEEK                peek at incoming message MSG_WAITALL                wait for full request or error MSG_DONTWAIT                do not block 
sl@0: 
sl@0:  The MSG_OOB flag requests receipt of out-of-band data
sl@0: that would not be received in the normal data stream.
sl@0: Some protocols place expedited data at the head of the normal
sl@0: data queue, and thus this flag cannot be used with such protocols.
sl@0: The MSG_PEEK flag causes the receive operation to return data
sl@0: from the beginning of the receive queue without removing that
sl@0: data from the queue.
sl@0: Thus, a subsequent receive call will return the same data.
sl@0: The MSG_WAITALL flag requests that the operation block until
sl@0: the full request is satisfied.
sl@0: The MSG_DONTWAIT flag requests the call to return when it would block otherwise.
sl@0: If no data is available, errno is set to EAGAIN.
sl@0: 
sl@0: The flags MSG_OOB, MSG_PEEK, MSG_WAITALL and MSG_DONTWAIT are not supported for 
sl@0: local sockets(AF_LOCAL, AF_LINUX etc..).
sl@0: 
sl@0:  The recvmsg system call uses a msghdr structure to minimize the number of directly supplied arguments.
sl@0: This structure has the following form, as defined in \#include \<sys/socket.h\>
sl@0: @code
sl@0:  struct msghdr {
sl@0: caddr_tmsg_name;/* optional address */
sl@0: u_intmsg_namelen;/* size of address */
sl@0: structiovec *msg_iov;/* scatter/gather array */
sl@0: u_intmsg_iovlen;/* # elements in msg_iov */
sl@0: caddr_tmsg_control;/* ancillary data, see below */
sl@0: u_intmsg_controllen; /* ancillary data buffer len */
sl@0: intmsg_flags;/* flags on received message */
sl@0: };
sl@0: @endcode
sl@0: 
sl@0:  Here msg_name and msg_namelen specify the destination address if the socket is unconnected; msg_name may be given as a null pointer if no names are desired or required.
sl@0: The msg_iov and msg_iovlen arguments
sl@0: describe scatter gather locations, as discussed in read .
sl@0: The msg_control argument,
sl@0: which has length msg_controllen, points to a buffer for other protocol control related messages
sl@0: or other miscellaneous ancillary data.
sl@0: The messages are of the form: 
sl@0: @code
sl@0: struct cmsghdr {
sl@0: u_intcmsg_len;/* data byte count, including hdr */
sl@0: intcmsg_level;/* originating protocol */
sl@0: intcmsg_type;/* protocol-specific type */
sl@0: /* followed by
sl@0: u_charcmsg_data[]; */
sl@0: };
sl@0: @endcode
sl@0: 
sl@0:  As an example, one could use this to learn of changes in the data-stream
sl@0: in XNS/SPP, or in ISO, to obtain user-connection-request data by requesting
sl@0: a recvmsg with no data buffer provided immediately after an accept system call.
sl@0: 
sl@0:  Open file descriptors are now passed as ancillary data for AF_UNIX domain sockets, with cmsg_level set to SOL_SOCKET and cmsg_type set to SCM_RIGHTS.
sl@0: 
sl@0:  Process credentials can also be passed as ancillary data for AF_UNIX domain sockets using a cmsg_type of SCM_CREDS. In this case, cmsg_data should be a structure of type cmsgcred, which is defined in \#include \<sys/socket.h\> as follows:
sl@0: @code
sl@0:  struct cmsgcred {
sl@0: pid_tcmcred_pid;/* PID of sending process */
sl@0: uid_tcmcred_uid;/* real UID of sending process */
sl@0: uid_tcmcred_euid;/* effective UID of sending process */
sl@0: gid_tcmcred_gid;/* real GID of sending process */
sl@0: shortcmcred_ngroups;/* number or groups */
sl@0: gid_tcmcred_groups[CMGROUP_MAX];/* groups */
sl@0: };
sl@0: @endcode
sl@0: 
sl@0:  The kernel will fill in the credential information of the sending process
sl@0: and deliver it to the receiver.
sl@0: 
sl@0:  The msg_flags field is set on return according to the message received. MSG_EOR indicates end-of-record; the data returned completed a record 
sl@0:   (generally used with sockets of type SOCK_SEQPACKET). MSG_TRUNC indicates that the trailing portion of a datagram was discarded 
sl@0:   because the datagram was larger than the buffer supplied. MSG_CTRUNC indicates that some control data were discarded due to 
sl@0:   lack of space in the buffer for ancillary data. MSG_OOB is returned to indicate that expedited or out-of-band data 
sl@0:   were received.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void Recv()
sl@0: {
sl@0:    struct sockaddr_in serv_addr;
sl@0:    int sock_fd;
sl@0:    char line[10];
sl@0:    int size = 10;
sl@0:    serv_addr.sin_family = AF_INET;
sl@0:    serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sl@0:    serv_addr.sin_port = htons(5000);
sl@0:    sock_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
sl@0:    connect(sock_fd,(struct sockaddr*)&serv;_addr,sizeof(serv_addr));
sl@0:    recv(sock_fd, line, size, 0);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void Sendto()
sl@0: {
sl@0:    struct sockaddr_in sender_addr;
sl@0:    int sock_fd;
sl@0:    char line[15] = "Hello World!";
sl@0:    unsigned int size = sizeof(sender_addr);
sl@0:    sock_fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
sl@0:    sender_addr.sin_family = AF_INET;
sl@0:    sender_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sl@0:    sender_addr.sin_port = htons(5000);
sl@0:    recvfrom(sock_fd,line,13,0,(struct sockaddr*)&sender;_addr,&size;);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void SendMsgRecvMsg()
sl@0: {
sl@0:    int sock_fd;
sl@0:    unsigned int sender_len;
sl@0:    struct msghdr msg;
sl@0:    struct iovec iov;
sl@0:    struct sockaddr_in receiver_addr,sender_addr;
sl@0:    char line[10];
sl@0:    sock_fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
sl@0:    receiver_addr.sin_family = AF_INET;
sl@0:    receiver_addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    receiver_addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(struct sockaddr*)&receiver;_addr,sizeof(receiver_addr));
sl@0:    sender_len = sizeof(sender_addr);
sl@0:    msg.msg_name = &sender;_addr;
sl@0:    msg.msg_namelen = sender_len;
sl@0:    msg.msg_iov = &iov;
sl@0:    msg.msg_iovlen = 1;
sl@0:    msg.msg_iov->iov_base = line;
sl@0:    msg.msg_iov->iov_len = 10;
sl@0:    msg.msg_control = 0;
sl@0:    msg.msg_controllen = 0;
sl@0:    msg.msg_flags = 0;
sl@0:    recvmsg(sock_fd,&msg;,0);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see fcntl()
sl@0: @see getsockopt()
sl@0: @see read()
sl@0: @see select()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  recvfrom(int s, void *  buf, size_t len, int flags, struct sockaddr *  from, socklen_t *  fromlen)
sl@0: @param s
sl@0: @param buf
sl@0: @param len
sl@0: @param flags
sl@0: @param from
sl@0: @param fromlen
sl@0: 
sl@0: Refer to recv() for the documentation
sl@0: 
sl@0: @see fcntl()
sl@0: @see getsockopt()
sl@0: @see read()
sl@0: @see select()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  recvmsg(int fd, struct msghdr *message, int flags)
sl@0: @param fd
sl@0: @param message
sl@0: @param flags
sl@0: 
sl@0: Refer to recv() for the documentation
sl@0: 
sl@0: @see fcntl()
sl@0: @see getsockopt()
sl@0: @see read()
sl@0: @see select()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  send(int fd, const void *buf, size_t cnt, int flags)
sl@0: @param fd
sl@0: @param buf
sl@0: @param cnt
sl@0: @param flags
sl@0: 
sl@0: Note: This description also covers the following functions -
sl@0:  sendto()  sendmsg() 
sl@0: 
sl@0:   The send function,
sl@0: and sendto and sendmsg system calls
sl@0: are used to transmit a message to another socket.
sl@0: The send function
sl@0: may be used only when the socket is in a connected state, while sendto and sendmsg may be used at any time.
sl@0: 
sl@0:  The address of the target is given by to with tolen specifying its size.
sl@0: The length of the message is given by len. If the message is too long to pass atomically through the
sl@0: underlying protocol, the error EMSGSIZE is returned, and
sl@0: the message is not transmitted.
sl@0: 
sl@0:  No indication of failure to deliver is implicit in a send. Locally detected errors are indicated by a return value of -1.
sl@0: 
sl@0:  If no messages space is available at the socket to hold
sl@0: the message to be transmitted, then send normally blocks, unless the socket has been placed in
sl@0: non-blocking I/O mode.
sl@0: The select system call may be used to determine when it is possible to
sl@0: send more data.
sl@0: 
sl@0:  The flags argument may include one or more of the following: 
sl@0: @code
sl@0: #defineMSG_OOB0x00001 //process out-of-band data 
sl@0: #defineMSG_PEEK0x00002 // peek at incoming message 
sl@0: #defineMSG_DONTROUTE0x00004 // bypass routing, use direct interface 
sl@0: #define MSG_EOR0x00008 // data completes record 
sl@0: #defineMSG_EOF0x00100 // data completes transaction
sl@0: @endcode
sl@0: 
sl@0:  The flag MSG_OOB is used to send "out-of-band"
sl@0: data on sockets that support this notion (e.g. SOCK_STREAM); the underlying protocol must also support "out-of-band"
sl@0: data. MSG_EOR is used to indicate a record mark for protocols which support the
sl@0: concept. MSG_EOF requests that the sender side of a socket be shut down, and that an
sl@0: appropriate indication be sent at the end of the specified data;
sl@0: this flag is only implemented for SOCK_STREAM sockets in the PF_INET protocol family, and is used to implement Transaction TCP MSG_DONTROUTE is usually used only by diagnostic or routing programs.
sl@0: 
sl@0:  See recv for a description of the msghdr structure.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void Recv()
sl@0: {
sl@0:    struct sockaddr_in serv_addr;
sl@0:    int sock_fd;
sl@0:    char line[15] = "Hello world!";
sl@0:    int size = 13;
sl@0:    serv_addr.sin_family = AF_INET;
sl@0:    serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sl@0:    serv_addr.sin_port = htons(5000);
sl@0:    sock_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
sl@0:    connect(sock_fd,(struct sockaddr*)&serv;_addr,sizeof(serv_addr));
sl@0:    send(sock_fd, line, size, 0);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void Sendto()
sl@0: {
sl@0:    sockaddr_in receiver_addr;
sl@0:    int sock_fd;
sl@0:    char line[15] = "Hello World!";
sl@0:    sock_fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
sl@0:    receiver_addr.sin_family = AF_INET;
sl@0:    receiver_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sl@0:    receiver_addr.sin_port = htons(5000);
sl@0:    sendto(sock_fd, line, 13, 0,(struct sockaddr*)&receiver;_addr,sizeof(receiver_addr));
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void sendmsg()
sl@0: {
sl@0:    struct sockaddr_in receiver_addr;
sl@0:    int sock_fd;
sl@0:    char line[15] = "Hello World!";
sl@0:    struct msghdr msg;
sl@0:    struct iovec iov;
sl@0:    sock_fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
sl@0:     
sl@0:    receiver_addr.sin_family = AF_INET;
sl@0:    receiver_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
sl@0:    receiver_addr.sin_port = htons(5000);
sl@0:    msg.msg_name = &receiver;_addr;
sl@0:    msg.msg_namelen = sizeof(receiver_addr);
sl@0:    msg.msg_iov = &iov;
sl@0:    msg.msg_iovlen = 1;
sl@0:    msg.msg_iov->iov_base = line;
sl@0:    msg.msg_iov->iov_len = 13;
sl@0:    msg.msg_control = 0;
sl@0:    msg.msg_controllen = 0;
sl@0:    msg.msg_flags = 0;
sl@0:    sendmsg(sock_fd,&msg;,0);
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @return   This function call returns the number of characters sent; otherwise the
sl@0: value -1 is returned and the global variable errno is set to indicate the
sl@0: error.
sl@0: 
sl@0: @see fcntl()
sl@0: @see getsockopt()
sl@0: @see recv()
sl@0: @see select()
sl@0: @see socket()
sl@0: @see write()
sl@0: 
sl@0: 
sl@0: Bugs:
sl@0: 
sl@0:  Because sendmsg does not necessarily block until the data has been transferred, it
sl@0: is possible to transfer an open file descriptor across an AF_UNIX domain socket
sl@0: (see recv then close it before it has actually been sent, the result being that the receiver
sl@0: gets a closed file descriptor.
sl@0: It is left to the application to
sl@0: implement an acknowledgment mechanism to prevent this from happening. 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
sl@0: @param s
sl@0: @param msg
sl@0: @param len
sl@0: @param flags
sl@0: @param to
sl@0: @param tolen
sl@0: 
sl@0: Refer to  send() for the documentation
sl@0: 
sl@0: @see fcntl()
sl@0: @see getsockopt()
sl@0: @see recv()
sl@0: @see select()
sl@0: @see socket()
sl@0: @see write()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  sendmsg(int fd, const struct msghdr *message, int flags)
sl@0: @param fd
sl@0: @param message
sl@0: @param flags
sl@0: 
sl@0: Refer to  send() for the documentation
sl@0: 
sl@0: @see fcntl()
sl@0: @see getsockopt()
sl@0: @see recv()
sl@0: @see select()
sl@0: @see socket()
sl@0: @see write()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
sl@0: @param s
sl@0: @param level
sl@0: @param optname
sl@0: @param optval
sl@0: @param optlen
sl@0: 
sl@0: Refer to  getsockopt() for the documentation
sl@0: 
sl@0: @see ioctl()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0: Note:For multicast to work on Symbian OS the connection for the interface needs to be started first.
sl@0: On most of the desktop Operating Systems,the network interface is always running, so things like setsockopt() will always pass.
sl@0: But on Symbian, the interface is not always running (in order to save battery and/or data charges) so some options in setsockopt() will not work until the connection is started.
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  shutdown(int fd, int how)
sl@0: @param fd
sl@0: @param how
sl@0: @return   The shutdown() function returns the value 0 if successful; otherwise the
sl@0: value -1 is returned and the global variable errno is set to indicate the
sl@0: error.
sl@0: 
sl@0: @code
sl@0:  SHUT_RD further receives will be disallowed.
sl@0:  SHUT_WR further sends will be disallowed.
sl@0:  SHUT_RDWR
sl@0:   further sends and receives will be disallowed.
sl@0: 
sl@0: @endcode
sl@0:   The shutdown system call causes all or part of a full-duplex connection on
sl@0: the socket associated with the file descriptor sockfd to be shut down.
sl@0: The how argument specifies the type of shutdown.
sl@0: Possible values are: SHUT_RD further receives will be disallowed. SHUT_WR further sends will be disallowed. SHUT_RDWR  further sends and receives will be disallowed.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: TInt shutdown_example()
sl@0: {
sl@0:    int sock_fd;
sl@0:    sockaddr_in addr,ss;
sl@0:    unsigned int len;   
sl@0:    
sl@0:    sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sl@0:        
sl@0:    addr.sin_family = AF_INET;
sl@0:    addr.sin_addr.s_addr = htonl(INADDR_ANY);
sl@0:    addr.sin_port = htons(5000);
sl@0:    bind(sock_fd,(sockaddr*)&addr;,sizeof(addr));
sl@0:    shutdown(sock_fd, SHUT_RD)
sl@0:    close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see connect()
sl@0: @see socket()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @fn  sockatmark(int s)
sl@0: @param s
sl@0: @return   Upon successful completion, the sockatmark function returns the value 1 if the read pointer is pointing at
sl@0: the OOB mark, 0 if it is not.Otherwise the value -1 is returned
sl@0: and the global variable errno is set to indicate the error.
sl@0: 
sl@0:   To find out if the read pointer is currently pointing at
sl@0: the mark in the data stream, the sockatmark function is provided.
sl@0: If sockatmark returns 1, the next read will return data
sl@0: after the mark.
sl@0: Otherwise (assuming out of band data has arrived),
sl@0: the next read will provide data sent by the client prior
sl@0: to transmission of the out of band signal.
sl@0: The routine used
sl@0: in the remote login process to flush output on receipt of an
sl@0: interrupt or quit signal is shown below.
sl@0: It reads the normal data up to the mark (to discard it),
sl@0: then reads the out-of-band byte. 
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: oob()
sl@0: {
sl@0: int out = FWRITE, mark;
sl@0: char waste[BUFSIZ];
sl@0: /* flush local terminal output */
sl@0: ioctl(1, TIOCFLUSH, (char *)&out;);
sl@0: for (;;) {
sl@0: if ((mark = sockatmark(rem)) < 0) {
sl@0: perror("sockatmark");
sl@0: break;
sl@0: }
sl@0: if (mark)
sl@0: break;
sl@0: (void) read(rem, waste, sizeof (waste));
sl@0: }
sl@0: if (recv(rem, &mark;, 1, MSG_OOB) < 0) {
sl@0: perror("recv");
sl@0: ...
sl@0: }
sl@0: ...
sl@0: }
sl@0: @endcode
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <netinet/in.h>
sl@0: #include <unistd.h>
sl@0: void SockAtMark()
sl@0: {
sl@0:    int sockfd;
sl@0:    sockaddr_in selfAddr;
sl@0:    sockfd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
sl@0:        
sl@0:    selfAddr.sin_family = AF_INET;
sl@0:    selfAddr.sin_addr.s_addr = INADDR_ANY;
sl@0:    selfAddr.sin_port = htons(5000);
sl@0:    bind(sockfd,(struct sockaddr*)&selfAddr;, sizeof(selfAddr));
sl@0:    sockatmark(sockfd);
sl@0:    close(sockfd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see recv()
sl@0: @see send()
sl@0: @see ioctl()
sl@0: 
sl@0: 
sl@0:  
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @fn  socket(int family, int style, int protocol)
sl@0: @param family
sl@0: @param style
sl@0: @param protocol
sl@0: @return   The socket() function returns valid socket descriptor if successful; otherwise the
sl@0: value -1 is returned and the global variable errno is set to indicate the
sl@0: error.
sl@0: 
sl@0:   The socket system call
sl@0: creates an endpoint for communication and returns a descriptor.
sl@0: 
sl@0:  The family argument specifies a communications domain within which communication 
sl@0:   will take place; this selects the protocol family which should be used. These 
sl@0:   families are defined in the include file \#include \<sys/socket.h\> The currently understood formats 
sl@0:   are:
sl@0: 
sl@0:  PF_LOCALHost-internal protocols, formerly called PF_UNIX,
sl@0: PF_INETInternet version 4 protocols,
sl@0: 
sl@0:  The socket has the indicated style, which specifies the semantics of communication.
sl@0: Currently
sl@0: defined types are:
sl@0: 
sl@0: @code
sl@0: 
sl@0: SOCK_STREAMStream socket,
sl@0: SOCK_DGRAMDatagram socket,
sl@0: SOCK_SEQPACKETSequenced packet stream
sl@0: 
sl@0: @endcode
sl@0: 
sl@0:  A SOCK_STREAM type provides sequenced, reliable,
sl@0: two-way connection based byte streams.
sl@0: An out-of-band data transmission mechanism may be supported.
sl@0: A SOCK_DGRAM socket supports
sl@0: datagrams (connectionless, unreliable messages of
sl@0: a fixed (typically small) maximum length).
sl@0: A SOCK_SEQPACKET socket may provide a sequenced, reliable,
sl@0: two-way connection-based data transmission path for datagrams
sl@0: of fixed maximum length; a consumer may be required to read
sl@0: an entire packet with each read system call.
sl@0: This facility is protocol specific, and presently unimplemented.
sl@0: 
sl@0:  The protocol argument
sl@0: specifies a particular protocol to be used with the socket.
sl@0: Normally only a single protocol exists to support a particular
sl@0: socket type within a given protocol family.
sl@0: However, it is possible
sl@0: that many protocols may exist, in which case a particular protocol
sl@0: must be specified in this manner.
sl@0: The protocol number to use is
sl@0: particular to the "communication domain"
sl@0: in which communication
sl@0: is to take place.
sl@0: 
sl@0:  Sockets of type SOCK_STREAM are full-duplex byte streams, similar
sl@0: to pipes.
sl@0: A stream socket must be in a connected state before any data may be sent or received
sl@0: on it.
sl@0: A connection to another socket is created with a connect system call.
sl@0: Once connected, data may be transferred using read and write calls or some variant of the send and recv functions.
sl@0: (Some protocol families, such as the Internet family,
sl@0: support the notion of an "implied connect,"
sl@0: which permits data to be sent piggybacked onto a connect operation by
sl@0: using the sendto system call.)
sl@0: When a session has been completed a close may be performed.
sl@0: Out-of-band data may also be transmitted as described in send and received as described in recv
sl@0: 
sl@0:  The communications protocols used to implement a SOCK_STREAM insure that data
sl@0: is not lost or duplicated.
sl@0: If a piece of data for which the
sl@0: peer protocol has buffer space cannot be successfully transmitted
sl@0: within a reasonable length of time, then
sl@0: the connection is considered broken and calls
sl@0: will indicate an error with
sl@0: -1 returns and with ETIMEDOUT as the specific code
sl@0: in the global variable errno. The protocols optionally keep sockets "warm"
sl@0: by forcing transmissions
sl@0: roughly every minute in the absence of other activity.
sl@0: An error is then indicated if no response can be
sl@0: elicited on an otherwise
sl@0: idle connection for an extended period (e.g. 5 minutes).
sl@0: 
sl@0:  SOCK_SEQPACKET sockets employ the same system calls as SOCK_STREAM sockets. The only difference is that read calls will return only the amount of data 
sl@0:   requested and any remaining in the arriving packet will be discarded.
sl@0: 
sl@0:  SOCK_DGRAM sockets allow sending of datagrams to correspondents named 
sl@0:   in send calls. Datagrams are generally received 
sl@0:   with recvfrom which returns the next datagram with 
sl@0:   its return address.
sl@0: 
sl@0: Examples:
sl@0: @code
sl@0: #include <sys/socket.h>
sl@0: #include <unistd.h>
sl@0: #include <stdio.h>
sl@0: #inlcude <netinet/in.h>
sl@0: void SocketExample()
sl@0: {
sl@0:     int sock_fd;
sl@0:     sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
sl@0:     close(sock_fd);
sl@0: }
sl@0: 
sl@0: @endcode
sl@0: @see accept()
sl@0: @see bind()
sl@0: @see connect()
sl@0: @see getpeername()
sl@0: @see getsockname()
sl@0: @see getsockopt()
sl@0: @see ioctl()
sl@0: @see listen()
sl@0: @see read()
sl@0: @see recv()
sl@0: @see select()
sl@0: @see send()
sl@0: @see shutdown()
sl@0: @see write()
sl@0: 
sl@0: 
sl@0: 
sl@0: @capability Deferred @ref RSocket::Open(RSocketServ &,TUint,TUint,TUint)
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @typedef typedef	__sa_family_t	sa_family_t
sl@0: 
sl@0: Address family type
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @typedef typedef	__socklen_t	socklen_t
sl@0: 
sl@0: Socket address length type.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @struct sockaddr
sl@0: 
sl@0: Structure used by kernel to store most addresses.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @var sockaddr::sa_len
sl@0: total length 
sl@0: */
sl@0: 
sl@0: /** @var sockaddr::sa_family
sl@0: address family 
sl@0: */
sl@0: 
sl@0: /** @var sockaddr::sa_data
sl@0: actually longer; address value
sl@0: */
sl@0: 
sl@0: /** @struct cmsghdr
sl@0: 
sl@0: Header for ancillary data objects in msg_control buffer.
sl@0: Used for additional information with/about a datagram not expressible by flags.  
sl@0: The format is a sequence of message elements headed by cmsghdr structures.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @var cmsghdr::cmsg_len
sl@0: data byte count, including hdr
sl@0: */
sl@0: 
sl@0: /** @var cmsghdr::cmsg_level
sl@0: originating protocol
sl@0: */
sl@0: 
sl@0: /** @var cmsghdr::cmsg_type
sl@0: protocol-specific type
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @struct msghdr
sl@0: 
sl@0: Message header for recvmsg and sendmsg calls.
sl@0: Used value-result for recvmsg, value only for sendmsg.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_name
sl@0: optional address
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_namelen
sl@0: size of address 
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_iov
sl@0: scatter or gather array
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_iovlen
sl@0: x elements in msg_iov 
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_control
sl@0: ancillary data, see below
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_controllen
sl@0: ancillary data buffer len 
sl@0: */
sl@0: 
sl@0: /** @var msghdr::msg_flags
sl@0: flags on received message
sl@0: */
sl@0: 
sl@0: /** @def CMSG_DATA(cmsg)
sl@0: 
sl@0: given pointer to struct cmsghdr, return pointer to data
sl@0: 	
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def CMSG_NXTHDR(mhdr, cmsg)
sl@0: 
sl@0: given pointer to struct cmsghdr, return pointer to next cmsghdr
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def CMSG_FIRSTHDR(mhdr)
sl@0: 
sl@0: RFC 2292 requires to check msg_controllen, in case that the kernel returns an empty list for some reasons.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @struct linger
sl@0: 
sl@0: Structure used for manipulating linger option.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @var linger::l_onoff
sl@0: option on or off
sl@0: */
sl@0: 
sl@0: /** @var linger::l_linger
sl@0: linger time 
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def AF_UNIX
sl@0: 
sl@0: local to host (pipes, portals) 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 	
sl@0: /** @def AF_INET	
sl@0: 
sl@0: internetwork: UDP, TCP, etc.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def AF_UNSPEC
sl@0: 
sl@0: Address family. Unspecified.
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SHUT_RD	
sl@0: 
sl@0: shut down the reading side
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SHUT_WR
sl@0: 
sl@0: shut down the writing side 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SHUT_RDWR
sl@0: 
sl@0: shut down both sides
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def MSG_OOB	
sl@0: 
sl@0: process out-of-band data
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def MSG_PEEK
sl@0: 
sl@0: peek at incoming message
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def MSG_DONTROUTE
sl@0: 
sl@0: send without using routing tables 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def MSG_EOR
sl@0: 
sl@0: data completes record
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def MSG_TRUNC
sl@0: 
sl@0: data discarded before delivery 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def MSG_CTRUNC
sl@0: 
sl@0: control data lost before delivery 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def MSG_WAITALL
sl@0: 
sl@0: wait for full request or error
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_ACCEPTCONN	
sl@0: 
sl@0: socket has had listen() 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_BROADCAST
sl@0: 
sl@0: permit sending of broadcast msgs
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def SO_DEBUG
sl@0: 
sl@0: turn on debugging info recording KSODebug 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_DONTROUTE
sl@0: 
sl@0: just use interface addresses
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_ERROR
sl@0: 
sl@0: get error status and clear
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_KEEPALIVE
sl@0: 
sl@0: keep connections alive KSoTcpKeepAlive 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_LINGER
sl@0: 
sl@0: linger on close if data present
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_OOBINLINE
sl@0: 
sl@0: leave received OOB data in line KSoTcpOobInline
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def SO_RCVBUF
sl@0: 
sl@0: receive buffer size KSORecvBuf 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_RCVLOWAT
sl@0: 
sl@0: receive low-water mark
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_RCVTIMEO
sl@0: 
sl@0: receive timeout
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_REUSEADDR
sl@0: 
sl@0: Allow a socket to be bound to an local address that is already in use. 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def SO_SNDBUF
sl@0: 
sl@0: send buffer size KSOSendBuf 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_SNDLOWAT
sl@0: 
sl@0: send low-water mark
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SO_SNDTIMEO
sl@0: 
sl@0: send timeout
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def SO_TYPE	
sl@0: 
sl@0: get socket type 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SOCK_DGRAM
sl@0: 
sl@0: datagram socket
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SOCK_STREAM
sl@0: 
sl@0: stream socket
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: /** @def SOCK_SEQPACKET
sl@0: 
sl@0: sequenced packet stream 
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def SOL_SOCKET
sl@0: 
sl@0: options for socket level KSOLSocket
sl@0: 
sl@0: @publishedAll
sl@0: @externallyDefinedApi
sl@0: */
sl@0: 
sl@0: 
sl@0: /** @def SOCK_RAW
sl@0: 
sl@0: raw-protocol interface
sl@0: 
sl@0: @publishedAll
sl@0: @released
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: 
sl@0: