Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PChannel::Errors PSocket::Select ( SelectList read,
SelectList write,
SelectList except,
const PTimeInterval timeout 
) [static, inherited]

Select a socket with available data. This function will block until the timeout or data is available to be read or written to the specified sockets.

The read#, write# and except# lists are modified by the call so that only the sockets that have data available are present. If the call timed out then all of these lists will be empty.

If no timeout is specified then the call will block until a socket has data available.

Returns:
TRUE if the select was successful or timed out, FALSE if an error occurred. If a timeout occurred then the lists returned will be empty.
For the versions taking sockets directly instead of lists the integer returned is >0 for an error being a value from the PChannel::Errors enum, 0 for a timeout, -1 for the first socket having read data, -2 for the second socket and -3 for both.
Parameters:
read  List of sockets to check for readability.
write  List of sockets to check for writability.
except  List of sockets to check for exceptions.
timeout  Timeout for wait on read/write data.

Definition at line 591 of file winsock.cxx.

References PChannel::ConvertOSError(), PChannel::Interrupted, PChannel::IsOpen(), and PChannel::NotOpen.

{
  PINDEX i;

  P_fd_set readfds;
  for (i = 0; i < read.GetSize(); i++) {
    if (!read[i].IsOpen())
      return NotOpen;
    readfds += read[i].GetHandle();
  }

  P_fd_set writefds;
  for (i = 0; i < write.GetSize(); i++) {
    if (!write[i].IsOpen())
      return NotOpen;
    writefds += write[i].GetHandle();
  }

  P_fd_set exceptfds;
  for (i = 0; i < except.GetSize(); i++) {
    if (!except[i].IsOpen())
      return NotOpen;
    exceptfds += except[i].GetHandle();
  }

  P_timeval tval = timeout;
  int retval = select(INT_MAX, readfds, writefds, exceptfds, tval);

  Errors lastError;
  int osError;
  if (!ConvertOSError(retval, lastError, osError))
    return lastError;

  if (retval > 0) {
    for (i = 0; i < read.GetSize(); i++) {
      int h = read[i].GetHandle();
      if (h < 0)
        return Interrupted;
      if (!readfds.IsPresent(h))
        read.RemoveAt(i--);
    }
    for (i = 0; i < write.GetSize(); i++) {
      int h = write[i].GetHandle();
      if (h < 0)
        return Interrupted;
      if (!writefds.IsPresent(h))
        write.RemoveAt(i--);
    }
    for (i = 0; i < except.GetSize(); i++) {
      int h = except[i].GetHandle();
      if (h < 0)
        return Interrupted;
      if (!exceptfds.IsPresent(h))
        except.RemoveAt(i--);
    }
  }
  else {
    read.RemoveAll();
    write.RemoveAll();
    except.RemoveAll();
  }

  return NoError;
}


Generated by  Doxygen 1.6.0   Back to index