fcntl()

Provides socket I/O control. Can be used to set nonblocking I/O mode for the specified socket.

Syntax

result = fcntl(socket, cmd, status)

int socket, cmd; long result, status;

Parameters

result

0 if fcntl() is successful.

 

-1if a failure occurs.

socket

Socket descriptor of a local socket.

cmd

Command to get or set socket status. The possible values for

 

cmd are:

 

 

F_GETFL

Get the socket status. The status value is

 

 

returned in status.

 

F_SETFL

Set the status to value as specified in

 

 

status. The only status setting currently

 

 

supported is O_NONBLOCK.

status

Specify the socket status. It is a 32bit data type, each bit of

 

which represents a characteristic of the socket. Setting and

 

unsetting the bit in this parameter sets or unsets the socket

 

characteristic,respectively.

 

For F_SETFL, fcntl() sets the current status to the value

 

specified in status.

 

The currently supported value for status is:

 

O_NONBLOCK

This option designates the socket as

 

 

nonblocking. A request on a nonblocking

 

 

socket that cannot complete immediately

returns to the caller and sets errno to EAGAIN. This option affects the following calls: accept(), connect(), recv(), and send(). In a nonblocking connect() call, the errno value returned is set to EINPROGRESS instead of EAGAIN.

Sockets are created in blocking mode by default.

Berkeley Software Distribution Interprocess Communication 45