IIPSocket.socket

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

  1. alias socket = ISocket.socket
  2. int socket(int type, int protocol)
    class IIPSocket
    int
    socket
    (
    int type
    ,
    int protocol = 0
    )

Parameters

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