Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ socket(2) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

accept

bind

getsockname

getsockopt, setsockopt

ioctlx, ioctl, gtty, stty

listen

recv, recvfrom, recvmsg

select

send, sendto, sendmsg

shutdown

connect

socketpair



SOCKET(2,L)                 AIX Technical Reference                 SOCKET(2,L)



-------------------------------------------------------------------------------
socket



PURPOSE

Creates an endpoint for communication and returns a descriptor.

SYNTAX

#include <sys/types.h>
#include <sys/socket.h>

int socket  (domain, type, protocol)
int domain, type, protocol;

DESCRIPTION

The socket system call creates an endpoint for communication and returns a
socket descriptor.

The domain parameter specifies a communications domain within which
communication will take place; this selects the protocol family which should be
used.  The protocol family generally is the same as the address format for the
addresses supplied in later operations on the socket.  These formats are
defined in the sys/socket.h header file.  The formats are:

AF_UNIX   AIX path names
AF_INET   ARPA Internet addresses.

The value of the type parameter specifies the semantics of communication.  AIX
supports these types:

SOCK_STREAM   Provides sequenced, two-way byte streams with a transmission
              mechanism for out-of-band data.
SOCK_DGRAM    Provides datagrams, which are connectionless messages of a fixed
              maximum length (usually small).

The protocol parameter specifies a particular protocol to be used with the
socket.  In most cases, a single protocol exists to support a particular socket
type using a given address format.  When many protocols exist, you must specify
a particular protocol.  Use the number for the communication domain in which
the communication takes place.

The different types of sockets available are used for different purposes.
SOCK_DGRAM sockets allow sending datagrams to correspondents named in send
socket calls.  Programs can also receive datagrams via sockets by using the
recv system call.

SOCK_STREAM sockets are full-duplex byte streams.  A stream socket must be
connected before any data may be sent or received on it.  Create a connection



Processed November 7, 1990        SOCKET(2,L)                                 1





SOCKET(2,L)                 AIX Technical Reference                 SOCKET(2,L)



to another socket with the connect system call.  Once connected, use the read
and write system calls, or the send and recv system calls to transfer data.
Issue the close system call when a session is finished.  Use the send and recv
system calls for out-of-band data.

SOCK_STREAM communications protocols are designed to prevent the loss or
duplication of data.  If a piece of data for which the peer protocol has buffer
space cannot be successfully transmitted within a reasonable period of time,
the connection is broken.  When this occurs, the socket system calls indicate
an error with a return value of -1 and with ETIMEDOUT as the specific code
written to the global variable errno.  If a process sends on a broken stream, a
SIGPIPE signal is raised.  Processes that cannot handle the signal terminate.

An fcntl system call can be used to specify a process group to receive a SIGURG
signal when out-of-band data arrives on a socket.  It may also be used to
enable non-blocking I/O and asynchronous notification of I/O events via the
SIGIO signal.

The operation of sockets is controlled by socket level options.  The getsockopt
and setsockopt system calls are used to get and set these options, which are
defined in the sys/socket.h file.  See "getsockopt, setsockopt" for information
on how to use these options.

RETURN VALUE

Upon successful completion, a descriptor referring to the socket is returned.
If the socket system call fails, a value of -1 is returned, and errno is set to
indicate the error.

ERROR CONDITIONS

The system call fails if one or more of the following are true:

EPROTONOSUPPORT
          The protocol type or the specified protocol is not supported within
          this domain.

EMFILE    The per-process descriptor table is full.

ENOBUFS   Insufficient resources were available in the system to complete the
          call.

ENFILE    The system file table is full.

EACCES    Permission to create a socket of the specified type and/or protocol
          is denied.

RELATED INFORMATION

In this book:  "accept," "bind," "getsockname," "getsockopt, setsockopt,"
"ioctlx, ioctl, gtty, stty," "listen," "recv, recvfrom, recvmsg," "select,"
"send, sendto, sendmsg," "shutdown," "connect," and "socketpair."



Processed November 7, 1990        SOCKET(2,L)                                 2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026