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

streambuf::int_type SerialStreamBuf::underflow (  )  [protected, virtual]

Reads and returns the next character from the associated serial port if one otherwise returns traits::eof(). This method is used for buffered I/O while uflow() is called for unbuffered I/O.

Returns:
The next character from the serial port.

Definition at line 854 of file SerialStreamBuf.cc.

References mFileDescriptor, mPutbackAvailable, and mPutbackChar.

Referenced by uflow().

                           {
    //
    // If we do not have a valid file handler for the serial port, we
    // cannot do much.
    //
    if( -1 == mFileDescriptor ) {
        return traits_type::eof() ;
    }
    //
    // Read the next character from the serial port. 
    //
    char next_ch ;
    ssize_t retval ;
    //
    // If a putback character is available then we return that
    // character. However, we are not supposed to change the value of
    // gptr() in this routine so we leave mPutbackAvailable set to true.
    // 
    if ( mPutbackAvailable ) {
        next_ch = mPutbackChar ;
    } else {
        //
        // If no putback character is available then we need to read one
        // character from the serial port.
        //

        retval = read(mFileDescriptor, &next_ch, 1);

        //
        // Make the next character the putback character. This has the
        // effect of returning the next character without changing gptr()
        // as required by the C++ standard.
        //
        if( retval == 1 ) {
            mPutbackChar = next_ch ;
            mPutbackAvailable = true ;
        } else if( ( -1 == retval ) ||
                   (  0 == retval ) ) {
            //
            // If we had a problem reading the character, we return
            // traits::eof().
            //
            return traits_type::eof() ;
        }
    }
    //
    // :NOTE: Wed Aug  9 21:26:51 2000 Pagey
    // The value of mPutbackAvailable is always true when the code
    // reaches here.
    //
    //
    // Return the character as an int value as required by the C++
    // standard.
    //
    return traits_type::to_int_type(next_ch) ;
}


Generated by  Doxygen 1.6.0   Back to index