ioctlsocket

This function controls the mode of a socket.

At a Glance

Header file: Winsock.h
Windows CE versions: 1.0 and later

Syntax

int ioctlsocket (SOCKET s, long cmd, u_long *argp);

Parameters

s

[in] Descriptor that identifies a socket.

cmd

[in] Command to perform on the socket s.

argp

[in/out] Pointer to a parameter for cmd.

Return Values

Zero indicates success. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

Remarks

The ioctlsocket function can be used on any socket in any state. It is used to set or retrieve operating parameters associated with the socket, independent of the protocol and communications subsystem. Here are the supported commands to use in the cmd parameter and their semantics:

FIONBIO

Use with a nonzero argp parameter to enable the nonblocking mode of socket s. The argp parameter is zero if nonblocking is to be disabled. The argp parameter points to an unsigned long value. When a socket is created, it operates in blocking mode by default (nonblocking mode is disabled). This is consistent with BSD sockets.

FIONREAD

Use to determine the amount of data pending in the network's input buffer that can be read from socket s. The argp parameter points to an unsigned long value in which ioctlsocket stores the result. If s is stream oriented (for example, type SOCK_STREAM), FIONREAD returns the amount of data that can be read in a single call to the recv function; this might not be the same as the total amount of data queued on the socket. If s is message oriented (for example, type SOCK_DGRAM), FIONREAD returns the size of the first datagram (message) queued on the socket.

See Also

getsockopt, socket, setsockopt, WSAStartup