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

Fix error message when connecting to a stream raises an error before connect() #1202

Merged
merged 1 commit into from Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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