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

Commit

Permalink
bug #1202 Fix error message when connecting to a stream raises an err…
Browse files Browse the repository at this point in the history
…or before connect() (fabpot)

This PR was merged into the 6.2-dev branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Doc update?   | no
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets | #1201
| License       | MIT

<!-- Replace this comment by the description of your issue. -->

Commits
-------

28a0e25 fixed error message when connecting to a stream raises an error before connect()
  • Loading branch information
fabpot committed Jun 27, 2019
2 parents b22e508 + 28a0e25 commit 5a90a13
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 5a90a13

Please sign in to comment.