Exemple #1
0
  private void deliverToBuffer() {
    while (transportBuffer.containsKey(recvBase)) {
      p(this, 4, "coalescing at recvBase: " + recvBase);
      dumpState(6);

      byte[] payload = transportBuffer.get(recvBase).getPayload();

      if (recvbb.remaining() >= payload.length) {
        recvbb.put(payload);
        recvBase += payload.length;
        p(this, 5, "coalesced: recvBase incremented to " + recvBase);
      } else {
        p(this, 5, "coalesce ending: buffer full");
        break;
      }
    }
  }
Exemple #2
0
  /**
   * Write to the socket up to len bytes from the buffer buf starting at position pos.
   *
   * @param buf byte[] the buffer to write from
   * @param pos int starting position in buffer
   * @param len int number of bytes to write
   * @return int on success, the number of bytes written, which may be smaller than len; on failure,
   *     -1
   */
  public int write(byte[] buf, int pos, int len) {
    aa(this, isSender(), "nonsender can't write");
    aa(this, isConnected(), "nonsender can't write");

    // fill buffer
    p(
        this,
        3,
        "write called"); // \n\t buf = " + TCPManager.bytesToString(buf)); p(this, 4, "sendbb
                         // position: " + sendbb.position());
    dumpState(4);
    // p(this, 4, "sendbb limit: " + sendbb.limit());
    // p(this, 4, "sendbb remaining: " + sendbb.remaining());
    // p(this, 4, "sendbb size: " + sendbb.capacity());

    int bytesCopied = Math.min(sendbb.remaining(), len);
    sendbb.put(buf, pos, bytesCopied);
    p(this, 3, "bytes copied: " + bytesCopied);

    // try to send as much as possible
    sendFromBuffer();
    return bytesCopied;
  }