Files
.github
admin
docs
install
pages_template
qrcode
scan
system
autoload
PEAR2
Cache
Console
Net
RouterOS
Transmitter
Exception.php
FilterCollection.php
LockException.php
NetworkStream.php
SocketException.php
Stream.php
StreamException.php
TcpClient.php
TcpServerConnection.php
Autoload.php
mail
Admin.php
App.php
Balance.php
Csrf.php
File.php
Hookers.php
Http.php
Lang.php
Log.php
Message.php
Mikrotik.php
Package.php
Paginator.php
Parsedown.php
Password.php
Text.php
Timezone.php
User.php
Validator.php
index.html
cache
controllers
devices
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
Dockerfile
LICENSE
README.md
composer.json
config.sample.php
docker-compose.example.yml
favicon.ico
index.php
init.php
radius.php
update.php
version.json
mitrobill/system/autoload/PEAR2/Net/Transmitter/SocketException.php

130 lines
4.0 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
/**
* Wrapper for network stream functionality.
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* PHP has built in support for various types of network streams, such as HTTP and TCP sockets. One problem that arises with them is the fact that a single fread/fwrite call might not read/write all the data you intended, regardless of whether you're in blocking mode or not. While the PHP manual offers a workaround in the form of a loop with a few variables, using it every single time you want to read/write can be tedious.
This package abstracts this away, so that when you want to get exactly N amount of bytes, you can be sure the upper levels of your app will be dealing with N bytes. Oh, and the functionality is nicely wrapped in an object (but that's just the icing on the cake).
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* PHP version 5
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* @category Net
* @package PEAR2_Net_Transmitter
* @author Vasil Rangelov <boen.robot@gmail.com>
* @copyright 2011 Vasil Rangelov
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
2023-10-05 16:55:44 +07:00
* @version 1.0.0b2
2017-03-11 02:51:06 +07:00
* @link http://pear2.php.net/PEAR2_Net_Transmitter
*/
/**
* The namespace declaration.
*/
namespace PEAR2\Net\Transmitter;
/**
* Used to enable any exception in chaining.
*/
use Exception as E;
/**
* Exception thrown when something goes wrong with the connection.
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* @category Net
* @package PEAR2_Net_Transmitter
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear2.php.net/PEAR2_Net_Transmitter
*/
class SocketException extends StreamException
{
/**
2023-10-05 16:55:44 +07:00
* The system level error code.
*
* @var int
2017-03-11 02:51:06 +07:00
*/
protected $errorNo;
/**
2023-10-05 16:55:44 +07:00
* The system level error message.
*
* @var string
2017-03-11 02:51:06 +07:00
*/
protected $errorStr;
/**
* Creates a new socket exception.
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* @param string $message The Exception message to throw.
* @param int $code The Exception code.
* @param E|null $previous Previous exception thrown,
* or NULL if there is none.
* @param int|string|resource|null $fragment The fragment up until the
* point of failure.
* On failure with sending, this is the number of bytes sent
* successfully before the failure.
* On failure when receiving, this is a string/stream holding
* the contents received successfully before the failure.
2023-10-05 16:55:44 +07:00
* NULL if the failure occurred before the operation started.
2017-03-11 02:51:06 +07:00
* @param int $errorNo The system level error number.
* @param string $errorStr The system level
* error message.
*/
public function __construct(
$message = '',
$code = 0,
E $previous = null,
$fragment = null,
$errorNo = null,
$errorStr = null
) {
parent::__construct($message, $code, $previous, $fragment);
$this->errorNo = $errorNo;
$this->errorStr = $errorStr;
}
/**
* Gets the system level error code on the socket.
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* @return int The system level error number.
*/
public function getSocketErrorNumber()
{
return $this->errorNo;
}
// @codeCoverageIgnoreStart
// Unreliable in testing.
/**
* Gets the system level error message on the socket.
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* @return string The system level error message.
*/
public function getSocketErrorMessage()
{
return $this->errorStr;
}
/**
* Returns a string representation of the exception.
2023-10-05 16:55:44 +07:00
*
2017-03-11 02:51:06 +07:00
* @return string The exception as a string.
*/
public function __toString()
{
$result = parent::__toString();
if (null !== $this->getSocketErrorNumber()) {
$result .= "\nSocket error number:" . $this->getSocketErrorNumber();
}
if (null !== $this->getSocketErrorMessage()) {
$result .= "\nSocket error message:"
. $this->getSocketErrorMessage();
}
return $result;
}
// @codeCoverageIgnoreEnd
}