Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fcntl() - control sockets

&pagelevel(4)&pagelevel

#include <fnctl.h>

int fcntl(int s, int cmd, int arg);

Description

The fcntl() function also executes control functions for sockets.

s designates the socket descriptor and cmd selects the control function to be executed.

More general information on this function is available in the manual "C Library Functions for POSIX Applications".

The following control functions are supported for sockets:

F_DUPFD

Duplicates a socket descriptor.

F_GETFD

Gets the "close-on-exec" bit that belongs to the socket s. If the least significant bit is 0, the socket remains open when exec() is called, otherwise, the socket is closed when exec() is called.

F_SETFD

Queries the "close-on-exec" bit belonging to the socket s to the least significant bit of the integer value passed as the third parameter (0 or 1 as above).

F_GETFL

Queries the file status bit of the socket s.

F_SETFL

Sets the file status bit of the socket s to the integer value passed as the third parameter. Only specific bits can be set (e.g. O_NONBLOCK for non-blocking sockets).

F_SETOWN

The process ID can be set for the socket s, causing a SIGIO signal to be supplied when a message arrives from the process.

F_GETOWN

Queries the process ID set for the socket s.

Return value

0:

If successful.

-1:

If errors occur. errno is set to indicate the error.

Errors

EBADF

The s parameter is not a valid descriptor.

EINVAL

cmd or arg are not valid for this descriptor.

EIO

A physical input/output error has occurred.

EMFILE

cmd is F_DUPFD and the maximum number of open file descriptors has been reached in the calling process.