kdecore Library API Documentation

KNetwork::KBufferedSocket Class Reference

Buffered stream sockets. More...

#include <kbufferedsocket.h>

Inheritance diagram for KNetwork::KBufferedSocket:

KNetwork::KStreamSocket KNetwork::KClientSocketBase QObject KNetwork::KActiveSocketBase QIODevice KNetwork::KSocketBase List of all members.

Signals

void bytesWritten (int bytes)

Public Member Functions

 KBufferedSocket (const QString &node=QString::null, const QString &service=QString::null, QObject *parent=0L, const char *name=0L)
virtual ~KBufferedSocket ()
virtual void setSocketDevice (KSocketDevice *device)
virtual void close ()
virtual Q_LONG bytesAvailable () const
virtual Q_LONG waitForMore (int msecs, bool *timeout=0L)
virtual Q_LONG readBlock (char *data, Q_ULONG maxlen)
virtual Q_LONG readBlock (char *data, Q_ULONG maxlen, KSocketAddress &from)
virtual Q_LONG peekBlock (char *data, Q_ULONG maxlen)
virtual Q_LONG peekBlock (char *data, Q_ULONG maxlen, KSocketAddress &from)
virtual Q_LONG writeBlock (const char *data, Q_ULONG len)
virtual Q_LONG writeBlock (const char *data, Q_ULONG len, const KSocketAddress &to)
virtual void enableRead (bool enable)
virtual void enableWrite (bool enable)
void setInputBuffering (bool enable)
KIOBufferBaseinputBuffer ()
void setOutputBuffering (bool enable)
KIOBufferBaseoutputBuffer ()
virtual Q_ULONG bytesToWrite () const
virtual void closeNow ()
bool canReadLine () const
QCString readLine ()
void reset ()

Protected Slots

virtual void slotReadActivity ()
virtual void slotWriteActivity ()

Protected Member Functions

virtual bool setSocketOptions (int opts)
virtual void stateChanging (SocketState newState)

Detailed Description

Buffered stream sockets.

This class allows the user to create and operate buffered stream sockets such as those used in most Internet connections. This class is also the one that resembles the most to the old QSocket implementation.

Objects of this type operate only in non-blocking mode. A call to setBlocking(true) will result in an error.

Author:
Thiago Macieira <thiago.macieira@kdemail.net>

Definition at line 52 of file kbufferedsocket.h.


Constructor & Destructor Documentation

KBufferedSocket::KBufferedSocket const QString node = QString::null,
const QString service = QString::null,
QObject parent = 0L,
const char *  name = 0L
 

Default constructor.

Parameters:
node destination host
service destination service to connect to
parent the parent object for this object
name the internal name for this object

Definition at line 50 of file kbufferedsocket.cpp.

References setInputBuffering(), and setOutputBuffering().

KBufferedSocket::~KBufferedSocket  )  [virtual]
 

Destructor.

Definition at line 59 of file kbufferedsocket.cpp.

References closeNow().


Member Function Documentation

void KBufferedSocket::setSocketDevice KSocketDevice device  )  [virtual]
 

Be sure to catch new devices.

Reimplemented from KNetwork::KSocketBase.

Definition at line 67 of file kbufferedsocket.cpp.

References KNetwork::KSocketBase::setBlocking(), and KNetwork::KSocketBase::setSocketDevice().

bool KBufferedSocket::setSocketOptions int  opts  )  [protected, virtual]
 

Buffered sockets can only operate in non-blocking mode.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 73 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::setSocketOptions().

void KBufferedSocket::close  )  [virtual]
 

Closes the socket for new data, but allow data that had been buffered for output with writeBlock to be still be written.

See also:
closeNow

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 82 of file kbufferedsocket.cpp.

References closeNow(), KNetwork::KSocketDevice::readNotifier(), QSocketNotifier::setEnabled(), KNetwork::KClientSocketBase::setState(), KNetwork::KSocketBase::socketDevice(), and KNetwork::KClientSocketBase::stateChanged().

Q_LONG KBufferedSocket::bytesAvailable  )  const [virtual]
 

Make use of the buffers.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 96 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::bytesAvailable().

Referenced by waitForMore().

Q_LONG KBufferedSocket::waitForMore int  msecs,
bool *  timeout = 0L
[virtual]
 

Make use of buffers.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 104 of file kbufferedsocket.cpp.

References bytesAvailable(), KNetwork::KActiveSocketBase::resetError(), slotReadActivity(), and KNetwork::KClientSocketBase::waitForMore().

Q_LONG KBufferedSocket::readBlock char *  data,
Q_ULONG  maxlen
[virtual]
 

Reads data from the socket.

Make use of buffers.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 116 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::gotError(), KNetwork::KClientSocketBase::readBlock(), KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError().

Referenced by readBlock().

Q_LONG KBufferedSocket::readBlock char *  data,
Q_ULONG  maxlen,
KSocketAddress from
[virtual]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Reads data from a socket.

The from parameter is always set to peerAddress()

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 132 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::peerAddress(), and readBlock().

Q_LONG KBufferedSocket::peekBlock char *  data,
Q_ULONG  maxlen
[virtual]
 

Peeks data from the socket.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 138 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::gotError(), KNetwork::KClientSocketBase::peekBlock(), KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError().

Referenced by peekBlock().

Q_LONG KBufferedSocket::peekBlock char *  data,
Q_ULONG  maxlen,
KSocketAddress from
[virtual]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Peeks data from the socket.

The from parameter is always set to peerAddress()

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 154 of file kbufferedsocket.cpp.

References peekBlock(), and KNetwork::KClientSocketBase::peerAddress().

