Use the FCNTL command to control
the operating characteristics of a socket.
Format
.-,--BLOCKING-.
>>-SOCKET--(--"FCNTL"--,--socketid--,--fcmd--+-------------+---->
'-,--fvalue---'
>--)-----------------------------------------------------------><
Parameters
- socketid
- The socket descriptor.
- fcmd
- The command to be run. The following commands are available:
- F_SETFL
- Sets the status flags for the socket
- F_GETFL
- Retrieves the status flags of the socket
- fvalue
- One of the following flags:
- BLOCKING
- Puts a socket into blocking mode. If the targeted socket is in
nonblocking mode and there is no data on the socket, issuing this
command causes socket commands that support nonblocking socket descriptors
to return the 35 EWOULDBLOCK error message. By default,
the fvalue parameter is set to BLOCKING.
- NON-BLOCKING
- Puts a socket into nonblocking mode. The value FNDELAY is also
accepted.
Returned value
The
command returns a string that contains the return code. If the F_GETFL
flag is issued, the string also contains the flag. The return code can be 0, a REXX socket API error number, or the REXX TCP/IP error number that is set by the socket command. The return code 0 indicates that the requested socket command was completed successfully.
The
string 0 BLOCKING is an example of what this command might return.
See Socket call error return codes for additional information about the numeric error codes that are returned by this command.
The following REXX TCP/IP error numbers can be returned:- 1 EPERM
- 9 EBADF
- 35 EWOULDBLOCK
The following REXX socket API error numbers can be returned:- 2001 EINVALIDRXSOCKETCALL
- 2009 ESOCKETNOTDEFINED
LE C/C++ equivalent
int fcntl(int socket, int cmd, ...);
Code example
Figure 1. FCNTL command example/* REXX EXARXR04 */
/*
* This sample demonstrates the use of the FCNTL
* socket command.
*
* The program will open a STREAM socket and use the
* FCNTL command to set the socket to NON-BLOCKING
* mode.
*/
src = socket("INITIALIZE","MYSET01");
if perror(src,"INITIALIZE") = 0 then do
src = socket("SOCKET","AF_INET","STREAM");
if perror(src,"SOCKET") = 0 then do
l_socketid = WORD(src,2);
src = socket("FCNTL",l_socketid,F_SETFL,"NON-BLOCKING");
src = socket("FCNTL",l_socketid,F_GETFL);
Say src;
end; /* SOCKET */
src = socket("CLOSE",l_socketid);
src = perror(src,"CLOSE");
end;
src = socket("TERMINATE","MYSET01");
src = perror(src,"TERMINATE");
exit 0;
/* This routine returns -1 if the first word if arg 1 is not zero */
perror: if word(arg(1),1) = 0 then return 0; else
Say arg(2) "Error : "arg(1);
return -1;