KNetwork::KClientSocketBase Class Reference
Abstract client socket class. More...
#include <kclientsocketbase.h>
Inheritance diagram for KNetwork::KClientSocketBase:

Public Types | |
enum | SocketState { Idle, HostLookup, HostFound, Bound, Connecting, Open, Closing, Unconnected = Bound, Connected = Open, Connection = Open } |
Signals | |
void | stateChanged (int newstate) |
void | gotError (int code) |
void | hostFound () |
void | bound (const KResolverEntry &local) |
void | aboutToConnect (const KResolverEntry &remote, bool &skip) |
void | connected (const KResolverEntry &remote) |
void | closed () |
void | readyRead () |
void | readyWrite () |
Public Member Functions | |
KClientSocketBase (QObject *parent, const char *name) | |
virtual | ~KClientSocketBase () |
SocketState | state () const |
KResolver & | peerResolver () const |
const KResolverResults & | peerResults () const |
KResolver & | localResolver () const |
const KResolverResults & | localResults () const |
void | setResolutionEnabled (bool enable) |
void | setFamily (int families) |
virtual bool | lookup () |
virtual bool | bind (const QString &node=QString::null, const QString &service=QString::null)=0 |
virtual bool | bind (const KResolverEntry &address) |
virtual bool | connect (const QString &node=QString::null, const QString &service=QString::null)=0 |
virtual bool | connect (const KResolverEntry &address) |
void | connectToHost (const QString &host, Q_UINT16 port) |
virtual bool | disconnect () |
virtual bool | open (int) |
virtual void | close () |
virtual void | flush () |
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 KSocketAddress | localAddress () const |
virtual KSocketAddress | peerAddress () const |
bool | emitsReadyRead () const |
virtual void | enableRead (bool enable) |
bool | emitsReadyWrite () const |
virtual void | enableWrite (bool enable) |
Protected Slots | |
virtual void | slotReadActivity () |
virtual void | slotWriteActivity () |
Protected Member Functions | |
virtual bool | setSocketOptions (int opts) |
void | setState (SocketState state) |
virtual void | stateChanging (SocketState newState) |
void | copyError () |
Detailed Description
Abstract client socket class.This class provides the base functionality for client sockets, such as, and especially, name resolution and signals.
- Note:
- This class is abstract. If you're looking for a normal, client socket class, see KStreamSocket and KBufferedSocket
- Author:
- Thiago Macieira <thiago.macieira@kdemail.net>
Definition at line 48 of file kclientsocketbase.h.
Member Enumeration Documentation
|
Socket states. These are the possible states for a KClientSocketBase:
Whenever the socket state changes, the stateChanged(int) signal will be emitted. Definition at line 70 of file kclientsocketbase.h. Referenced by connect(). |
Constructor & Destructor Documentation
|
Default constructor.
Definition at line 50 of file kclientsocketbase.cpp. |
|
Destructor.
Definition at line 58 of file kclientsocketbase.cpp. References close(). |
Member Function Documentation
|
Returns the current state for this socket.
Definition at line 64 of file kclientsocketbase.cpp. Referenced by KNetwork::KStreamSocket::bind(), KNetwork::KDatagramSocket::bind(), bind(), close(), KNetwork::KStreamSocket::connect(), KNetwork::KDatagramSocket::connect(), connect(), disconnect(), KNetwork::KBufferedSocket::enableRead(), lookup(), KNetwork::KStreamSocket::remainingTimeout(), KNetwork::KStreamSocket::setTimeout(), KNetwork::KBufferedSocket::slotReadActivity(), KNetwork::KBufferedSocket::slotWriteActivity(), and KNetwork::KBufferedSocket::writeBlock(). |
|
Sets the socket options. Reimplemented from KSocketBase. Reimplemented from KNetwork::KSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 75 of file kclientsocketbase.cpp. References copyError(), KNetwork::KSocketBase::hasDevice(), KNetwork::KSocketBase::mutex(), KNetwork::KSocketDevice::setSocketOptions(), and KNetwork::KSocketBase::socketDevice(). Referenced by KNetwork::KStreamSocket::KStreamSocket(). |
|
Returns the internal KResolver object used for looking up the peer host name and service. This can be used to set extra options to the lookup process other than the default values, as well as obtaining the error codes in case of lookup failure. Definition at line 91 of file kclientsocketbase.cpp. Referenced by KNetwork::KStreamSocket::connect(), KNetwork::KDatagramSocket::connect(), KNetwork::KDatagramSocket::KDatagramSocket(), KNetwork::KStreamSocket::KStreamSocket(), and lookup(). |
|
Returns the internal list of resolved results for the peer address.
Definition at line 96 of file kclientsocketbase.cpp. |
|
Returns the internal KResolver object used for looking up the local host name and service. This can be used to set extra options to the lookup process other than the default values, as well as obtaining the error codes in case of lookup failure. Definition at line 101 of file kclientsocketbase.cpp. Referenced by KNetwork::KStreamSocket::bind(), KNetwork::KDatagramSocket::bind(), KNetwork::KDatagramSocket::KDatagramSocket(), KNetwork::KStreamSocket::KStreamSocket(), and lookup(). |
|
Returns the internal list of resolved results for the local address.
Definition at line 106 of file kclientsocketbase.cpp. |
|
Enables or disables name resolution. If this flag is set to true, bind and connect operations will trigger name lookup operations (i.e., converting a hostname into its binary form). If the flag is set to false, those operations will instead try to convert a string representation of an address without attempting name resolution. This is useful, for instance, when IP addresses are in their string representation (such as "1.2.3.4") or come from other sources like KSocketAddress.
Definition at line 111 of file kclientsocketbase.cpp. |
|
Sets the allowed families for the resolutions.
Definition at line 125 of file kclientsocketbase.cpp. |
|
Starts the lookup for peer and local hostnames as well as their services. If the blocking mode for this object is on, this function will wait for the lookup results to be available (by calling the KResolver::wait method on the resolver objects). When the lookup is done, the signal hostFound will be emitted (only once, even if we're doing a double lookup). If the lookup failed (for any of the two lookups) the gotError signal will be emitted with the appropriate error condition (see KSocketBase::SocketError). This function returns true on success and false on error. Note that this is not the lookup result! Definition at line 131 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::blocking(), localResolver(), peerResolver(), setState(), state(), stateChanged(), and KNetwork::KResolver::wait(). Referenced by KNetwork::KDatagramSocket::bind(), KNetwork::KStreamSocket::connect(), and KNetwork::KDatagramSocket::connect(). |
|
Binds this socket to the given nodename and service, or use the default ones if none are given. Upon successful binding, the bound signal will be emitted. If an error is found, the gotError signal will be emitted.
Implemented in KNetwork::KDatagramSocket, and KNetwork::KStreamSocket. |
|
Reimplemented from KSocketBase. Connect this socket to this specific address. Unlike bind(const QString&, const QString&) above, this function really does bind the socket. No lookup is performed. The bound signal will be emitted. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KDatagramSocket, and KNetwork::KStreamSocket. Definition at line 189 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::bind(), bound(), KNetwork::KActiveSocketBase::resetError(), setState(), KNetwork::KSocketBase::socketDevice(), state(), and stateChanged(). |
|
Attempts to connect to the these hostname and service, or use the default ones if none are given. If a connection attempt is already in progress, check on its state and set the error status (NoError or InProgress). If the blocking mode for this object is on, this function will only return when all the resolved peer addresses have been tried or when a connection is established. Upon successfully connecting, the connected signal will be emitted. If an error is found, the gotError signal will be emitted.
Implemented in KNetwork::KDatagramSocket, and KNetwork::KStreamSocket. |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KDatagramSocket, and KNetwork::KStreamSocket. Definition at line 210 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::connect(), connected(), copyError(), KNetwork::KSocketBase::error(), setState(), KNetwork::KSocketBase::socketDevice(), SocketState, state(), and stateChanged(). |
|
Definition at line 259 of file kclientsocketbase.h. |
|
Disconnects the socket. Note that not all socket types can disconnect. Implements KNetwork::KActiveSocketBase. Definition at line 244 of file kclientsocketbase.cpp. References copyError(), KNetwork::KSocketDevice::disconnect(), setState(), KNetwork::KSocketBase::socketDevice(), state(), and stateChanged(). |
|
Opens the socket. Reimplemented from QIODevice. You should not call this function; instead, use connect Definition at line 273 of file kclientsocketbase.h. |
|
Closes the socket. Reimplemented from QIODevice. The closing of the socket causes the emission of the signal closed. Reimplemented in KNetwork::KBufferedSocket. Definition at line 261 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::close(), closed(), setState(), KNetwork::KSocketBase::socketDevice(), state(), and stateChanged(). Referenced by ~KClientSocketBase(). |
|
This call is not supported on sockets. Reimplemented from QIODevice. Definition at line 287 of file kclientsocketbase.h. |
|
Returns the number of bytes available on this socket. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 280 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::bytesAvailable(), and KNetwork::KSocketBase::socketDevice(). Referenced by KNetwork::KDatagramSocket::receive(). |
|
Waits for more data. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 285 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::socketDevice(), and KNetwork::KSocketDevice::waitForMore(). |
|
Reads data from a socket. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 290 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::readBlock(), and KNetwork::KSocketBase::socketDevice(). Referenced by KNetwork::KDatagramSocket::receive(). |
|
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. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 295 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::readBlock(), and KNetwork::KSocketBase::socketDevice(). |
|
Peeks data from the socket. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 300 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::peekBlock(), and KNetwork::KSocketBase::socketDevice(). |
|
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. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 305 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::peekBlock(), and KNetwork::KSocketBase::socketDevice(). |
|
Writes data to the socket. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 310 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::socketDevice(), and KNetwork::KSocketDevice::writeBlock(). Referenced by KNetwork::KDatagramSocket::send(). |
|
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. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KBufferedSocket. Definition at line 315 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::socketDevice(), and KNetwork::KSocketDevice::writeBlock(). |
|
Returns the local socket address. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Definition at line 320 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::localAddress(), and KNetwork::KSocketBase::socketDevice(). |
|
Returns the peer socket address. Reimplemented from KSocketBase. Implements KNetwork::KActiveSocketBase. Definition at line 325 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::peerAddress(), and KNetwork::KSocketBase::socketDevice(). Referenced by KNetwork::KBufferedSocket::peekBlock(), and KNetwork::KBufferedSocket::readBlock(). |
|
Returns true if the readyRead signal is set to be emitted.
Definition at line 330 of file kclientsocketbase.cpp. Referenced by KNetwork::KBufferedSocket::slotReadActivity(), and KNetwork::KBufferedSocket::stateChanging(). |
|
Enables the emission of the readyRead signal. By default, this signal is enabled.
Reimplemented in KNetwork::KBufferedSocket. Definition at line 335 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::mutex(), KNetwork::KSocketDevice::readNotifier(), and KNetwork::KSocketBase::socketDevice(). |
|
Returns true if the readyWrite signal is set to be emitted.
Definition at line 345 of file kclientsocketbase.cpp. Referenced by KNetwork::KBufferedSocket::stateChanging(). |
|
Enables the emission of the readyWrite signal. By default, this signal is disabled.
Reimplemented in KNetwork::KBufferedSocket. Definition at line 350 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::mutex(), KNetwork::KSocketBase::socketDevice(), and KNetwork::KSocketDevice::writeNotifier(). |
|
This slot is connected to the read notifier's signal meaning the socket can read more data. The default implementation only emits the readyRead signal. Override if your class requires processing of incoming data. Reimplemented in KNetwork::KBufferedSocket. Definition at line 360 of file kclientsocketbase.cpp. References readyRead(). Referenced by stateChanging(). |
|
This slot is connected to the write notifier's signal meaning the socket can write more data. The default implementation only emits the readyWrite signal. Override if your class writes data from another source (like a buffer). Reimplemented in KNetwork::KBufferedSocket. Definition at line 366 of file kclientsocketbase.cpp. References readyWrite(). Referenced by stateChanging(). |
|
This signal is emitted whenever the socket state changes. Note: do not delete this object inside the slot called by this signal.
Referenced by bind(), close(), KNetwork::KBufferedSocket::close(), KNetwork::KDatagramSocket::connect(), connect(), disconnect(), and lookup(). |
|
This signal is emitted when this object finds an error.
The Referenced by KNetwork::KStreamSocket::connect(), KNetwork::KBufferedSocket::peekBlock(), KNetwork::KBufferedSocket::readBlock(), KNetwork::KDatagramSocket::receive(), and KNetwork::KBufferedSocket::writeBlock(). |
|
This signal is emitted when the lookup is successfully completed.
Referenced by KNetwork::KStreamSocket::connect(), and KNetwork::KDatagramSocket::KDatagramSocket(). |
|
This signal is emitted when the socket successfully binds to an address.
Referenced by bind(). |
|
This signal is emitted when the socket is about to connect to an address (but before doing so).
The This function is also useful if one wants to reset the timeout.
|
|
This socket is emitted when the socket successfully connects to a remote address.
Referenced by connect(). |
|
This signal is emitted when the socket completes the closing/shut down process.
Referenced by close(). |
|
This signal is emitted whenever the socket is ready for reading -- i.e., there is data to be read in the buffers. The subsequent read operation is guaranteed to be non-blocking. You can toggle the emission of this signal with the enableRead function. This signal is by default enabled. Referenced by slotReadActivity(), and KNetwork::KBufferedSocket::slotReadActivity(). |
|
This signal is emitted whenever the socket is ready for writing -- i.e., whenever there's space available in the buffers to receive more data. The subsequent write operation is guaranteed to be non-blocking. You can toggle the emission of this signal with the enableWrite function. This signal is by default disabled. You will want to disable this signal after the first reception, since it'll probably fire at every event loop. Referenced by slotWriteActivity(). |
|
Sets the socket state to This function does not emit the stateChanged signal. Definition at line 69 of file kclientsocketbase.cpp. References stateChanging(). Referenced by KNetwork::KServerSocket::accept(), bind(), close(), KNetwork::KBufferedSocket::close(), KNetwork::KDatagramSocket::connect(), connect(), disconnect(), and lookup(). |
|
This function is called by setState whenever the state changes. You should override it if you need to specify any actions to be done when the state changes. The default implementation acts for these states only:
Reimplemented in KNetwork::KBufferedSocket. Definition at line 395 of file kclientsocketbase.cpp. References KNetwork::KSocketDevice::readNotifier(), slotReadActivity(), slotWriteActivity(), KNetwork::KSocketBase::socketDevice(), and KNetwork::KSocketDevice::writeNotifier(). Referenced by setState(). |
|
Convenience function to set this object's error code to match that of the socket device.
Definition at line 419 of file kclientsocketbase.cpp. References KNetwork::KSocketBase::error(), KNetwork::KActiveSocketBase::setError(), and KNetwork::KSocketBase::socketDevice(). Referenced by connect(), disconnect(), setSocketOptions(), KNetwork::KBufferedSocket::slotReadActivity(), and KNetwork::KBufferedSocket::slotWriteActivity(). |
The documentation for this class was generated from the following files: