@@ -190,71 +190,49 @@ public function check($resolve, $reject)
190190 */
191191 public function attemptConnection($ip)
192192 {
193- $promise = null;
194- $that = $this;
195-
196- return new Promise\Promise(
197- function ($resolve, $reject) use (&$promise, $that, $ip) {
198- $uri = '';
193+ $uri = '';
199194
200- // prepend original scheme if known
201- if (isset($that ->parts['scheme'])) {
202- $uri .= $that ->parts['scheme'] . '://';
203- }
195+ // prepend original scheme if known
196+ if (isset($this ->parts['scheme'])) {
197+ $uri .= $this ->parts['scheme'] . '://';
198+ }
204199
205- if (\strpos($ip, ':') !== false) {
206- // enclose IPv6 addresses in square brackets before appending port
207- $uri .= '[' . $ip . ']';
208- } else {
209- $uri .= $ip;
210- }
200+ if (\strpos($ip, ':') !== false) {
201+ // enclose IPv6 addresses in square brackets before appending port
202+ $uri .= '[' . $ip . ']';
203+ } else {
204+ $uri .= $ip;
205+ }
211206
212- // append original port if known
213- if (isset($that ->parts['port'])) {
214- $uri .= ':' . $that ->parts['port'];
215- }
207+ // append original port if known
208+ if (isset($this ->parts['port'])) {
209+ $uri .= ':' . $this ->parts['port'];
210+ }
216211
217- // append orignal path if known
218- if (isset($that ->parts['path'])) {
219- $uri .= $that ->parts['path'];
220- }
212+ // append orignal path if known
213+ if (isset($this ->parts['path'])) {
214+ $uri .= $this ->parts['path'];
215+ }
221216
222- // append original query if known
223- if (isset($that ->parts['query'])) {
224- $uri .= '?' . $that ->parts['query'];
225- }
217+ // append original query if known
218+ if (isset($this ->parts['query'])) {
219+ $uri .= '?' . $this ->parts['query'];
220+ }
226221
227- // append original hostname as query if resolved via DNS and if
228- // destination URI does not contain "hostname" query param already
229- $args = array();
230- \parse_str(isset($that ->parts['query']) ? $that ->parts['query'] : '', $args);
231- if ($that ->host !== $ip && !isset($args['hostname'])) {
232- $uri .= (isset($that ->parts['query']) ? '&' : '?') . 'hostname=' . \rawurlencode($that ->host);
233- }
222+ // append original hostname as query if resolved via DNS and if
223+ // destination URI does not contain "hostname" query param already
224+ $args = array();
225+ \parse_str(isset($this ->parts['query']) ? $this ->parts['query'] : '', $args);
226+ if ($this ->host !== $ip && !isset($args['hostname'])) {
227+ $uri .= (isset($this ->parts['query']) ? '&' : '?') . 'hostname=' . \rawurlencode($this ->host);
228+ }
234229
235- // append original fragment if known
236- if (isset($that ->parts['fragment'])) {
237- $uri .= '#' . $that ->parts['fragment'];
238- }
230+ // append original fragment if known
231+ if (isset($this ->parts['fragment'])) {
232+ $uri .= '#' . $this ->parts['fragment'];
233+ }
239234
240- $promise = $that->connector->connect($uri);
241- $promise->then($resolve, $reject);
242- },
243- function ($_, $reject) use (&$promise, $that) {
244- // cancellation should reject connection attempt
245- // (try to) cancel pending connection attempt
246- $reject(new \RuntimeException('Connection to ' . $that->uri . ' cancelled during connection attempt'));
247-
248- if ($promise instanceof CancellablePromiseInterface) {
249- // overwrite callback arguments for PHP7+ only, so they do not show
250- // up in the Exception trace and do not cause a possible cyclic reference.
251- $_ = $reject = null;
252-
253- $promise->cancel();
254- $promise = null;
255- }
256- }
257- );
235+ return $this->connector->connect($uri);
258236 }
259237
260238 /**
0 commit comments