diff --git a/modules/registrars/cozaepp/Net/EPP/Protocol.php b/modules/registrars/cozaepp/Net/EPP/Protocol.php index 1c80dac9235b8ebe6554e4417afb2a76a5a816f1..3574a4501b6b76868359cd970bd1cc3df6747efe 100644 --- a/modules/registrars/cozaepp/Net/EPP/Protocol.php +++ b/modules/registrars/cozaepp/Net/EPP/Protocol.php @@ -38,37 +38,37 @@ class Net_EPP_Protocol { * @return PEAR_Error|string either an error or a string */ static function getFrame($socket) { - if (@feof($socket)) return new PEAR_Error('connection closed (socket is EOF)'); - $hdr = @fread($socket, 4); - - if (empty($hdr) && feof($socket)) { - return new PEAR_Error('connection closed (no header received and socket is EOF)'); + # NK: Use non-blocking IO + $hdr = ""; + while (strlen($hdr) < 4) { + if (@feof($socket)) return new PEAR_Error('Connection closed (socket is EOF)'); + if (($hdrstr = @fread($socket,4 - strlen($hdr))) !== false) { + $hdr .= $hdrstr; + } else { + return new PEAR_ERROR('Error reading from socket:'.$php_errormsg); + } + } - } elseif (false === $hdr) { - return new PEAR_Error('Error reading from peer: '.$php_errormsg); + $unpacked = unpack('N', $hdr); + $length = $unpacked[1]; + if ($length < 5) { + return new PEAR_Error(sprintf('Got a bad frame header length of %d bytes from peer', $length)); } else { - $unpacked = unpack('N', $hdr); - $length = $unpacked[1]; - if ($length < 5) { - return new PEAR_Error(sprintf('Got a bad frame header length of %d bytes from peer', $length)); + $length -= 4; // discard the length of the header itself - } else { - $length -= 4; // discard the length of the header itself - - // sometimes the socket can be buffered with a limit below the frame - // length, so we continually read from the socket until we get the full frame: - $frame = ''; - while (strlen($frame) < $length) $frame .= fread($socket, ($length)); + // sometimes the socket can be buffered with a limit below the frame + // length, so we continually read from the socket until we get the full frame: + $frame = ''; + while (strlen($frame) < $length) $frame .= fread($socket, ($length)); - if (strlen($frame) > $length) { - return new PEAR_Error(sprintf("Frame length (%d bytes) doesn't match header (%d bytes)", strlen($frame), ($length))); + if (strlen($frame) > $length) { + return new PEAR_Error(sprintf("Frame length (%d bytes) doesn't match header (%d bytes)", strlen($frame), ($length))); - } else { - return $frame; + } else { + return $frame; - } } } }