src/wire/libevent_socket.cpp
bool LibeventSocket::ReadPacketHeader() {
  size_t initial_read_size = sizeof(int32_t);
  if (pkt_manager.is_started == true) {
    // All packets other than the startup packet have a 5B header
    initial_read_size++;
  }
  // check if header bytes are available
  if (IsReadDataAvailable(initial_read_size) == false) {
    // nothing more to read
    return false;
  }

  // get packet size from the header
  if (pkt_manager.is_started == true) {
    // Header also contains msg type
    rpkt.msg_type =
        static_cast<NetworkMessageType>(rbuf_.GetByte(rbuf_.buf_ptr));
    // extract packet size
    GetSizeFromPktHeader(rbuf_.buf_ptr + 1);
  } else {
    GetSizeFromPktHeader(rbuf_.buf_ptr);
  }

  // do we need to use the extended buffer for this packet?
  rpkt.is_extended = (rpkt.len > rbuf_.GetMaxSize());

  if (rpkt.is_extended) {
    LOG_DEBUG("Using extended buffer for pkt size:%ld", rpkt.len);
    // reserve space for the extended buffer
    rpkt.ReserveExtendedBuffer();
  }

  // we have processed the data, move buffer pointer
  rbuf_.buf_ptr += initial_read_size;
  rpkt.header_parsed = true;

  return true;
}
// The function tries to do a preliminary read to fetch the size value and
// then reads the rest of the packet.
// Assume: Packet length field is always 32-bit int
The function tries to do a preliminary read to fetch the size value and
then reads the rest of the packet.
Assume: Packet length field is always 32-bit int
The function tries to do a preliminary read to fetch the size value and then reads the rest of the packet . Assume : Packet length field is always 32 - bit int
bool LibeventSocket::ReadPacketHeader() {
  size_t initial_read_size = sizeof(int32_t);
  if (pkt_manager.is_started == true) {
    initial_read_size++;
  }
  if (IsReadDataAvailable(initial_read_size) == false) {
    return false;
  }
  if (pkt_manager.is_started == true) {
    rpkt.msg_type =
        static_cast<NetworkMessageType>(rbuf_.GetByte(rbuf_.buf_ptr));
    GetSizeFromPktHeader(rbuf_.buf_ptr + 1);
  } else {
    GetSizeFromPktHeader(rbuf_.buf_ptr);
  }
  rpkt.is_extended = (rpkt.len > rbuf_.GetMaxSize());
  if (rpkt.is_extended) {
    LOG_DEBUG("Using extended buffer for pkt size:%ld", rpkt.len);
    rpkt.ReserveExtendedBuffer();
  }
  rbuf_.buf_ptr += initial_read_size;
  rpkt.header_parsed = true;
  return true;
}
bool LibeventSocket :: ReadPacketHeader ( ) { size_t initial_read_size = sizeof ( int32_t ) ; if ( pkt_manager . is_started == true ) { initial_read_size ++ ; } if ( IsReadDataAvailable ( initial_read_size ) == false ) { return false ; } if ( pkt_manager . is_started == true ) { rpkt . msg_type = static_cast < NetworkMessageType > ( rbuf_ . GetByte ( rbuf_ . buf_ptr ) ) ; GetSizeFromPktHeader ( rbuf_ . buf_ptr + 1 ) ; } else { GetSizeFromPktHeader ( rbuf_ . buf_ptr ) ; } rpkt . is_extended = ( rpkt . len > rbuf_ . GetMaxSize ( ) ) ; if ( rpkt . is_extended ) { LOG_DEBUG ( " " , rpkt . len ) ; rpkt . ReserveExtendedBuffer ( ) ; } rbuf_ . buf_ptr += initial_read_size ; rpkt . header_parsed = true ; return true ; }
The function tries to do a preliminary read to fetch the size value and
then reads the rest of the packet.
The function tries to do a preliminary read to fetch the size value and then reads the rest of the packet .
// All packets other than the startup packet have a 5B header // check if header bytes are available // nothing more to read // get packet size from the header // Header also contains msg type // extract packet size // do we need to use the extended buffer for this packet? // reserve space for the extended buffer // we have processed the data, move buffer pointer