The ioctlsocket function sends commands to sockets. See the description of the function arguments below, for information about the commands that can be sent.
The system include file WinSock2.inc contains the following declaration for the ioctlsocket function:
function ioctlsocket(s : SOCKET; cmd : integer; var argp : u_long) : integer;
external dll='ws2_32.dll';
The first argument passed to the ioctlsocket function is the socket that you want to send a command to.
The second argument passed to the ioctlsocket function is the command that you want to send to the socket. The Windows Sockets API supports three commands, and these commands are:
The third argument passed to the ioctlsocket function is of type u_long and is passed by reference. You use this argument to further specify what the command should do or to retrieve values returned by the command.
The ioctlsocket function returns a value of integer type that indicates whether the call was successful. A value of zero means that the call succeeded. A value of SOCKET_ERROR indicates that the called failed, and in this case you can use the WSAGetLastError function to retrieve a code that identifies the error that caused the call to fail. NOTE: The constant SOCKET_ERROR is declared in the system include file WinSock2.inc.
The following code fragments illustrates how to enable socket's non-blocking mode.
ulNonBlockingMode := 1;
iRet := ioctlsocket(s, FIONBIO, ulNonBlockingMode);
The code fragment above assumes that s is a socket that has already been created, ulNonBlockingMode is a variable of type u_long, and iRet is a variable of integer type. NOTE: The type u_long is declared in the system include file WinSock2.inc.
The authoritative source of information about the WinSock2 library is the Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website at msdn.microsoft.com.