libgslutil  1.2.3
Enumerations | Functions
Unix networking routines

Enumerations

enum  unix_subproto_t { unix_subproto_stream, unix_subproto_packet, unix_subproto_seqpacket }
 Unix domain socket types.Contains a list of the supported socket types in the Unix domain. More...
 

Functions

int unix_connect (int flags, const char *path, enum unix_subproto_t subproto))
 Connect to a remote Unix domain server. More...
 
int unix_server (int flags, const char *path, const char *owner, const char *group, int mode, enum unix_subproto_t subproto)
 Create a Unix domain server socket. More...
 
int unix_accept (int flags, int fd))
 Accept a client from a connection-oriented Unix domain server socket. More...
 

Detailed Description

unix_connect() instantiates and connects a client socket. unix_server() instantiates and binds a server socket. unix_accept() accepts an incoming connection from a server socket.

Enumeration Type Documentation

◆ unix_subproto_t

Unix domain socket types.Contains a list of the supported socket types in the Unix domain.

Enumerator
unix_subproto_stream 

Connection-oriented streams.

unix_subproto_packet 

Connectionless packets.

unix_subproto_seqpacket 

Connection-oriented packets. Only from linux-2.6.4.

Function Documentation

◆ unix_connect()

int unix_connect ( int  flags,
const char *  path,
enum unix_subproto_t  subproto 
)

Connect to a remote Unix domain server.

Parameters
flagsFlags for connection.
pathPath to the server socket. If the first character of the string is an ASCII null, then the server socket refers to the abstract namespace.
subprotoUnix domain socket type.
Return values
-1on error (and see errno).
filedescriptor of new client on success.

Creates a Unix domain socket and connects it to a remote server using the socket type specified in subproto.

flags may contain GSL_NONBLOCK to specify non-blocking mode.

◆ unix_server()

int unix_server ( int  flags,
const char *  path,
const char *  owner,
const char *  group,
int  mode,
enum unix_subproto_t  subproto 
)

Create a Unix domain server socket.

Parameters
flagsFlags for server socket.
pathPath to the server socket. If the first character of the string is an ASCII null, then the server socket refers to the abstract namespace.
ownerOwner name for chown (may be 0).
groupGroup name for chgrp (may be 0).
modeMode number for chmod (-1 means 0666 - umask).
subprotoUnix domain socket type.
Return values
-1on error (and see errno).
filedescriptor of new server on success.

Creates a Unix domain socket and binds it to a socket file using the details in path and, optionally, owner, group and mode (see gsl_set_perms()). Note the process's umask is temporarily altered during creation of the socket.

flags may contain GSL_NONBLOCK to specify non-blocking mode (this will only affect the server; newly-accepted clients may be either blocking or non-blocking).

See also
unix_accept().

◆ unix_accept()

int unix_accept ( int  flags,
int  fd 
)

Accept a client from a connection-oriented Unix domain server socket.

Parameters
flagsFlags for client socket.
fdServer's file descriptor.
Return values
-1on error (and see errno).
Returns
file descriptor of new client on success.

This function attempts to accept() a connection from Unix domain socket server. It will retry on any error except EAGAIN, which indicates that there are actually no more clients to accept. It should be called in a loop until it does this. If a persistent error occurs, -1 will be returned and the last error recorded in errno.

flags may contain GSL_NONBLOCK to specify that a newly-accepted client will be in non-blocking mode.