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 28a0e25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Expand Up @@ -4,7 +4,7 @@ Changelog
6.2.2 (2019-XX-XX)
------------------

* n/a
* fixed error message when connecting to a stream raises an error before connect()

6.2.1 (2019-04-21)
------------------
Expand Down
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 28a0e25

Please sign in to comment.