Ejemplo n.º 1
0
 /**
  * Write a frame to this channel synchronously.
  *
  * @param OutgoingFrame $frame The frame to write.
  *
  * @throws ChannelClosedException The channel has been closed.
  */
 public function writeSync(OutgoingFrame $frame)
 {
     if ($this->stream === null) {
         throw ChannelClosedException::channelClosed();
     }
     $buffer = $this->serializer->serialize($frame);
     assert(Debug::dumpOutgoingFrame('#' . (int) $this->stream, $frame));
     assert(Debug::dumpOutgoingHex('#' . (int) $this->stream, $buffer));
     do {
         $bytes = @\fwrite($this->stream, $buffer);
         // @codeCoverageIgnoreStart
         if ($bytes === false) {
             $error = \error_get_last();
             throw new ErrorException($error['message'], $error['type'], 1, $error['file'], $error['line']);
         }
         // @codeCoverageIgnoreEnd
         $buffer = \substr($buffer, $bytes);
     } while ($buffer);
     $this->hasSentFrame = true;
 }
Ejemplo n.º 2
0
 /**
  * Close this channel.
  *
  * @recoil-coroutine
  *
  * Closing a channel indicates that no more values will be written to the
  * channel. Once a channel is closed future invocations of write() MUST
  * throw a ChannelClosedException.
  */
 public function close() : Generator
 {
     $exception = ChannelClosedException::channelClosed();
     foreach ($this->strandQueue as $strand) {
         $strand->throw($exception);
     }
 }