os2_select()

The socket call gets read, write, and exception status on a group of sockets.

With the os2_select() call, the socket numbers are specified as an array of integers, in which the read socket numbers are followed by write socket numbers, followed by the exception socket numbers. TCP/IP for OS/2 Warp monitors the activity on a socket by specifying the number of sockets to be checked for readability, readiness for writing, and exception-pending conditions.

Syntax

#include <types.h>
#include <unistd.h>
int os2_select(s, noreads, nowrites, noexcepts, timeout)
int *s;
int noreads;
int nowrites;
int noexcepts;
long timeout;

Parameters

s

noreads nowrites noexcepts timeout

Description

This call monitors activity on a set of different sockets until a timeout expires, to see if any sockets are ready for reading or writing, or if any exceptional conditions are pending.

If the timeout value is 0, select() does not wait before returning. If the timeout value is -1, select() does not time out, but returns when a socket becomes ready. If the timeout value is a number of milliseconds, select() waits for the specified interval before returning. The select() call checks all indicated sockets at the same time and returns when any of them is ready.

Reinitializing the socket array every time select() is called is required.

Return Values

The number of ready sockets is returned. The value -1 indicates an error. The value 0 indicates an expired time limit. If the return value is greater than 0, the socket numbers in s that were not ready are set to -1. You can get the specific error code by calling sock_errno() or psock_errno().

Error Code

SOCENOTSOCK SOCEFAULT SOCEINVAL SOCEINTR

Examples

The following is an example of the os2_select() call.

#define MAX_TIMEOUT  1000/* input_ready(insock)- Check to see if there is available input on
 * socket insock.
 * Returns 1 if input is available.
 *         0 if input is not available.
 *        -1 on error.
 */

int input_ready(insock)
int insock;                 /* input socket descriptor */

{
  int socks[1];    /* array of sockets */
  long timeout = MAX_TIMEOUT;

  /* put socket to check in socks[] */
  socks[0] = insock;

  /* check for READ availability on this socket */
  return os2_select(socks, 1, 0, 0, timeout);
}

Related Calls


[Back: os2_ioctl()]
[Next: psock_errno()]