tcpserver : manage the timeout : disconnect the user and generate an exception by default. Can be overloaded by the developper
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5993 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -512,20 +512,20 @@ class tcpserver
|
||||
throw new \Exception ("Can not read data in parent mode", 500);
|
||||
if ($this->socket === null)
|
||||
throw new \Exception ("Can not read from client : not connected", 500);
|
||||
stream_set_timeout ($this->socket, $this->timeout);
|
||||
if ($this->readMode === "text")
|
||||
{
|
||||
$read = stream_get_line ($this->socket, $maxLength, "\r\n");
|
||||
if ($read === false)
|
||||
throw new \Exception ("Can not read from client : ".
|
||||
error_get_last ()["message"], 500);
|
||||
}
|
||||
else
|
||||
{
|
||||
$read = @fread ($this->socket, $maxLength);
|
||||
if ($read === false)
|
||||
throw new \Exception ("Can not read from client : ".
|
||||
error_get_last ()["message"], 500);
|
||||
$meta = stream_get_meta_data ($this->socket);
|
||||
if (isset ($meta["timed_out"]) && $meta["timed_out"] === true)
|
||||
{
|
||||
$this->timeoutHandler();
|
||||
return false;
|
||||
}
|
||||
if ($read === false)
|
||||
throw new \Exception ("Can not read from client : ".
|
||||
error_get_last ()["message"], 500);
|
||||
$this->logReceive ($read);
|
||||
return $read;
|
||||
}
|
||||
@@ -669,6 +669,18 @@ class tcpserver
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** Manage the timeout exception handler
|
||||
* By default, disconnect and generate an exception
|
||||
*/
|
||||
public function timeoutHandler ()
|
||||
// {{{
|
||||
{
|
||||
$this->disconnect ();
|
||||
throw new \Exception (dgettext ("domframework",
|
||||
"Disconnected for inactivity"), 500);
|
||||
}
|
||||
// }}}
|
||||
|
||||
/////////////////////////
|
||||
// PRIVATE METHODS //
|
||||
/////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user