This repository has been archived by the owner on Sep 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into test_incomplete_frame_fix
Conflicts: src/Devristo/Phpws/Protocol/WebSocketTransportInterface.php
- Loading branch information
Showing
5 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Devristo\Phpws\Client; | ||
|
||
use React\SocketClient\Connector as BaseConnector; | ||
use React\EventLoop\LoopInterface; | ||
use React\Dns\Resolver\Resolver; | ||
|
||
class Connector extends BaseConnector | ||
{ | ||
|
||
protected $contextOptions = array(); | ||
|
||
public function __construct(LoopInterface $loop, Resolver $resolver, array $contextOptions = null) | ||
{ | ||
parent::__construct($loop, $resolver); | ||
|
||
$contextOptions = null === $contextOptions ? array() : $contextOptions; | ||
$this->contextOptions = $contextOptions; | ||
} | ||
|
||
protected function createStreamContext() | ||
{ | ||
return stream_context_create($this->contextOptions); | ||
} | ||
|
||
public function createSocketForAddress($address, $port) | ||
{ | ||
$url = $this->getSocketUrl($address, $port); | ||
|
||
$socket = stream_socket_client($url, $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT, $this->createStreamContext()); | ||
|
||
if (!$socket) { | ||
return When::reject(new \RuntimeException( | ||
sprintf("connection to %s:%d failed: %s", $address, $port, $errstr), | ||
$errno | ||
)); | ||
} | ||
|
||
stream_set_blocking($socket, 0); | ||
|
||
// wait for connection | ||
|
||
return $this | ||
->waitForStreamOnce($socket) | ||
->then(array($this, 'checkConnectedSocket')) | ||
->then(array($this, 'handleConnectedSocket')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,4 @@ public function close(); | |
public function setData($key, $value); | ||
|
||
public function getData($key); | ||
} | ||
} |