Skip to content
Snippets Groups Projects
Commit c61d27de authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Fixed timeouts and added noblocking write

* Fixed timeouts for non-blocking read
* Added non-blocking write (fixes short write errors)

- Special thanks to Srinivasu for reporting this

Change-Id: I5aa36c023640a4cef130383ba48635f39ce7a086
parent df96ab59
No related branches found
No related tags found
No related merge requests found
......@@ -49,13 +49,13 @@ class Net_EPP_Protocol {
}
} else {
// Sleep 0.25s
usleep(2500);
usleep(250000);
}
// Update metadata
$info = stream_get_meta_data($socket);
$time_end = microtime(true);
if (($time_end - $time_start) > 5) {
throw new exception('Timeout while contacting EPP Server');
if (($time_end - $time_start) > 10000000) {
throw new exception('Timeout while reading from EPP Server');
}
}
......@@ -67,6 +67,45 @@ class Net_EPP_Protocol {
return $result;
}
static function _fwrite_nb($socket,$buffer,$length) {
// Loop writing and checking info to see if we hit timeout
$info = stream_get_meta_data($socket);
$time_start = microtime(true);
$pos = 0;
while (!$info['timed_out'] && !feof($socket)) {
// Some servers don't like alot of data, so keep it small per chunk
$wlen = $length - $pos;
if ($wlen > 1024) { $wlen = 1024; }
// Try write remaining data from socket
$written = @fwrite($socket,substr($buffer,$pos),$wlen);
// If we read something, bump up the position
if ($written && $written !== false) {
$pos += $written;
// If we hit the length we looking for, break
if ($pos == $length) {
break;
}
} else {
// Sleep 0.25s
usleep(250000);
}
// Update metadata
$info = stream_get_meta_data($socket);
$time_end = microtime(true);
if (($time_end - $time_start) > 10000000) {
throw new exception('Timeout while writing to EPP Server');
}
}
// Check for timeout
if ($info['timed_out']) {
throw new Exception('Timeout while writing data to socket');
}
return $pos;
}
/**
* get an EPP frame from the remote peer
* @param resource $socket a socket connected to the remote peer
......@@ -100,7 +139,7 @@ class Net_EPP_Protocol {
static function sendFrame($socket, $xml) {
// Grab XML length & add on 4 bytes for the counter
$length = strlen($xml) + 4;
$res = fwrite($socket, pack('N',$length) . $xml);
$res = Net_EPP_Protocol::_fwrite_nb($socket, pack('N',$length) . $xml,$length);
// Check our write matches
if ($length != $res) {
throw new Exception("Short write when sending XML");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment