private function writer(string $watcherId, $socket)
{
$bytes = @fwrite($socket, $this->buf);
if ($bytes == 0) {
if (!is_resource($socket) || @feof($socket)) {
\Amp\cancel($this->writeWatcher);
$this->sock = $this->writeWatcher = null;
$this->establish();
}
return;
}
if ($bytes === \strlen($this->buf)) {
\Amp\cancel($watcherId);
$this->writeWatcher = null;
}
$this->written += $bytes;
foreach ($this->promisors as $end => $deferred) {
if ($end > $this->written) {
break;
}
$deferred->succeed();
unset($this->promisors[$end]);
}
}