Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PInternetProtocol::ReadLine ( PString line,
BOOL  allowContinuation = FALSE 
) [virtual, inherited]

Read a string from the socket channel up to a CR/LF pair.

If the unstuffLine parameter is set then the function will remove the '.' character from the start of any line that begins with two consecutive '.' characters. A line that has is exclusively a '.' character will make the function return FALSE.

Note this function will block for the time specified by the PChannel::SetReadTimeout() function for only the first character in the line. The rest of the characters must each arrive within the time set by the readLineTimeout member variable. The timeout is set back to the original setting when the function returns.

Returns:
TRUE if a CR/LF pair was received, FALSE if a timeout or error occurred.
Parameters:
line  String to receive a CR/LF terminated line.
allowContinuation  Flag to handle continued lines.

Definition at line 436 of file inetprot.cxx.

References PChannel::GetLastReadCount(), PChannel::GetReadTimeout(), PIndirectChannel::Read(), PChannel::ReadChar(), PChannel::SetReadTimeout(), and PInternetProtocol::UnRead().

Referenced by PPOP3Client::GetMessageHeaders(), PPOP3Client::GetMessageSizes(), PPOP3Client::LogIn(), OnTextData(), PInternetProtocol::ReadCommand(), and PInternetProtocol::ReadResponse().

{
  str = PString();

  PCharArray line(100);
  PINDEX count = 0;
  BOOL gotEndOfLine = FALSE;

  int c = ReadChar();
  if (c < 0)
    return FALSE;

  PTimeInterval oldTimeout = GetReadTimeout();
  SetReadTimeout(readLineTimeout);

  while (c >= 0 && !gotEndOfLine) {
    if (unReadCount == 0) {
      char readAhead[1000];
      SetReadTimeout(0);
      if (PIndirectChannel::Read(readAhead, sizeof(readAhead)))
        UnRead(readAhead, GetLastReadCount());
      SetReadTimeout(readLineTimeout);
    }
    switch (c) {
      case '\b' :
      case '\177' :
        if (count > 0)
          count--;
        c = ReadChar();
        break;

      case '\r' :
        c = ReadChar();
        switch (c) {
          case -1 :
          case '\n' :
            break;

          case '\r' :
            c = ReadChar();
            if (c == '\n')
              break;
            UnRead(c);
            c = '\r';
            // Then do default case

          default :
            UnRead(c);
        }
        // Then do line feed case

      case '\n' :
        if (count == 0 || !allowContinuation || (c = ReadChar()) < 0)
          gotEndOfLine = TRUE;
        else if (c != ' ' && c != '\t') {
          UnRead(c);
          gotEndOfLine = TRUE;
        }
        break;

      default :
        if (count >= line.GetSize())
          line.SetSize(count + 100);
        line[count++] = (char)c;
        c = ReadChar();
    }
  }

  SetReadTimeout(oldTimeout);

  if (count > 0)
    str = PString(line, count);
  return gotEndOfLine;
}


Generated by  Doxygen 1.6.0   Back to index