Module irccd.socket

Sockets.

This API provides support for low level sockets. It currently suports AF_INET, AF_INET6 and AF_LOCAL (on Unix only).

Functions

new (family, type) Create a new socket.

Tables

family Socket address family
type Socket type
protocol Socket protocol

Class Socket

Socket:accept () Accept a client.
Socket:bind (address) Bind to an address.
Socket:blockMode (mode) Set the blocking mode.
Socket:close () Close the socket.
Socket:connect (address) Connect to an end point.
Socket:listen (count) Listen to a number of pending connections.
Socket:receive (howmany) Receive some data.
Socket:receiveFrom (howmany, from) Receive some data.
Socket:send (data) Send some data.
Socket:send (data, address) Send some data.
Socket:set (level, name, arg) Set an option.


Functions

new (family, type)
Create a new socket.

Parameters:

  • family one of the irccd.socket.family
  • type one of the irccd.socket.type

Returns:

  1. the created socket or nil
  2. the error message

Tables

family
Socket address family

Fields:

  • Inet AF_INET (IPv4) family.
  • Inet6 AF_INET6 (IPv6) family.
  • Unix AF_LOCAL (Unix) family, only on Unix.
type
Socket type

Fields:

  • Stream SOCK_STREAM sockets
  • Datagram SOCK_DGRAM sockets
protocol
Socket protocol

Fields:

  • Tcp IPPROTO_TCP
  • Udp IPPROTO_UDP
  • IPv4 IPPROTO_IPV4
  • IPv6 IPPROTO_IPv6

Class Socket

Socket:accept ()
Accept a client.

Returns:

  1. the accepted socket (or nil)
  2. the socket information (or nil)
  3. the error message if any
Socket:bind (address)

Bind to an address. As a convenience, this function may accept nil plus the error message for chained expression like:

s:bind(address.unix("/tmp/file.sock"))

Parameters:

  • address the address

Returns:

  1. true on success
  2. the error message

See also:

Socket:blockMode (mode)
Set the blocking mode.

Parameters:

  • mode the mode

Returns:

  1. true on success
  2. the error message
Socket:close ()
Close the socket. This function is required when you have finished using the socket, the __gc metamethod will not close the socket.
Socket:connect (address)
Connect to an end point. Like Socket:bind, you can pass nil plus an error message as parameters.

Parameters:

  • address the address

Returns:

  1. true on success
  2. the error message

See also:

Socket:listen (count)
Listen to a number of pending connections.

Parameters:

  • count an optional count, default: 64.

Returns:

  1. true on success
  2. the error message
Socket:receive (howmany)
Receive some data. Get some data as a stream mode.

Parameters:

  • howmany how much to receive

Returns:

  1. the read string or nil
  2. the error message
Socket:receiveFrom (howmany, from)
Receive some data. Get some data from a peer, typically UDP.

Parameters:

  • howmany how much to receive
  • from the address from

Returns:

  1. the read string or nil
  2. the error message

See also:

Socket:send (data)
Send some data. This function sends data to a stream based socket.

Parameters:

  • data the data

Returns:

  1. the number of bytes sent or nil
  2. the error message
Socket:send (data, address)
Send some data. This function sends data to a datagram based socket

Parameters:

  • data the data
  • address where to send

Returns:

  1. the number of bytes sent or nil
  2. the error message

See also:

Socket:set (level, name, arg)
Set an option. This function is a wrapper around the setsockopt function. Level and name are string which may refer to the following:

Levels available:

  • socket: the SOL_SOCKET level
  • tcp: the IPPROTO_TCP level
  • ipv6: the IPPROTO_IPV6 level

The following options belong to socket level:

  • reuse-address: bool, reuse the address.
  • broadcast: bool, sending broadcast data
  • debug: bool, print debug information
  • keep-alive: bool, enable sending keep alive packets


The following options belong to tcp level:

  • no-delay: bool, Disables the Nagle algorithm for send coalescing


The following options belong to ipv6 level:

  • v6only: bool, disable or enable the IPv6 mode only

Parameters:

  • level the level
  • name the name
  • arg the argument (depend on above)

Returns:

  1. true on success or nil
  2. the error message

Usage:

    s:set("socket", "reuse-address", true)
generated by LDoc 1.4.0