2021-05-07 12:07:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes\Sock;
|
|
|
|
|
2023-06-22 07:36:22 +00:00
|
|
|
// @todo Can we change this to use socket_strerr() && socket_last_error()
|
2021-05-07 12:07:26 +00:00
|
|
|
final class SocketException extends \Exception {
|
|
|
|
public const CANT_CREATE_SOCKET = 1;
|
|
|
|
public const CANT_BIND_SOCKET = 2;
|
|
|
|
public const CANT_LISTEN = 3;
|
|
|
|
public const CANT_ACCEPT = 4;
|
|
|
|
public const CANT_CONNECT = 5;
|
2021-04-01 10:59:15 +00:00
|
|
|
public const SOCKET_ERROR = 6;
|
|
|
|
public const SOCKET_EAGAIN = 11;
|
2021-07-04 11:47:23 +00:00
|
|
|
public const SOCKET_READ = 22;
|
2023-06-22 07:36:22 +00:00
|
|
|
public const CONNECTION_RESET = 104;
|
2021-05-07 12:07:26 +00:00
|
|
|
|
|
|
|
private array $messages = [
|
|
|
|
self::CANT_CREATE_SOCKET => 'Can\'t create socket: "%s"',
|
|
|
|
self::CANT_BIND_SOCKET => 'Can\'t bind socket: "%s"',
|
|
|
|
self::CANT_LISTEN => 'Can\'t listen: "%s"',
|
|
|
|
self::CANT_ACCEPT => 'Can\'t accept connections: "%s"',
|
|
|
|
self::CANT_CONNECT => 'Can\'t connect: "%s"',
|
2021-04-01 10:59:15 +00:00
|
|
|
self::SOCKET_ERROR => 'Socket Error: "%s"',
|
|
|
|
self::SOCKET_EAGAIN => 'Socket Resource Temporarily Unavailable - Try again',
|
2021-07-04 11:47:23 +00:00
|
|
|
self::SOCKET_READ => 'Unable to read from socket',
|
2023-06-22 07:36:22 +00:00
|
|
|
self::CONNECTION_RESET => 'Connection reset by peer',
|
2021-05-07 12:07:26 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct(int $code,string $params=NULL) {
|
|
|
|
$message = $params
|
|
|
|
? call_user_func_array('sprintf',[$this->messages[$code],$params])
|
|
|
|
: $this->messages[$code];
|
|
|
|
|
|
|
|
parent::__construct($message,$code);
|
|
|
|
}
|
|
|
|
}
|