src/nb_socket_io.cpp
// Expects a 10 byte length value prior to the string.
Expects a 10 byte length value prior to the string.
Expects a 10 byte length value prior to the string .
bool NBSocketIO::ReadMessage(string *str, int timeout_secs) const {
  *str = "";
  if (! WaitForReadable(timeout_secs)) {
    return false;
  }
  char len_str[11];
  if (! ReadNBytes(10, len_str)) {
    return false;
  }
  len_str[10] = 0;
  int len;
  if (sscanf(len_str, "%10d", &len) != 1) {
    return false;
  }
  if (len < 0 || len > kMaxMessageLen) {
    Warning("NBSocketIO::ReadMessage() bad length %s\n", len_str);
    return false;
  }
  unique_ptr<char []> buf( new char[len + 1]);
  if (! ReadNBytes(len, buf.get())) {
    return false;
  }
  buf[len] = 0;
  *str = buf.get();
  return true;
}
bool NBSocketIO :: ReadMessage ( string * str , int timeout_secs ) const { * str = " " ; if ( ! WaitForReadable ( timeout_secs ) ) { return false ; } char len_str [ 11 ] ; if ( ! ReadNBytes ( 10 , len_str ) ) { return false ; } len_str [ 10 ] = 0 ; int len ; if ( sscanf ( len_str , " " , & len ) != 1 ) { return false ; } if ( len < 0 || len > kMaxMessageLen ) { Warning ( " \n " , len_str ) ; return false ; } unique_ptr < char [ ] > buf ( new char [ len + 1 ] ) ; if ( ! ReadNBytes ( len , buf . get ( ) ) ) { return false ; } buf [ len ] = 0 ; * str = buf . get ( ) ; return true ; }
Expects a 10 byte length value prior to the string.
Expects a 10 byte length value prior to the string .
// Too many warning messages // Warning("Couldn't parse len_str: \"%s\"\n", len_str); // Needless copy?