From 1edd6bfe1a4c84f8f6aa3a6dec1d1d9b88f8a743 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 27 Jun 2019 11:12:45 +0200 Subject: [PATCH] fixed error message when connecting to a stream raises an error before connect() --- lib/classes/Swift/Transport/StreamBuffer.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/classes/Swift/Transport/StreamBuffer.php b/lib/classes/Swift/Transport/StreamBuffer.php index ab17f5c9b..e40b6d98b 100644 --- a/lib/classes/Swift/Transport/StreamBuffer.php +++ b/lib/classes/Swift/Transport/StreamBuffer.php @@ -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($this->url, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $streamContext); + } finally { + restore_error_handler(); } + if (!empty($this->params['blocking'])) { stream_set_blocking($this->stream, 1); } else {