src/socket_io.cpp
// Read a line terminated by \n.  We strip the \n in the string returned.
Read a line terminated by \n.  We strip the \n in the string returned.
Read a line terminated by \ n . We strip the \ n in the string returned .
bool SocketIO::ReadLine(string *str) const {
  *str = "";
  char c;
  while (true) {
    if (! ReadChar(&c)) {
      if (*str != "") {
	Warning("ReadLine: failed with partial line \"%s\"; fd %i\n", str->c_str(), fd_);
      }
      return false;
    }
    *str += c;
    int len = str->size();
    if (len >= 1 && (*str)[len-1] == '\n') {
      str->resize(len - 1);
      return true;
    }
  }
}
bool SocketIO :: ReadLine ( string * str ) const { * str = " " ; char c ; while ( true ) { if ( ! ReadChar ( & c ) ) { if ( * str != " " ) { Warning ( " \" \" \n " , str -> c_str ( ) , fd_ ) ; } return false ; } * str += c ; int len = str -> size ( ) ; if ( len >= 1 && ( * str ) [ len - 1 ] == ' \n ' ) { str -> resize ( len - 1 ) ; return true ; } } }
Read a line terminated by \n.
Read a line terminated by \ n .
// It is common for ReadChar() to fail if the other side closes the socket.  Normally // this happens before anything has been read.  It's unusual (although presumably possible) // for this to happen when part of a line has been read, so we print a warning in this // case.