SOCKET [ Berkeley Sockets/iX Reference Manual ] MPE/iX 5.0 Documentation
Berkeley Sockets/iX Reference Manual
SOCKET
C Interface
#include <sys/types.h>
#include <sys/socket.h>
int socket(af, type, protocol)
int af, type, protocol;
Description
The socket call creates an endpoint for communication and returns a
descriptor. The socket descriptor returned is used in all subsequent
socket-related system calls.he af parameter specifies an address family
to be used to interpret addresses in later operations that specify the
socket. These address families are defined in the include file
<sys/socket.h>. The only currently supported address families are as
follows:
AF_INET (DARPA Internet addresses)
AF_UNIX (directory path names on a local node)
NOTE If you do not have a supported networking link product installed on
your system and you attempt to use the address family AF_INET, then
the EAFNOSUPPORT error is returned.
The AF_UNIX address family can be used to create socket connections
without requiring a networking link product to be installed.
The type parameter specifies the communication semantics for the socket.
Currently defined types are as follows:
SOCK_STREAM
SOCK_DGRAM
A SOCK_STREAM type provides sequenced, reliable, two-way,
connection-based byte streams. A SOCK_DGRAM socket supports datagrams,
which are connection-less, unreliable messages of a fixed, typically
small, maximum length.
The protocol parameter specifies a particular protocol to be used with
the socket. The protocol number to use depends on the communication
domain in which communication is to take place. (Refer to the chapter on
name services routines.) Protocol can be supplied as zero, in which case
the system chooses a protocol type to use, based on the socket type.
Sockets of type SOCK_STREAM are byte streams similar to UNIX pipes,
except that they are full-duplex instead of half-duplex. A stream socket
must be in a connected state before any data can be sent or received on
it. A connection to another socket is created with a connect or accept
call. Once connected, data can be transferred using send and recv calls
or read and write calls. When a session has been completed, a close can
be performed.
The communications protocol (TCP) used to implement SOCK_STREAM for
AF_INET sockets, ensures that data is not lost or duplicated. If a peer
has buffer space for data and the data cannot be successfully transmitted
within a reasonable length of time, the connection is considered broken
and the next recv call indicates an error with errno set to ETIMEDOUT. An
end-of-file condition (zero bytes read) is returned if a process tries to
read on a broken stream. To use the errno global variable, include the
file <sys/errno.h>.
SOCK_DGRAM sockets allow sending of messages to correspondents named in
sendto calls. It is also possible to receive messages at a SOCK_DGRAM
socket with recvfrom. The sockets operation is controlled by socket
level options set by the setsockopt system call. (Refer to getsockopt or
setsockopt.) These options are defined in the file <sys/socket.h>.
Return Value
If the call is successful, a valid file descriptor referencing the socket
is returned. If it fails, a -1 is returned, and an error code is stored
in errno.
Errors
The following errors are returned by socket:
[EHOSTDOWN] The networking subsystem has not been started.
[EAFNOSUPPORT] The specified address family is not supported
on this version of the system.
[ESOCKTNOSUPPORT] The specified socket type is not supported in
this address family.
[EPROTONOSUPPORT] The specified protocol is not supported.
[EMFILE] The per-process descriptor table is full.
[ENOBUFS] No buffer space is available. The socket
cannot be created.
[ENFILE] The system's table of open files is temporarily
full, and no more socket calls can be accepted.
[EPROTOTYPE] The type of socket and protocol do not match.
[ETIMEDOUT] The connection timed out.
MPE/iX Specific
Break mode is supported on MPE/iX. This is true of all Berkeley
Sockets/iX system calls described in this section.
Author
UCB (University of California at Berkeley)
MPE/iX 5.0 Documentation