.TH "KBufferedIO" 3 "28 Jan 2004" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KBufferedIO \- This abstract class implements basic functionality for buffered input/output. Buffered I/O.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <kbufferedio.h>\fP
.PP
Inherits \fBKAsyncIO\fP.
.PP
Inherited by \fBKExtendedSocket\fP.
.PP
.SS "Public Types"

.in +1c
.ti -1c
.RI "enum \fBcloseModes\fP { \fBavailRead\fP =  0x01, \fBdirtyWrite\fP =  0x02, \fBinvoluntary\fP =  0x10, \fBdelayed\fP =  0x20, \fBclosedNow\fP =  0x40 }"
.br
.RI "\fIThe modes for \fBclosed\fP() signal. \fP"
.in -1c
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBbytesWritten\fP (int nbytes)"
.br
.RI "\fIThis signal gets sent whenever bytes are written from the buffer. \fP"
.ti -1c
.RI "void \fBclosed\fP (int \fBstate\fP)"
.br
.RI "\fIThis signal gets sent when the stream is closed. \fP"
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "virtual \fB~KBufferedIO\fP ()"
.br
.RI "\fIDestroys this class. \fP"
.ti -1c
.RI "virtual void \fBcloseNow\fP ()=0"
.br
.RI "\fICloses the stream now, discarding the contents of the write buffer. \fP"
.ti -1c
.RI "virtual bool \fBsetBufferSize\fP (int rsize, int wsize=-2)"
.br
.RI "\fISets the internal buffer size to value. \fP"
.ti -1c
.RI "virtual int \fBbytesAvailable\fP () const "
.br
.RI "\fIReturns the number of bytes available for reading in the read buffer. \fP"
.ti -1c
.RI "virtual int \fBwaitForMore\fP (int msec)=0"
.br
.RI "\fIWaits for more data to be available and returns the amount of available data then. \fP"
.ti -1c
.RI "virtual int \fBbytesToWrite\fP () const "
.br
.RI "\fIReturns the number of bytes yet to write, still in the write buffer. \fP"
.ti -1c
.RI "virtual bool \fBcanReadLine\fP () const "
.br
.RI "\fIChecks whether there is enough data in the buffer to read a line. \fP"
.ti -1c
.RI "virtual int \fBpeekBlock\fP (char *data, uint maxlen)=0"
.br
.RI "\fIReads into the user buffer at most maxlen bytes, but does not consume that data from the read buffer. \fP"
.ti -1c
.RI "virtual int \fBunreadBlock\fP (const  char *data, uint len)"
.br
.RI "\fIUnreads some data. \fP"
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "virtual unsigned \fBconsumeReadBuffer\fP (unsigned nbytes, char *destbuffer, bool discard=true)"
.br
.RI "\fIConsumes data from the input buffer. \fP"
.ti -1c
.RI "virtual void \fBconsumeWriteBuffer\fP (unsigned nbytes)"
.br
.RI "\fIConsumes data from the output buffer. \fP"
.ti -1c
.RI "virtual unsigned \fBfeedReadBuffer\fP (unsigned nbytes, const  char *buffer, bool atBeginning=false)"
.br
.RI "\fIFeeds data into the input buffer. \fP"
.ti -1c
.RI "virtual unsigned \fBfeedWriteBuffer\fP (unsigned nbytes, const  char *buffer)"
.br
.RI "\fIFeeds data into the output buffer. \fP"
.ti -1c
.RI "virtual unsigned \fBreadBufferSize\fP () const "
.br
.RI "\fIReturns the number of bytes in the read buffer. \fP"
.ti -1c
.RI "virtual unsigned \fBwriteBufferSize\fP () const "
.br
.RI "\fIReturns the number of bytes in the write buffer. \fP"
.ti -1c
.RI "virtual void \fBvirtual_hook\fP (int id, void *data)"
.br
.in -1c
.SS "Protected Attributes"

.in +1c
.ti -1c
.RI "\fBQPtrList\fP< \fBQByteArray\fP > \fBinBuf\fP"
.br
.RI "\fIFor an explanation on how this buffer work, please refer to the comments at the top of \fBkbufferedio.cpp\fP. \fP"
.ti -1c
.RI "\fBQPtrList\fP< \fBQByteArray\fP > \fBoutBuf\fP"
.br
.RI "\fIFor an explanation on how this buffer work, please refer to the comments at the top of \fBkbufferedio.cpp\fP. \fP"
.ti -1c
.RI "unsigned \fBinBufIndex\fP"
.br
.ti -1c
.RI "unsigned \fBoutBufIndex\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
This abstract class implements basic functionality for buffered input/output. Buffered I/O. 

