Unix Domain Sockets
unix-socket-available?
unix-socket-connect
unix-socket-path?
unix-socket-listen
unix-socket-listener?
unix-socket-close-listener
unix-socket-accept
unix-socket-accept-evt
7.9.0.4

Unix Domain Sockets

Ryan Culpepper <ryanc@racket-lang.org>

 (require racket/unix-socket) package: unix-socket-lib

This library provides support for unix domain sockets (specifically, sockets with family AF_UNIX and type SOCK_STREAM).

A boolean value that indicates whether unix domain sockets are available and supported on the current platform. The supported platforms are Linux, Mac OS X, and variants of BSD. This library does not currently support other Unix variants, and Windows does not have unix domain sockets.

procedure

(unix-socket-connect socket-path)  
input-port? output-port?
  socket-path : unix-socket-path?
Connects to the unix domain socket associated with socket-path and returns an input port and output port for communicating with the socket. The connection is closed when both ports are closed.

procedure

(unix-socket-path? v)  boolean?

  v : any/c
Returns #t if v is a valid unix domain socket path for the current system. There are two kinds of socket paths: filesystem paths and abstract socket names.

Otherwise, returns #f.

procedure

(unix-socket-listen socket-path [backlog])  unix-socket-listener?

  socket-path : unix-socket-path?
  backlog : exact-nonnegative-integer? = 4
Listen for connections on a unix domain socket bound to socket-path, returning a listener that can be used to accept incoming connections.

If socket-path refers to a filesystem path, binding the socket creates a file that must be deleted separately from closing the listener.

procedure

(unix-socket-listener? v)  boolean?

  v : any/c
Returns #t if v is a unix socket listener created with unix-socket-listen; #f otherwise.

A unix socket listener acts as a synchronizable event. It is ready when a client connection is ready to be accepted (see unix-socket-accept), and its synchronization result is the listener itself.

procedure

(unix-socket-close-listener listener)  void?

  listener : unix-socket-listener?
Closes a unix socket listener. The socket file must be deleted separately (e.g. using delete-file.)

procedure

(unix-socket-accept listener)  
input-port? output-port?
  listener : unix-socket-listener?
Accepts a client connection for listener. If no client connection is waiting to be accepted, the call to unix-socket-accept will block.

procedure

(unix-socket-accept-evt listener)  evt?

  listener : unix-socket-listener?
Returns a synchronizable event that is ready for synchronization when unix-socket-accept on listener would not block. The synchronization result is a list containing two items: an input port and an output port. The ports are managed by the custodian that is the current custodian at the time that unix-socket-accept-evt is called.

Added in version 1.2 of package unix-socket-lib.