IBM Tivoli NetView for z/OS, Version 6.2

Waiting for Activity on Sockets

Particularly when implementing an application that serves multiple clients or manages multiple sockets simultaneously, you might not want to block the application that is waiting for activity on just one socket (such as by issuing SOCKET TYPE=ACCEPT for a server listening socket when no connection requests are available to be accepted).

To wait for activity on any sockets managed by a TCP/IP application, use a SOCKET TYPE=SELECT command. To wait for activity on the sockets, any or all of read, write, and exception lists can be passed to the SOCKET TYPE=SELECT command. You can also specify a timeout value so that the command ends after a specified time, even if no activity occurred on any socket.

For example, suppose that a TCP/IP application has a listening (server) socket 0 and a socket 1 representing the server connection to a client and has issued the SOCKET TYPE=GIVESOCKET command to pass socket 2 to another TCP/IP application. To wait for another connection request, data from the client, and the other TCP/IP application to take the socket, respectively, and to wait no more than 15 seconds for the command to finish, use the following command:
SOCKET TYPE=SELECT READ=(0,1) EXCEPT=2 TIMEOUT=15
If data from the client becomes available before 15 seconds elapses, the SOCKET TYPE=SELECT command finishes with a message that is similar to the following message:
BNH610I SOCKET 1 READY FOR 'READ'

If multiple sockets had activity, a BNH610I message is issued for each socket that had activity, with the message variable containing a value for each type of event that occurred for the socket.

If 15 seconds elapses without any activity for any socket passed to SOCKET TYPE=SELECT, the SOCKET TYPE=SELECT command finishes with the following message:
BNH609I SELECT REQUEST HAS TIMED OUT
Note: Because of the limitations of the command parsing services that are used by the SOCKET command, the value of each of the READ, WRITE, and EXCEPT keywords cannot exceed 255 characters (including the parentheses that delimit a list of socket descriptors). If the number of sockets monitored for a type of activity becomes large enough to exceed the value length limit, the SOCKET command ends with a syntax error.

This error can be prevented in a couple of ways. One way is to limit the list to the descriptors that fit in the list and to close any others. Another way is to create multiple lists and rotate calls of SOCKET TYPE=SELECT through the different lists, perhaps using a relatively small TIMEOUT value so that no socket has to wait very long for its activity to be processed.



Feedback