Q_LONG KBufferedSocket::writeBlock const char *  data,
Q_ULONG  len
[virtual]
 

Writes data to the socket.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 160 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::gotError(), KNetwork::KActiveSocketBase::resetError(), QSocketNotifier::setEnabled(), KNetwork::KActiveSocketBase::setError(), KNetwork::KSocketBase::socketDevice(), KNetwork::KClientSocketBase::state(), KNetwork::KClientSocketBase::writeBlock(), and KNetwork::KSocketDevice::writeNotifier().

Referenced by writeBlock().

Q_LONG KBufferedSocket::writeBlock const char *  data,
Q_ULONG  len,
const KSocketAddress to
[virtual]
 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Writes data to the socket.

The to parameter is discarded.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 190 of file kbufferedsocket.cpp.

References writeBlock().

void KBufferedSocket::enableRead bool  enable  )  [virtual]
 

Catch changes.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 197 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::enableRead(), KNetwork::KSocketDevice::readNotifier(), QSocketNotifier::setEnabled(), QTimer::singleShot(), slotReadActivity(), KNetwork::KSocketBase::socketDevice(), and KNetwork::KClientSocketBase::state().

Referenced by stateChanging().

void KBufferedSocket::enableWrite bool  enable  )  [virtual]
 

Catch changes.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 214 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::enableWrite(), QSocketNotifier::setEnabled(), KNetwork::KSocketBase::socketDevice(), and KNetwork::KSocketDevice::writeNotifier().

Referenced by stateChanging().

void KBufferedSocket::setInputBuffering bool  enable  ) 
 

Sets the use of input buffering.

Definition at line 244 of file kbufferedsocket.cpp.

References KNetwork::KSocketBase::mutex().

Referenced by KBufferedSocket().

KIOBufferBase * KBufferedSocket::inputBuffer  ) 
 

Retrieves the input buffer object.

Definition at line 258 of file kbufferedsocket.cpp.

void KBufferedSocket::setOutputBuffering bool  enable  ) 
 

Sets the use of output buffering.

Definition at line 263 of file kbufferedsocket.cpp.

References KNetwork::KSocketBase::mutex().

Referenced by KBufferedSocket().

KIOBufferBase * KBufferedSocket::outputBuffer  ) 
 

Retrieves the output buffer object.

Definition at line 277 of file kbufferedsocket.cpp.

Q_ULONG KBufferedSocket::bytesToWrite  )  const [virtual]
 

Returns the length of the output buffer.

Definition at line 282 of file kbufferedsocket.cpp.

void KBufferedSocket::closeNow  )  [virtual]
 

Closes the socket and discards any output data that had been buffered with writeBlock but that had not yet been written.

See also:
close

Definition at line 290 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::close().

Referenced by close(), slotReadActivity(), slotWriteActivity(), and ~KBufferedSocket().

bool KBufferedSocket::canReadLine  )  const
 

Returns true if a line can be read with readLine.

Definition at line 295 of file kbufferedsocket.cpp.

QCString KBufferedSocket::readLine  ) 
 

Reads a line of data from the socket buffers.

Definition at line 303 of file kbufferedsocket.cpp.

void KBufferedSocket::stateChanging SocketState  newState  )  [protected, virtual]
 

Catch connection to clear the buffers.

Definition at line 226 of file kbufferedsocket.cpp.

References KNetwork::KClientSocketBase::emitsReadyRead(), KNetwork::KClientSocketBase::emitsReadyWrite(), enableRead(), enableWrite(), and KNetwork::KClientSocketBase::stateChanging().

void KBufferedSocket::slotReadActivity  )  [protected, virtual, slot]
 

Slot called when there's read activity.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 308 of file kbufferedsocket.cpp.

References closeNow(), KNetwork::KClientSocketBase::copyError(), KNetwork::KClientSocketBase::emitsReadyRead(), KNetwork::KSocketBase::error(), KNetwork::KClientSocketBase::gotError(), QMutex::lock(), KNetwork::KSocketBase::mutex(), KNetwork::KClientSocketBase::readyRead(), KNetwork::KActiveSocketBase::setError(), QTimer::singleShot(), KNetwork::KClientSocketBase::slotReadActivity(), KNetwork::KSocketBase::socketDevice(), KNetwork::KClientSocketBase::state(), and QMutex::unlock().

Referenced by enableRead(), and waitForMore().

void KBufferedSocket::slotWriteActivity  )  [protected, virtual, slot]
 

Slot called when there's write activity.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 355 of file kbufferedsocket.cpp.

References bytesWritten(), KNetwork::KClientSocketBase::close(), closeNow(), KNetwork::KClientSocketBase::copyError(), KNetwork::KSocketBase::error(), KNetwork::KClientSocketBase::gotError(), QMutex::lock(), KNetwork::KSocketBase::mutex(), QSocketNotifier::setEnabled(), KNetwork::KActiveSocketBase::setError(), KNetwork::KClientSocketBase::slotWriteActivity(), KNetwork::KSocketBase::socketDevice(), KNetwork::KClientSocketBase::state(), QMutex::unlock(), and KNetwork::KSocketDevice::writeNotifier().

void KNetwork::KBufferedSocket::bytesWritten int  bytes  )  [signal]
 

This signal is emitted whenever data is written.

Referenced by slotWriteActivity().

void KNetwork::KBufferedSocket::reset  )  [inline]
 

Deprecated:
Closes the socket.

This function is provided to ease porting from KExtendedSocket, which required a call to reset() in order to be able to connect again using the same device. This is not necessary in KBufferedSocket any more.

Reimplemented from QIODevice.

Definition at line 233 of file kbufferedsocket.h.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdecore Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 8 06:22:18 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003