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

SerialStreamBuf * LibSerial::SerialStreamBuf::close (  )  [inline]

If is_open() == false, returns a null pointer. If a put area exists, calls overflow(EOF) to flush characters. Finally it closes the file by calling std::close(mFileDescriptor) where mFileDescriptor is the value returned by the last call to open().

For the implementation of the corresponding function in class filebuf, if the last virtual member function called on *this (between underflow, overflow, seekoff, and seekpos) was overflow then it calls a_codecvt.unshift (possible several times) to determine a termination sequence, inserts those characters and calls overflow(EOF) again. However, this is not implemented here yet.

Postcondition: is_open() == false

Returns:
this on success, a null pointer otherwise.

Definition at line 533 of file SerialStreamBuf.h.

References is_open(), and mFileDescriptor.

Referenced by ~SerialStreamBuf().

        {
            //
            // Return a null pointer if the serial port is not currently open. 
            //
            if( this->is_open() == false ) {
                return 0 ;
            }
            //
            // Otherwise, close the serial port and set the file descriptor
            // to an invalid value.
            //
            if( -1 == ::close(mFileDescriptor) ) {
                //
                // If the close failed then return a null pointer. 
                //
                return 0 ;
            } else {
                //
                // Set the file descriptor to an invalid value, -1. 
                //
                mFileDescriptor = -1 ;
                //
                // On success, return "this" as required by the C++ standard.
                //
                return this ;
            }
        }


Generated by  Doxygen 1.6.0   Back to index