Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Socket/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,23 @@ protected function processPayload(string $payload): void
private function writeQueue(): void
{
foreach ($this->writeQueue as $data) {
\socket_write($this->socket, $data);
// Logger::debug('Respond %d bytes', $x);
$length = \strlen($data);
$written = 0;
while ($written < $length) {
$result = \socket_write($this->socket, \substr($data, $written));
if ($result === false) {
$errno = \socket_last_error($this->socket);
// If the send buffer is temporarily full, suspend the fiber and retry
if ($errno === \SOCKET_EAGAIN || $errno === \SOCKET_EWOULDBLOCK) {
\socket_clear_error($this->socket);
\Fiber::suspend();
continue;
}
// Unrecoverable error, stop writing
break 2;
}
$written += $result;
}
}
\socket_set_nonblock($this->socket);

Expand Down
Loading