ISocket.socket

Creates a socket endpoint for communication and sets this.fd to the corresponding file descriptor.

class ISocket
int
socket
(
int domain
,
int type
,
int protocol = 0
)

Parameters

domain int

The desired socket domain. The domain argument specifies a communication domain; this sel- ects the protocol family which will be used for communication. These families are defined in <sys/socket.h>. The currently understood formats include

Name Purpose Man page AF_UNIX, AF_LOCAL Local communication unix(7) AF_INET IPv4 Internet protocols ip(7) AF_INET6 IPv6 Internet protocols ipv6(7) AF_IPX IPX - Novell protocols AF_NETLINK Kernel user interface device netlink(7) AF_X25 ITU-T X.25 / ISO-8208 protocol x25(7) AF_AX25 Amateur radio AX.25 protocol AF_ATMPVC Access to raw ATM PVCs AF_APPLETALK AppleTalk ddp(7) AF_PACKET Low level packet interface packet(7)

type int

desired socket type, which specifies the communication semantics. Supported types are

SOCK_STREAM Provides sequenced, reliable, two-way, connec‐ tion-based byte streams. An out-of-band data transmission mechanism may be supported.

SOCK_DGRAM Supports datagrams - connectionless, unreliable messages of a fixed maximum length.

SOCK_SEQPACKET Provides a sequenced, reliable, two-way connec‐ tion-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each input system call.

SOCK_RAW Provides raw network protocol access.

Some socket types may not be implemented by all protocol fami‐ lies; for example, SOCK_SEQPACKET is not implemented for AF_INET (IPv4).

Since Linux 2.6.27, the type argument serves a second purpose: in addition to specifying a socket type, it may include the bit‐ wise OR of any of the following values, to modify the behavior of socket():

SOCK_NONBLOCK Set the O_NONBLOCK file status flag on the new open file description. Using this flag saves extra calls to fcntl(2) to achieve the same result.

SOCK_CLOEXEC Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. See the description of the O_CLOEXEC flag in open(2) for reasons why this may be useful.

protocol int

desired protocol or 0 to use the default protocol for the specified type (e.g. TCP for type == SOCK_STREAM or UDP for

Return Value

Type: int

the socket file descriptor on success or -1 on failure. On failure errno is set appropriately and this.fd is -1.

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

EAFNOSUPPORT The implementation does not support the specified address family.

EINVAL Unknown protocol, or protocol family not available.

EINVAL Invalid flags in type.

EMFILE Process file table overflow.

ENFILE The system limit on the total number of open files has been reached.

ENOBUFS or ENOMEM Insufficient memory is available. The socket cannot be cre‐ ated until sufficient resources are freed.

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

Other errors may be generated by the underlying protocol modules.

Meta