Skip to content

Commit

Permalink
Modified TcpClient to "use" \Exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
boenrobot committed Aug 14, 2013
1 parent f4c5c36 commit 9875997
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/PEAR2/Net/Transmitter/TcpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
*/
use PEAR2\Cache\SHM;

/**
* Used for matching arbitrary exceptions in
* {@link TcpClient::createException()} and releasing locks properly.
*/
use Exception as E;

/**
* A socket transmitter.
*
Expand Down Expand Up @@ -118,8 +124,7 @@ public function __construct(

if (null === $context) {
$context = stream_context_get_default();
} elseif (
(!is_resource($context))
} elseif ((!is_resource($context))
|| ('stream-context' !== get_resource_type($context))
) {
throw $this->createException('Invalid context supplied.', 6);
Expand All @@ -140,7 +145,7 @@ public function __construct(
)
);
restore_error_handler();
} catch (\Exception $e) {
} catch (E $e) {
restore_error_handler();
if (0 === $this->error_no) {
throw $this->createException(
Expand Down Expand Up @@ -177,15 +182,16 @@ private static function _handleError($level, $message)
*
* Creates a new exception. Used by the rest of the functions in this class.
*
* @param string $message The exception message.
* @param int $code The exception code.
* @param string $message The exception message.
* @param int $code The exception code.
* @param E $previous Previous exception thrown.
*
* @return SocketException The exception to then be thrown.
*/
protected function createException(
$message,
$code = 0,
\Exception $previous = null
E $previous = null
) {
return new SocketException(
$message,
Expand Down Expand Up @@ -306,7 +312,7 @@ public function send($contents, $offset = null, $length = null)
}
try {
$result = parent::send($contents, $offset, $length);
} catch (\Exception $e) {
} catch (E $e) {
$this->lock($previousState, true);
throw $e;
}
Expand Down Expand Up @@ -337,7 +343,7 @@ public function receive($length, $what = 'data')
}
try {
$result = parent::receive($length, $what);
} catch (\Exception $e) {
} catch (E $e) {
$this->lock($previousState, true);
throw $e;
}
Expand Down Expand Up @@ -374,7 +380,7 @@ public function receiveStream(
}
try {
$result = parent::receiveStream($length, $filters, $what);
} catch (\Exception $e) {
} catch (E $e) {
$this->lock($previousState, true);
throw $e;
}
Expand Down

0 comments on commit 9875997

Please sign in to comment.