Logo Search packages:      
Sourcecode: pwlib version File versions

BOOL PTelnetSocket::Write ( const void *  buf,
PINDEX  len 
) [virtual]

Low level write to the channel. This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written.

The GetErrorCode() function should be consulted after Write() returns FALSE to determine what caused the failure.

The TELNET channel intercepts and escapes commands in the data stream to implement the TELNET protocol.

Returns TRUE if at least len bytes were written to the channel.

Parameters:
buf  Pointer to a block of memory to write.
len  Number of bytes to write.

Reimplemented from PTCPSocket.

Definition at line 146 of file telnet.cxx.

References IAC, IsOurOption(), PChannel::lastWriteCount, TransmitBinary, and PTCPSocket::Write().

{
  const BYTE * base = (const BYTE *)buffer;
  const BYTE * next = base;
  int count = 0;

  while (length > 0) {
    if (*next == '\r' &&
            !(length > 1 && next[1] == '\n') && !IsOurOption(TransmitBinary)) {
      // send the characters
      if (!PTCPSocket::Write(base, (next - base) + 1))
        return FALSE;
      count += lastWriteCount;

      char null = '\0';
      if (!PTCPSocket::Write(&null, 1))
        return FALSE;
      count += lastWriteCount;

      base = next+1;
    }

    if (*next == IAC) {
      // send the characters
      if (!PTCPSocket::Write(base, (next - base) + 1))
        return FALSE;
      count += lastWriteCount;
      base = next;
    }

    next++;
    length--;
  }

  if (next > base) {
    if (!PTCPSocket::Write(base, next - base))
      return FALSE;
    count += lastWriteCount;
  }

  lastWriteCount = count;
  return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index