Through the available methods, you can find out how many bytes are available for reading, how many are still unsent and you can peek at the buffered data.
.PP
This class was intentionally written to resemble \fBQSocket\fP, because \fBKExtendedSocket\fP is a subclass of this one. This is so that applications written using \fBQSocket\fP's buffering characteristics will be more easily ported to the more powerful \fBKExtendedSocket\fP class.
.PP
KBufferedIO already provides a powerful internal buffering algorithm. However, this does not include the I/O itself, which must be implemented in derived classes. Thus, to implement a class that does some I/O, you must override, in addition to the pure virtual \fBQIODevice\fP methods, these two: 
.IP "\(bu" 2
\fBcloseNow\fP() 
.IP "\(bu" 2
\fBwaitForMore\fP()
.PP
If your derived class reimplements the buffering algorithm, you must then decide which buffering functions to override. For instance, you may want to change the protected functions like \fBfeedReadBuffer\fP() and \fBconsumeReadBuffer\fP().
.PP
\fBAuthor:\fP
.RS 4
Thiago Macieira <thiagom@mail.com> 
.RE
.PP
\fBVersion:\fP
.RS 4
\fBId\fP.RS 4
\fBkbufferedio.h\fP,v 1.10 2002/09/08 15:15:33 tjansen Exp 
.RE
.PP
.RE
.PP

