tcpserver : add exception catch, not log for "stream_select(): unable to select [4]: Interrupted system call (max_fd=0)" error, more tests
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5992 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -176,6 +176,18 @@ class tcpserver
|
|||||||
// {{{
|
// {{{
|
||||||
{
|
{
|
||||||
$this->logMethods (__METHOD__, func_get_args ());
|
$this->logMethods (__METHOD__, func_get_args ());
|
||||||
|
if (empty ($this->addresses))
|
||||||
|
throw new \Exception (dgettext ("domframework",
|
||||||
|
"Can not start TCP server loop without addresses initialized"), 500);
|
||||||
|
if (empty ($this->ports))
|
||||||
|
throw new \Exception (dgettext ("domframework",
|
||||||
|
"Can not start TCP server loop without port initialized"), 500);
|
||||||
|
foreach ($this->ports as $port)
|
||||||
|
{
|
||||||
|
if ($port < 1024 && posix_getuid() !== 0)
|
||||||
|
throw new \Exception (dgettext ("domframework",
|
||||||
|
"Can not start TCP server on port $port without root user"), 500);
|
||||||
|
}
|
||||||
$this->logDebug ("Initialize the signal managers");
|
$this->logDebug ("Initialize the signal managers");
|
||||||
//declare (ticks = 1);
|
//declare (ticks = 1);
|
||||||
pcntl_async_signals (true);
|
pcntl_async_signals (true);
|
||||||
@@ -359,7 +371,8 @@ class tcpserver
|
|||||||
ob_start ();
|
ob_start ();
|
||||||
// Catch the error messages from the application to not hang if triggered
|
// Catch the error messages from the application to not hang if triggered
|
||||||
// An other handler can be set in function to execute
|
// An other handler can be set in function to execute
|
||||||
set_error_handler (function () {});
|
set_error_handler ([$this, "errorHandler"]);
|
||||||
|
set_exception_handler ([$this, "exceptionHandler"]);
|
||||||
@fclose (STDIN);
|
@fclose (STDIN);
|
||||||
@fclose (STDOUT);
|
@fclose (STDOUT);
|
||||||
@fclose (STDERR);
|
@fclose (STDERR);
|
||||||
@@ -476,9 +489,7 @@ class tcpserver
|
|||||||
if ($this->socket === null)
|
if ($this->socket === null)
|
||||||
throw new \Exception ("Can not send to client : not connected", 500);
|
throw new \Exception ("Can not send to client : not connected", 500);
|
||||||
$length = strlen ($data);
|
$length = strlen ($data);
|
||||||
ob_start ();
|
|
||||||
$sentLen = fwrite ($this->socket, $data);
|
$sentLen = fwrite ($this->socket, $data);
|
||||||
$this->debug (ob_get_flush ());
|
|
||||||
if ($sentLen < $length)
|
if ($sentLen < $length)
|
||||||
throw new \Exception ("Can not send data to client", 500);
|
throw new \Exception ("Can not send data to client", 500);
|
||||||
$this->logSend ($data);
|
$this->logSend ($data);
|
||||||
@@ -515,7 +526,7 @@ $this->debug (ob_get_flush ());
|
|||||||
throw new \Exception ("Can not read from client : ".
|
throw new \Exception ("Can not read from client : ".
|
||||||
error_get_last ()["message"], 500);
|
error_get_last ()["message"], 500);
|
||||||
}
|
}
|
||||||
$this->logReceive ($data);
|
$this->logReceive ($read);
|
||||||
return $read;
|
return $read;
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@@ -639,10 +650,25 @@ $this->debug (ob_get_flush ());
|
|||||||
public function errorHandler ($errNo, $errMsg, $file, $line)
|
public function errorHandler ($errNo, $errMsg, $file, $line)
|
||||||
// {{{
|
// {{{
|
||||||
{
|
{
|
||||||
|
// @-operator : error suppressed
|
||||||
|
if (0 === error_reporting())
|
||||||
|
return false;
|
||||||
$this->logError ("line $line : $errMsg");
|
$this->logError ("line $line : $errMsg");
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
|
/** Exception catcher
|
||||||
|
* By default do nothing, but can be overrided by the user
|
||||||
|
* @param object $exception The exception to catch
|
||||||
|
*/
|
||||||
|
public function exceptionHandler ($exception)
|
||||||
|
// {{{
|
||||||
|
{
|
||||||
|
$this->logError ("Exception ".$exception->getMessage () . " (".
|
||||||
|
$exception->getFile ().":".$exception->getLine().")");
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
// PRIVATE METHODS //
|
// PRIVATE METHODS //
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user