Skip to content

Commit

Permalink
Set TCP_NODELAY option after handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jan 20, 2019
1 parent 1e001f9 commit 8b364a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Internal/Rfc6455Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ public function reapClient(
$this->clients[$client->id] = $client;
$this->heartbeatTimeouts[$client->id] = $this->now + $this->heartbeatPeriod;

\stream_context_set_option($socket->getResource(), 'socket', 'tcp_nodelay', true);
// Setting via stream API doesn't seem to work...
if (\function_exists('socket_import_stream') && \defined('TCP_NODELAY')) {
$sock = \socket_import_stream($socket->getResource());
/** @noinspection PhpComposerExtensionStubsInspection */
\socket_set_option($sock, \SOL_TCP, \TCP_NODELAY, 1);
}

Promise\rethrow(new Coroutine($this->tryAppOnOpen($client->id, $request)));
Promise\rethrow(new Coroutine($this->read($client)));
Expand Down
4 changes: 2 additions & 2 deletions test-autobahn/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function onOpen(int $clientId, Request $request)
public function onData(int $clientId, Websocket\Message $message)
{
if ($message->isBinary()) {
$this->broadcastBinary(yield $message->buffer());
yield $this->broadcastBinary(yield $message->buffer());
} else {
$this->broadcast(yield $message->buffer());
yield $this->broadcast(yield $message->buffer());
}
}

Expand Down

0 comments on commit 8b364a9

Please sign in to comment.