Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
fixed error message when connecting to a stream raises an error befor…
Browse files Browse the repository at this point in the history
…e connect()
  • Loading branch information
fabpot committed Jun 27, 2019
1 parent b22e508 commit 78dc257
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/classes/Swift/Transport/StreamBuffer.php
Expand Up @@ -264,13 +264,16 @@ private function establishSocketConnection()
$options = array_merge($options, $this->params['stream_context_options']);
}
$streamContext = stream_context_create($options);
$this->stream = @stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
if (false === $this->stream) {
throw new Swift_TransportException(
'Connection could not be established with host '.$this->params['host'].
' ['.$errstr.' #'.$errno.']'
);

set_error_handler(function ($type, $msg) {
throw new Swift_TransportException('Connection could not be established with host '.$this->params['host'].' :'.$msg);
});
try {
$this->stream = stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
} finally {
restore_error_handler();
}

if (!empty($this->params['blocking'])) {
stream_set_blocking($this->stream, 1);
} else {
Expand Down

0 comments on commit 78dc257

Please sign in to comment.