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

BOOL PTelnetSocket::SendCommand ( Command  cmd,
int  opt = 0 

Send an escaped IAC command. The opt parameters meaning depends on the command being sent:

opt is Options code.

TRUE is flush buffer.

InterruptProcess, Break, AbortProcess, SuspendProcess
TRUE is synchronise.

Synchronises the TELNET streams, inserts the data mark into outgoing data stream and sends an out of band data to the remote to flush all data in the stream up until the syncronisation command.

TRUE if the command was successfully sent.
cmd  Command code to send
opt  Option for command code.

Definition at line 191 of file telnet.cxx.

References AbortOutput, AbortProcess, Break, DataMark, DO, DONT, IAC, InterruptProcess, PTCPSocket::Read(), PChannel::readTimeout, SuspendProcess, TimingMark, WILL, WONT, PTCPSocket::Write(), and PTCPSocket::WriteOutOfBand().

Referenced by OnDo(), OnDont(), OnWill(), OnWont(), SendDo(), SendDont(), SendWill(), and SendWont().

  BYTE buffer[3];
  buffer[0] = IAC;
  buffer[1] = (BYTE)cmd;

  switch (cmd) {
    case DO :
    case DONT :
    case WILL :
    case WONT :
      buffer[2] = (BYTE)opt;
      return PTCPSocket::Write(buffer, 3);

    case InterruptProcess :
    case Break :
    case AbortProcess :
    case SuspendProcess :
    case AbortOutput :
      if (opt) {
        // Send the command
        if (!PTCPSocket::Write(buffer, 2))
          return FALSE;
        // Send a TimingMark for output flush.
        buffer[1] = TimingMark;
        if (!PTCPSocket::Write(buffer, 2))
          return FALSE;
        // Send a DataMark for synchronisation.
        if (cmd != AbortOutput) {
          buffer[1] = DataMark;
          if (!PTCPSocket::Write(buffer, 2))
            return FALSE;
          // Send the datamark character as the only out of band data byte.
          if (!WriteOutOfBand(&buffer[1], 1))
            return FALSE;
        // Then flush any waiting input data.
        PTimeInterval oldTimeout = readTimeout;
        readTimeout = 0;
        while (PTCPSocket::Read(buffer, sizeof(buffer)))
        readTimeout = oldTimeout;

    default :
      return PTCPSocket::Write(buffer, 2);

  return TRUE;

Generated by  Doxygen 1.6.0   Back to index