protected function wait()
    {
        $timeout = $this->getTimeout();
        if (null === $timeout) {
            // timeout=null just poll state and return instantly
            $sec = 0;
            $usec = 0;
        } elseif ($timeout > 0) {
            list($sec, $usec) = MiscHelper::splitSecondsMicroseconds($this->getTimeout());
        } else {
            // wait indefinitely for data if timeout=0
            $sec = null;
            $usec = 0;
        }

        $result = $this->io->select($sec, $usec);

        if ($result === false) {
            throw new AMQPIOWaitException('A network error occurred while awaiting for incoming data');
        }

        if ($result === 0) {
            if ($timeout > 0) {
                throw new AMQPTimeoutException(sprintf(
                    'The connection timed out after %s sec while awaiting incoming data',
                    $timeout
                ));
            } else {
                throw new AMQPNoDataException('No data is ready to read');
            }
        }
    }