docs: boolean writeOneFrame() throws IOException {
      WebSocketWriter writer;
      ByteString pong;
      Object messageOrClose = null;
      int receivedCloseCode = -1;
      String receivedCloseReason = null;
      Streams streamsToClose = null;
  
      synchronized (RealWebSocket.this) {
        if (failed) {
          return false; // Failed web socket.
        }
  
        writer = this.writer;
        pong = pongQueue.poll();
        if (pong == null) {
          messageOrClose = messageAndCloseQueue.poll();
          if (messageOrClose instanceof Close) {
            receivedCloseCode = this.receivedCloseCode;
            receivedCloseReason = this.receivedCloseReason;
            if (receivedCloseCode != -1) {
              streamsToClose = this.streams;
              this.streams = null;
              this.executor.shutdown();
            } else {
              // When we request a graceful close also schedule a cancel of the websocket.
              cancelFuture = executor.schedule(new CancelRunnable(),
                  ((Close) messageOrClose).cancelAfterCloseMillis, MILLISECONDS);
            }
          } else if (messageOrClose == null) {
            return false; // The queue is exhausted.
          }
        }
      }
  
      try {
        if (pong != null) {
          writer.writePong(pong);
  
        } else if (messageOrClose instanceof Message) {
          ByteString data = ((Message) messageOrClose).data;
          BufferedSink sink = Okio.buffer(writer.newMessageSink(
              ((Message) messageOrClose).formatOpcode, data.size()));
          sink.write(data);
          sink.close();
          synchronized (this) {
            queueSize -= data.size();
          }
  
        } else if (messageOrClose instanceof Close) {
          Close close = (Close) messageOrClose;
          writer.writeClose(close.code, close.reason);
  
          // We closed the writer: now both reader and writer are closed.
          if (streamsToClose != null) {
            listener.onClosed(this, receivedCloseCode, receivedCloseReason);
          }
  
        } else {
          throw new AssertionError();
        }
  
        return true;
      } finally {
        closeQuietly(streamsToClose);
      }
    }