mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing issue with timeout when reading socket.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8233 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3b872a218e
commit
7fd6cc52c2
2 changed files with 24 additions and 2 deletions
|
@ -120,7 +120,11 @@ class CakeSocket extends Object {
|
|||
$this->setLastError($errStr, $errNum);
|
||||
}
|
||||
|
||||
return $this->connected = is_resource($this->connection);
|
||||
$this->connected = is_resource($this->connection);
|
||||
if ($this->connected) {
|
||||
stream_set_timeout($this->connection, $this->config['timeout']);
|
||||
}
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,7 +222,13 @@ class CakeSocket extends Object {
|
|||
}
|
||||
|
||||
if (!feof($this->connection)) {
|
||||
return fread($this->connection, $length);
|
||||
$buffer = fread($this->connection, $length);
|
||||
$info = stream_get_meta_data($this->connection);
|
||||
if ($info['timed_out']) {
|
||||
$this->setLastError(E_WARNING, __('Connection timed out', true));
|
||||
return false;
|
||||
}
|
||||
return $buffer;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -144,6 +144,18 @@ class SocketTest extends CakeTestCase {
|
|||
$this->Socket = new CakeSocket(array('timeout' => 5));
|
||||
$this->Socket->connect();
|
||||
$this->assertEqual($this->Socket->read(26), null);
|
||||
|
||||
$config = array('host' => 'www.cakephp.org', 'timeout' => 1);
|
||||
$this->Socket = new CakeSocket($config);
|
||||
$this->assertTrue($this->Socket->connect());
|
||||
$this->assertFalse($this->Socket->read(1024 * 1024));
|
||||
$this->assertEqual($this->Socket->lastError(), '2: ' . __('Connection timed out', true));
|
||||
|
||||
$config = array('host' => 'www.cakephp.org', 'timeout' => 30);
|
||||
$this->Socket = new CakeSocket($config);
|
||||
$this->assertTrue($this->Socket->connect());
|
||||
$this->assertEqual($this->Socket->read(26), null);
|
||||
$this->assertEqual($this->Socket->lastError(), null);
|
||||
}
|
||||
/**
|
||||
* testLastError method
|
||||
|
|
Loading…
Reference in a new issue