larksuite-oapi/src/main/java/com/larksuite/oapi/okhttp3_14/internal/http2/Http2Stream.java
void receive(BufferedSource in, long byteCount) throws IOException {
      assert (!Thread.holdsLock(Http2Stream.this));

      while (byteCount > 0) {
        boolean finished;
        boolean flowControlError;
        synchronized (Http2Stream.this) {
          finished = this.finished;
          flowControlError = byteCount + readBuffer.size() > maxByteCount;
        }

        // If the peer sends more data than we can handle, discard it and close the connection.
        if (flowControlError) {
          in.skip(byteCount);
          closeLater(ErrorCode.FLOW_CONTROL_ERROR);
          return;
        }

        // Discard data received after the stream is finished. It's probably a benign race.
        if (finished) {
          in.skip(byteCount);
          return;
        }

        // Fill the receive buffer without holding any locks.
        long read = in.read(receiveBuffer, byteCount);
        if (read == -1) throw new EOFException();
        byteCount -= read;

        // Move the received data to the read buffer to the reader can read it. If this source has
        // been closed since this read began we must discard the incoming data and tell the
        // connection we've done so.
        long bytesDiscarded = 0L;
        synchronized (Http2Stream.this) {
          if (closed) {
            bytesDiscarded = receiveBuffer.size();
            receiveBuffer.clear();
          } else {
            boolean wasEmpty = readBuffer.size() == 0;
            readBuffer.writeAll(receiveBuffer);
            if (wasEmpty) {
              Http2Stream.this.notifyAll();
            }
          }
        }
        if (bytesDiscarded > 0L) {
          updateConnectionFlowControl(bytesDiscarded);
        }
      }
    }
/**
     * Accept bytes on the connection's reader thread. This function avoids holding locks while it
     * performs blocking reads for the incoming bytes.
     */
Accept bytes on the connection's reader thread. This function avoids holding locks while it
performs blocking reads for the incoming bytes.
Accept bytes on the connection ' s reader thread . This function avoids holding locks while it performs blocking reads for the incoming bytes .
void receive(BufferedSource in, long byteCount) throws IOException {
      assert (!Thread.holdsLock(Http2Stream.this));
      while (byteCount > 0) {
        boolean finished;
        boolean flowControlError;
        synchronized (Http2Stream.this) {
          finished = this.finished;
          flowControlError = byteCount + readBuffer.size() > maxByteCount;
        }
        if (flowControlError) {
          in.skip(byteCount);
          closeLater(ErrorCode.FLOW_CONTROL_ERROR);
          return;
        }
        if (finished) {
          in.skip(byteCount);
          return;
        }
        long read = in.read(receiveBuffer, byteCount);
        if (read == -1) throw new EOFException();
        byteCount -= read;
        long bytesDiscarded = 0L;
        synchronized (Http2Stream.this) {
          if (closed) {
            bytesDiscarded = receiveBuffer.size();
            receiveBuffer.clear();
          } else {
            boolean wasEmpty = readBuffer.size() == 0;
            readBuffer.writeAll(receiveBuffer);
            if (wasEmpty) {
              Http2Stream.this.notifyAll();
            }
          }
        }
        if (bytesDiscarded > 0L) {
          updateConnectionFlowControl(bytesDiscarded);
        }
      }
    }
void receive ( BufferedSource in , long byteCount ) throws IOException { assert ( ! Thread . holdsLock ( Http2Stream . this ) ) ; while ( byteCount > 0 ) { boolean finished ; boolean flowControlError ; synchronized ( Http2Stream . this ) { finished = this . finished ; flowControlError = byteCount + readBuffer . size ( ) > maxByteCount ; } if ( flowControlError ) { in . skip ( byteCount ) ; closeLater ( ErrorCode . FLOW_CONTROL_ERROR ) ; return ; } if ( finished ) { in . skip ( byteCount ) ; return ; } long read = in . read ( receiveBuffer , byteCount ) ; if ( read == - 1 ) throw new EOFException ( ) ; byteCount -= read ; long bytesDiscarded = 0L ; synchronized ( Http2Stream . this ) { if ( closed ) { bytesDiscarded = receiveBuffer . size ( ) ; receiveBuffer . clear ( ) ; } else { boolean wasEmpty = readBuffer . size ( ) == 0 ; readBuffer . writeAll ( receiveBuffer ) ; if ( wasEmpty ) { Http2Stream . this . notifyAll ( ) ; } } } if ( bytesDiscarded > 0L ) { updateConnectionFlowControl ( bytesDiscarded ) ; } } }
Accept bytes on the connection's reader thread.
Accept bytes on the connection ' s reader thread .
// If the peer sends more data than we can handle, discard it and close the connection. // Discard data received after the stream is finished. It's probably a benign race. // Fill the receive buffer without holding any locks. // Move the received data to the read buffer to the reader can read it. If this source has // been closed since this read began we must discard the incoming data and tell the // connection we've done so.