You are here

function Net_Socket::select in Flickr API 5

Runs the equivalent of the select() system call on the socket with a timeout specified by tv_sec and tv_usec.

@access public

Parameters

integer $state Which of read/write/error to check for.:

integer $tv_sec Number of seconds for timeout.:

integer $tv_usec Number of microseconds for timeout.:

Return value

False if select fails, integer describing which of read/write/error are ready, or PEAR_Error if not connected.

File

phpFlickr/PEAR/Net/Socket.php, line 492

Class

Net_Socket
Generalized Socket class.

Code

function select($state, $tv_sec, $tv_usec = 0) {
  if (!is_resource($this->fp)) {
    return $this
      ->raiseError('not connected');
  }
  $read = null;
  $write = null;
  $except = null;
  if ($state & NET_SOCKET_READ) {
    $read[] = $this->fp;
  }
  if ($state & NET_SOCKET_WRITE) {
    $write[] = $this->fp;
  }
  if ($state & NET_SOCKET_ERROR) {
    $except[] = $this->fp;
  }
  if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) {
    return false;
  }
  $result = 0;
  if (count($read)) {
    $result |= NET_SOCKET_READ;
  }
  if (count($write)) {
    $result |= NET_SOCKET_WRITE;
  }
  if (count($except)) {
    $result |= NET_SOCKET_ERROR;
  }
  return $result;
}