src/wire/libevent_socket.cpp
bool LibeventSocket::ReadPacket() {
  if (rpkt.is_extended) {
    // extended packet mode
    auto bytes_available = rbuf_.buf_size - rbuf_.buf_ptr;
    auto bytes_required = rpkt.ExtendedBytesRequired();
    // read minimum of the two ranges
    auto read_size = std::min(bytes_available, bytes_required);
    rpkt.AppendToExtendedBuffer(rbuf_.Begin() + rbuf_.buf_ptr,
                                rbuf_.Begin() + rbuf_.buf_ptr + read_size);
    // data has been copied, move ptr
    rbuf_.buf_ptr += read_size;
    if (bytes_required > bytes_available) {
      // more data needs to be read
      return false;
    }
    // all the data has been read
    rpkt.InitializePacket();
    return true;
  } else {
    if (IsReadDataAvailable(rpkt.len) == false) {
      // data not available yet, return
      return false;
    }
    // Initialize the packet's "contents"
    rpkt.InitializePacket(rbuf_.buf_ptr, rbuf_.Begin());
    // We have processed the data, move buffer pointer
    rbuf_.buf_ptr += rpkt.len;
  }
  return true;
}
// Tries to read the contents of a single packet, returns true on success, false
// on failure.
Tries to read the contents of a single packet, returns true on success, false
on failure.
Tries to read the contents of a single packet returns true on success false on failure .
bool LibeventSocket::ReadPacket() {
  if (rpkt.is_extended) {
    auto bytes_available = rbuf_.buf_size - rbuf_.buf_ptr;
    auto bytes_required = rpkt.ExtendedBytesRequired();
    auto read_size = std::min(bytes_available, bytes_required);
    rpkt.AppendToExtendedBuffer(rbuf_.Begin() + rbuf_.buf_ptr,
                                rbuf_.Begin() + rbuf_.buf_ptr + read_size);
    rbuf_.buf_ptr += read_size;
    if (bytes_required > bytes_available) {
      return false;
    }
    rpkt.InitializePacket();
    return true;
  } else {
    if (IsReadDataAvailable(rpkt.len) == false) {
      return false;
    }
    rpkt.InitializePacket(rbuf_.buf_ptr, rbuf_.Begin());
    rbuf_.buf_ptr += rpkt.len;
  }
  return true;
}
bool LibeventSocket :: ReadPacket ( ) { if ( rpkt . is_extended ) { auto bytes_available = rbuf_ . buf_size - rbuf_ . buf_ptr ; auto bytes_required = rpkt . ExtendedBytesRequired ( ) ; auto read_size = std :: min ( bytes_available , bytes_required ) ; rpkt . AppendToExtendedBuffer ( rbuf_ . Begin ( ) + rbuf_ . buf_ptr , rbuf_ . Begin ( ) + rbuf_ . buf_ptr + read_size ) ; rbuf_ . buf_ptr += read_size ; if ( bytes_required > bytes_available ) { return false ; } rpkt . InitializePacket ( ) ; return true ; } else { if ( IsReadDataAvailable ( rpkt . len ) == false ) { return false ; } rpkt . InitializePacket ( rbuf_ . buf_ptr , rbuf_ . Begin ( ) ) ; rbuf_ . buf_ptr += rpkt . len ; } return true ; }
Tries to read the contents of a single packet, returns true on success, false
on failure.
Tries to read the contents of a single packet returns true on success false on failure .
// extended packet mode // read minimum of the two ranges // data has been copied, move ptr // more data needs to be read // all the data has been read // data not available yet, return // Initialize the packet's "contents" // We have processed the data, move buffer pointer