ioctlsocket()

PROTOTYPE

#include <sockets.h>

int ioctlsocket(int socket, int request, void *arg);

DESCRIPTION

ioctlsocket() is a multifunction call whose operation depends on its request parameter, which can be FIONBIO, FIONREAD, or SIOCATMARK. socket is a handle returned by socket(). arg points to a parameter whose meaning is determined by the value of request.

If request equals FIONBIO, arg points to an input parameter of type “int”. If this parameter is zero, the socket’s non-blocking flag is cleared, otherwise it is set. If a socket’s non-blocking flag is set, service calls using the socket return immediately with errno set to EWOULDBLOCK if the call cannot be completed without blocking.

If request equals FIONREAD, arg points to an output parameter of type “int”. If the socket is a TCP socket, the output is the number of bytes available to read from the socket. If the socket is a UDP socket, the output is the number of bytes in the first datagram queued at the socket.

If request is SIOCATMARK, arg points to an output parameter of type “int”. If out-of-band data is available at the socket, 1 is output, otherwise 0 is output. This request can only be made on a TCP socket.

If successful, ioctlsocket() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EINVAL request has an invalid value.
EFAULT arg is NULL.
ENETDOWN TargetTCP has not been initialized.
ENOTSOCK socket is not a valid socket handle.
EOPNOTSUPP SIOCATMARK requested on a UDP socket.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Make socket non-blocking.                                         */
  /*-------------------------------------------------------------------*/
  flag = 1;
  rc = ioctlsocket(sock, FIONBIO, &flag);