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

std::streamsize SerialStreamBuf::showmanyc (  )  [protected, virtual]

Check, wether input is available on the port. If you call SerialStream::in_avail, this method will be called to check for available input.

            while( serial_port.rdbuf()->in_avail() > 0  ) {
              serial_port.get(ch);
              ...
            }

Definition at line 811 of file SerialStreamBuf.cc.

References mFileDescriptor, mPutbackAvailable, and mPutbackChar.

                                         {

  int retval = -1;

  if ( -1 == mFileDescriptor ) {
    return -1;
  };

  if ( mPutbackAvailable ) {

    // We still have a character left in the buffer.
    retval = 1;

  } else {

    // Switch to non-blocking read.
    int flags = fcntl(this->mFileDescriptor, F_GETFL, 0) ;
    if( -1 == fcntl( this->mFileDescriptor, 
                     F_SETFL, 
                     flags | O_NONBLOCK ) ) {
        return -1;
    }

    // Try to read a character.
    retval = read(mFileDescriptor, &mPutbackChar, 1);

    if ( retval == 1 ) {
      mPutbackAvailable = true;
    } else
      retval = 0;

    // Switch back to blocking read.
    if( -1 == fcntl( this->mFileDescriptor, 
                     F_SETFL, 
                     flags ) ) {
        return -1;
    }
  };
  return retval;    

}


Generated by  Doxygen 1.6.0   Back to index