Utility functions for accessing system functionality.

Methods
Constants
UNIX_PATH_MAX = INT2NUM(sizeof(addr.sun_path))
  The maximum length of a Unix socket path, including terminating null.
Public Class methods
accept(fileno)

Accept a new client from the given socket.

  • fileno (integer): The file descriptor of the server socket.
  • Returns: The accepted client‘s file descriptor.
  • Raises SystemCallError if something went wrong.
/*
 * call-seq: accept(fileno)
 *
 * Accept a new client from the given socket.
 *
 * - +fileno+ (integer): The file descriptor of the server socket.
 * - Returns: The accepted client's file descriptor.
 * - Raises +SystemCallError+ if something went wrong.
 */
static VALUE
f_accept(VALUE self, VALUE fileno) {

close_all_file_descriptors(exceptions)

Close all file descriptors, except those given in the exceptions array. For example, the following would close all file descriptors except standard input (0) and standard output (1).

 close_all_file_descriptors([0, 1])
/*
 * call-seq: close_all_file_descriptors(exceptions)
 *
 * Close all file descriptors, except those given in the +exceptions+ array.
 * For example, the following would close all file descriptors except standard
 * input (0) and standard output (1).
 *
 *  close_all_file_descriptors([0, 1])
 */
static VALUE
close_all_file_descriptors(VALUE self, VALUE exceptions) {

create_unix_socket(filename, backlog)

Create a SOCK_STREAM server Unix socket. Unlike Ruby‘s UNIXServer class, this function is also able to create Unix sockets on the abstract namespace by prepending the filename with a null byte.

  • filename (string): The filename of the Unix socket to create.
  • backlog (integer): The backlog to use for listening on the socket.
  • Returns: The file descriptor of the created Unix socket, as an integer.
  • Raises SystemCallError if something went wrong.
/*
 * call-seq: create_unix_socket(filename, backlog)
 *
 * Create a SOCK_STREAM server Unix socket. Unlike Ruby's UNIXServer class,
 * this function is also able to create Unix sockets on the abstract namespace
 * by prepending the filename with a null byte.
 *
 * - +filename+ (string): The filename of the Unix socket to create.
 * - +backlog+ (integer): The backlog to use for listening on the socket.
 * - Returns: The file descriptor of the created Unix socket, as an integer.
 * - Raises +SystemCallError+ if something went wrong.
 */
static VALUE
create_unix_socket(VALUE self, VALUE filename, VALUE backlog) {

disable_stdio_buffering

Disables any kind of buffering on the C stdout and stderr variables, so that +fprintf()+ on stdout and stderr have immediate effect.

/*
 * call-seq: disable_stdio_buffering
 *
 * Disables any kind of buffering on the C +stdout+ and +stderr+ variables,
 * so that +fprintf()+ on +stdout+ and +stderr+ have immediate effect.
 */
static VALUE
disable_stdio_buffering() {

recv_fd(socket_fd)

Receive a file descriptor from the given Unix socket. Returns the received file descriptor as an integer. Raises SystemCallError if something went wrong.

You do not have call this method directly. A convenience wrapper is provided by IO#recv_io.

/*
 * call-seq: recv_fd(socket_fd)
 *
 * Receive a file descriptor from the given Unix socket. Returns the received
 * file descriptor as an integer. Raises +SystemCallError+ if something went
 * wrong.
 *
 * You do not have call this method directly. A convenience wrapper is
 * provided by IO#recv_io.
 */
static VALUE
recv_fd(VALUE self, VALUE socket_fd) {

send_fd(socket_fd, fd_to_send)

Send a file descriptor over the given Unix socket. You do not have to call this function directly. A convenience wrapper is provided by IO#send_io.

  • socket_fd (integer): The file descriptor of the socket.
  • fd_to_send (integer): The file descriptor to send.
  • Raises SystemCallError if something went wrong.
/*
 * call-seq: send_fd(socket_fd, fd_to_send)
 *
 * Send a file descriptor over the given Unix socket. You do not have to call
 * this function directly. A convenience wrapper is provided by IO#send_io.
 *
 * - +socket_fd+ (integer): The file descriptor of the socket.
 * - +fd_to_send+ (integer): The file descriptor to send.
 * - Raises +SystemCallError+ if something went wrong.
 */
static VALUE
send_fd(VALUE self, VALUE socket_fd, VALUE fd_to_send) {