.TH "KBufferedIO" kde3 "11 Jun 2005" "Version Version 3.4.1" "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
.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
.in -1c
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBbytesWritten\fP (int nbytes)"
.br
.ti -1c
.RI "void \fBclosed\fP (int \fBstate\fP)"
.br
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "virtual \fB~KBufferedIO\fP ()"
.br
.ti -1c
.RI "virtual void \fBcloseNow\fP ()=0"
.br
.ti -1c
.RI "virtual bool \fBsetBufferSize\fP (int rsize, int wsize=-2)"
.br
.ti -1c
.RI "virtual int \fBbytesAvailable\fP () const "
.br
.ti -1c
.RI "virtual int \fBwaitForMore\fP (int msec)=0"
.br
.ti -1c
.RI "virtual int \fBbytesToWrite\fP () const "
.br
.ti -1c
.RI "virtual bool \fBcanReadLine\fP () const "
.br
.ti -1c
.RI "virtual int \fBpeekBlock\fP (char *data, uint maxlen)=0"
.br
.ti -1c
.RI "virtual int \fBunreadBlock\fP (const char *data, uint len)"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "virtual unsigned \fBconsumeReadBuffer\fP (unsigned nbytes, char *destbuffer, bool discard=true)"
.br
.ti -1c
.RI "virtual void \fBconsumeWriteBuffer\fP (unsigned nbytes)"
.br
.ti -1c
.RI "virtual unsigned \fBfeedReadBuffer\fP (unsigned nbytes, const char *buffer, bool atBeginning=false)"
.br
.ti -1c
.RI "virtual unsigned \fBfeedWriteBuffer\fP (unsigned nbytes, const char *buffer)"
.br
.ti -1c
.RI "virtual unsigned \fBreadBufferSize\fP () const "
.br
.ti -1c
.RI "virtual unsigned \fBwriteBufferSize\fP () const "
.br
.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
.ti -1c
.RI "\fBQPtrList\fP< \fBQByteArray\fP > \fBoutBuf\fP"
.br
.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 KExtendedSocket is a subclass of this one. This is so that applications written using QSocket's buffering characteristics will be more easily ported to the more powerful KExtendedSocket 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: 
.PD 0

.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

.PP
Definition at line 56 of file kbufferedio.h.
.SH "Member Enumeration Documentation"
.PP 
.SS "enum \fBKBufferedIO::closeModes\fP"
.PP
The modes for \fBclosed()\fP signal. 
.PP
Definition at line 68 of file kbufferedio.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KBufferedIO::~\fBKBufferedIO\fP ()\fC [virtual]\fP"
.PP
Destroys this class. 
.PP
The flushing of the buffers is implementation dependant. The default implementation discards the contents 
.PP
Definition at line 95 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. 
.PP
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. 
.SS "bool KBufferedIO::setBufferSize (int rsize, int wsize = \fC-2\fP)\fC [virtual]\fP"
.PP
Sets the internal buffer size to value. 
.PP
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

.PP
Definition at line 102 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. 
.PP
\fBReturns:\fP
.RS 4
the number of bytes available for reading 
.RE
.PP

.PP
Definition at line 112 of file kbufferedio.cpp.
.PP
References readBufferSize().
.PP
Referenced by 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. 
.PP
\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

.SS "int KBufferedIO::bytesToWrite () const\fC [virtual]\fP"
.PP
Returns the number of bytes yet to write, still in the write buffer. 
.PP
\fBReturns:\fP
.RS 4
the number of unwritten bytes in the write buffer 
.RE
.PP

.PP
Definition at line 117 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. 
.PP
The default implementation reads directly from inBuf, 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

.PP
Definition at line 123 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. 
.PP
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

.SS "int KBufferedIO::unreadBlock (const char * data, uint len)\fC [virtual]\fP"
.PP
Unreads some data. 
.PP
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
\fIlen\fP the size of the data 
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes actually unread 
.RE
.PP

.PP
Definition at line 153 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. 
.PP
\fBParameters:\fP
.RS 4
\fInbytes\fP the number of bytes sent. 
.RE
.PP

.SS "void KBufferedIO::closed (int state)\fC [signal]\fP"
.PP
This signal gets sent when the stream is closed. 
.PP
The \fCstate\fP parameter will give the current state, in OR-ed bits: 
.PD 0

.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 closeNow, 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

.SS "unsigned KBufferedIO::consumeReadBuffer (unsigned nbytes, char * destbuffer, bool discard = \fCtrue\fP)\fC [protected, virtual]\fP"
.PP
Consumes data from the input buffer. 
.PP
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

.PP
Definition at line 162 of file kbufferedio.cpp.
.PP
References QPtrList::first(), inBuf, QPtrList::next(), readBufferSize(), and QPtrList::remove().
.SS "void KBufferedIO::consumeWriteBuffer (unsigned nbytes)\fC [protected, virtual]\fP"
.PP
Consumes data from the output buffer. 
.PP
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

.PP
Definition at line 212 of file kbufferedio.cpp.
.PP
References QPtrList::current(), QPtrList::first(), outBuf, QPtrList::remove(), and QIODevice::size().
.SS "unsigned KBufferedIO::feedReadBuffer (unsigned nbytes, const char * buffer, bool atBeginning = \fCfalse\fP)\fC [protected, virtual]\fP"
.PP
Feeds data into the input buffer. 
.PP
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

.PP
Definition at line 241 of file kbufferedio.cpp.
.PP
References QPtrList::append(), inBuf, and QPtrList::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. 
.PP
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

.PP
Definition at line 257 of file kbufferedio.cpp.
.PP
References QPtrList::append(), and outBuf.
.SS "unsigned KBufferedIO::readBufferSize () const\fC [protected, virtual]\fP"
.PP
Returns the number of bytes in the read buffer. 
.PP
\fBReturns:\fP
.RS 4
the size of the read buffer in bytes 
.RE
.PP

.PP
Definition at line 268 of file kbufferedio.cpp.
.PP
References QPtrList::first().
.PP
Referenced by bytesAvailable(), and consumeReadBuffer().
.SS "unsigned KBufferedIO::writeBufferSize () const\fC [protected, virtual]\fP"
.PP
Returns the number of bytes in the write buffer. 
.PP
\fBReturns:\fP
.RS 4
the size of the write buffer in bytes 
.RE
.PP

.PP
Definition at line 281 of file kbufferedio.cpp.
.PP
Referenced by bytesToWrite().
.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. 
.PP
Definition at line 212 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. 
.PP
Definition at line 218 of file kbufferedio.h.
.PP
Referenced by consumeWriteBuffer(), and feedWriteBuffer().

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