.PP
Definition at line 59 of file kbufferedio.h.
.SH "Member Enumeration Documentation"
.PP 
.SS "enum \fBKBufferedIO::closeModes\fP"
.PP
The modes for \fBclosed\fP() signal. Definition at line 71 of file kbufferedio.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KBufferedIO::~\fBKBufferedIO\fP ()\fC [virtual]\fP"
.PP
Destroys this class. The flushing of the buffers is implementation dependant. The default implementation discards the contents Definition at line 97 of file kbufferedio.cpp.
.SH "Member Function Documentation"
.PP 
.SS "virtual void KBufferedIO::closeNow ()\fC [pure virtual]\fP"
.PP
Closes the stream now, discarding the contents of the write buffer. That is, we won't try to flush that buffer before closing. If you want that buffer to be flushed, you can call \fBQIODevice::flush\fP(), which is blocking, and then closeNow, or you can call \fBQIODevice::close\fP() for a delayed close. Implemented in \fBKExtendedSocket\fP.
.SS "bool KBufferedIO::setBufferSize (int rsize, int wsize = -2)\fC [virtual]\fP"
.PP
Sets the internal buffer size to value. Not all implementations support this.
.PP
The parameters may be 0 to make the class unbuffered or -1 to let the class choose the size (which may be unlimited) or -2 to leave the buffer size untouched.
.PP
Note that setting the write buffer size to any value smaller than the current size of the buffer will force it to flush first, which can make this call blocking.
.PP
The default implementation does not support setting the buffer sizes. You can only call this function with values -1 for 'don't care' or -2 for 'unchanged' 
.PP
\fBParameters:\fP
.RS 4
\fIrsize\fP the size of the read buffer 
.br
\fIwsize\fP the size of the write buffer 
.RE
.PP
\fBReturns:\fP
.RS 4
true if setting both was ok. If false is returned, the buffers were left unchanged. 
.RE
.PP
Reimplemented in \fBKExtendedSocket\fP.
.PP
Definition at line 104 of file kbufferedio.cpp.
.SS "int KBufferedIO::bytesAvailable () const\fC [virtual]\fP"
.PP
Returns the number of bytes available for reading in the read buffer. \fBReturns:\fP
.RS 4
the number of bytes available for reading 
.RE
.PP
Reimplemented in \fBKExtendedSocket\fP.
.PP
Definition at line 114 of file kbufferedio.cpp.
.PP
References readBufferSize().
.PP
Referenced by KExtendedSocket::bytesAvailable(), and canReadLine().
.SS "virtual int KBufferedIO::waitForMore (int msec)\fC [pure virtual]\fP"
.PP
Waits for more data to be available and returns the amount of available data then. \fBParameters:\fP
.RS 4
\fImsec\fP number of milliseconds to wait, -1 to wait forever 
.RE
.PP
\fBReturns:\fP
.RS 4
-1 if we cannot wait (e.g., that doesn't make sense in this stream) 
.RE
.PP
Implemented in \fBKExtendedSocket\fP.
.SS "int KBufferedIO::bytesToWrite () const\fC [virtual]\fP"
.PP
Returns the number of bytes yet to write, still in the write buffer. \fBReturns:\fP
.RS 4
the number of unwritten bytes in the write buffer 
.RE
.PP
Definition at line 119 of file kbufferedio.cpp.
.PP
References writeBufferSize().
.SS "bool KBufferedIO::canReadLine () const\fC [virtual]\fP"
.PP
Checks whether there is enough data in the buffer to read a line. The default implementation reads directly from \fBinBuf\fP, so if your implementation changes the meaning of that member, then you must override this function. 
.PP
\fBReturns:\fP
.RS 4
true when there is enough data in the buffer to read a line 
.RE
.PP
Definition at line 125 of file kbufferedio.cpp.
.PP
References bytesAvailable(), QPtrList::first(), and QPtrList::next().
.SS "virtual int KBufferedIO::peekBlock (char * data, uint maxlen)\fC [pure virtual]\fP"
.PP
Reads into the user buffer at most maxlen bytes, but does not consume that data from the read buffer. This is useful to check whether we already have the needed data to process something.
.PP
This function may want to try and read more data from the system provided it won't block.
.PP
\fBParameters:\fP
.RS 4
\fIdata\fP the user buffer pointer, at least maxlen bytes long 
.br
\fImaxlen\fP the maximum length to be peeked 
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes actually copied. 
.RE
.PP
Implemented in \fBKExtendedSocket\fP.
.SS "int KBufferedIO::unreadBlock (const char * data, uint len)\fC [virtual]\fP"
.PP
Unreads some data. That is, write the data to the beginning of the read buffer, so that next calls to readBlock or peekBlock will see this data instead.
.PP
Note not all devices implement this since this could mean a semantic problem. For instance, sockets are sequential devices, so they won't accept unreading. 
.PP
\fBParameters:\fP
.RS 4
\fIdata\fP the data to be unread 
.br
\fIsize\fP the size of the data 
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes actually unread 
.RE
.PP
Reimplemented in \fBKExtendedSocket\fP.
.PP
Definition at line 155 of file kbufferedio.cpp.
.PP
References feedReadBuffer().
.SS "void KBufferedIO::bytesWritten (int nbytes)\fC [signal]\fP"
.PP
This signal gets sent whenever bytes are written from the buffer. \fBParameters:\fP
.RS 4
\fInbytes\fP the number of bytes sent. 
.RE
.PP
Referenced by KExtendedSocket::flush(), and KExtendedSocket::writeBlock().
.SS "void KBufferedIO::closed (int state)\fC [signal]\fP"
.PP
This signal gets sent when the stream is closed. The \fCstate\fP parameter will give the current state, in OR-ed bits: 
.IP "\(bu" 2
availRead: read buffer contains data to be read 
.IP "\(bu" 2
dirtyWrite: write buffer wasn't empty when the stream closed 
.IP "\(bu" 2
involuntary: the stream wasn't closed due to user request (i.e., call to close). Probably remote end closed it 
.IP "\(bu" 2
delayed: the stream was closed voluntarily by the user, but it happened only after the write buffer was emptied 
.IP "\(bu" 2
closedNow: the stream was closed voluntarily by the user, by explicitly calling \fBcloseNow\fP, which means the write buffer's contents may have been discarded 
.PP
\fBParameters:\fP
.RS 4
\fIstate\fP the state (see function description) 
.RE
.PP

.PP
Referenced by KExtendedSocket::close(), and KExtendedSocket::closeNow().
.SS "unsigned KBufferedIO::consumeReadBuffer (unsigned nbytes, char * destbuffer, bool discard = true)\fC [protected, virtual]\fP"
.PP
Consumes data from the input buffer. That is, this will copy the data stored in the input (read) buffer into the given \fCdestbuffer\fP, as much as \fCnbytes\fP. 
.PP
\fBParameters:\fP
.RS 4
\fInbytes\fP the maximum amount of bytes to copy into the buffer 
.br
\fIdestbuffer\fP the destination buffer into which to copy the data 
.br
\fIdiscard\fP whether to discard the copied data after the operation 
.RE
.PP
\fBReturns:\fP
.RS 4
the real amount of data copied. If it is less than nbytes, then all the buffer was copied. 
.RE
.PP
Definition at line 164 of file kbufferedio.cpp.
.PP
References QPtrList< QByteArray >::first(), inBuf, QPtrList< QByteArray >::next(), readBufferSize(), and QPtrList< QByteArray >::remove().
.PP
Referenced by KExtendedSocket::peekBlock(), KExtendedSocket::readBlock(), KExtendedSocket::release(), and KExtendedSocket::setBufferSize().
.SS "void KBufferedIO::consumeWriteBuffer (unsigned nbytes)\fC [protected, virtual]\fP"
.PP
Consumes data from the output buffer. Since this is called whenever we managed to send data out the wire, we can only discard this amount from the buffer. There is no copying and no 'peeking' for the output buffer.
.PP
Note this function should be called AFTER the data was sent. After it is called, the data is no longer available in the buffer. And don't pass wrong nbytes values. 
.PP
\fBParameters:\fP
.RS 4
\fInbytes\fP the amount of bytes to discard 
.RE
.PP
Definition at line 214 of file kbufferedio.cpp.
.PP
References QPtrList< QByteArray >::current(), QPtrList< QByteArray >::first(), outBuf, and QPtrList< QByteArray >::remove().
.PP
Referenced by KExtendedSocket::flush(), KExtendedSocket::release(), and KExtendedSocket::setBufferSize().
.SS "unsigned KBufferedIO::feedReadBuffer (unsigned nbytes, const char * buffer, bool atBeginning = false)\fC [protected, virtual]\fP"
.PP
Feeds data into the input buffer. This happens when we detected available data in the device and read it.
.PP
The data will be appended to the buffer or inserted at the beginning, depending on whether \fCatBeginning\fP is set or not. 
.PP
\fBParameters:\fP
.RS 4
\fInbytes\fP the number of bytes in the buffer 
.br
\fIbuffer\fP the data that was read 
.br
\fIatBeginning\fP whether to append or insert at the beginning 
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes that have been appended 
.RE
.PP
Definition at line 243 of file kbufferedio.cpp.
.PP
References QPtrList< QByteArray >::append(), inBuf, and QPtrList< QByteArray >::prepend().
.PP
Referenced by unreadBlock().
.SS "unsigned KBufferedIO::feedWriteBuffer (unsigned nbytes, const char * buffer)\fC [protected, virtual]\fP"
.PP
Feeds data into the output buffer. This happens when the user told us to write some data. The data will be appended to the buffer. 
.PP
\fBParameters:\fP
.RS 4
\fInbytes\fP the number of bytes in the buffer 
.br
\fIbuffer\fP the data that is to be written 
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes that have been appended 
.RE
.PP
Definition at line 259 of file kbufferedio.cpp.
.PP
References QPtrList< QByteArray >::append(), and outBuf.
.PP
Referenced by KExtendedSocket::writeBlock().
.SS "unsigned KBufferedIO::readBufferSize () const\fC [protected, virtual]\fP"
.PP
Returns the number of bytes in the read buffer. \fBReturns:\fP
.RS 4
the size of the read buffer in bytes 
.RE
.PP
Definition at line 270 of file kbufferedio.cpp.
.PP
Referenced by bytesAvailable(), KExtendedSocket::close(), KExtendedSocket::closeNow(), consumeReadBuffer(), KExtendedSocket::release(), and KExtendedSocket::setBufferSize().
.SS "unsigned KBufferedIO::writeBufferSize () const\fC [protected, virtual]\fP"
.PP
Returns the number of bytes in the write buffer. \fBReturns:\fP
.RS 4
the size of the write buffer in bytes 
.RE
.PP
Definition at line 283 of file kbufferedio.cpp.
.PP
Referenced by bytesToWrite(), KExtendedSocket::close(), KExtendedSocket::closeNow(), KExtendedSocket::flush(), KExtendedSocket::release(), KExtendedSocket::setBufferSize(), and KExtendedSocket::writeBlock().
.SH "Member Data Documentation"
.PP 
.SS "\fBQPtrList\fP<\fBQByteArray\fP> \fBKBufferedIO::inBuf\fP\fC [protected]\fP"
.PP
For an explanation on how this buffer work, please refer to the comments at the top of \fBkbufferedio.cpp\fP. Definition at line 215 of file kbufferedio.h.
.PP
Referenced by consumeReadBuffer(), and feedReadBuffer().
.SS "\fBQPtrList\fP<\fBQByteArray\fP> \fBKBufferedIO::outBuf\fP\fC [protected]\fP"
.PP
For an explanation on how this buffer work, please refer to the comments at the top of \fBkbufferedio.cpp\fP. Definition at line 221 of file kbufferedio.h.
.PP
Referenced by consumeWriteBuffer(), feedWriteBuffer(), and KExtendedSocket::flush().

.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
