KNetwork::KSocketDevice Class Reference
Low-level socket functionality. More...
#include <ksocketdevice.h>
Inheritance diagram for KNetwork::KSocketDevice:

Public Types | |
enum | Capabilities { CanConnectString = 0x01, CanBindString = 0x02, CanNotBind = 0x04, CanNotListen = 0x08, CanMulticast = 0x10, CanNotUseDatagrams = 0x20 } |
Public Member Functions | |
KSocketDevice (const KSocketBase *=0L) | |
KSocketDevice (int fd) | |
virtual | ~KSocketDevice () |
int | socket () const |
virtual int | capabilities () const |
virtual bool | setSocketOptions (int opts) |
virtual bool | open (int mode) |
virtual void | close () |
virtual void | flush () |
virtual bool | create (int family, int type, int protocol) |
bool | create (const KResolverEntry &address) |
virtual bool | bind (const KResolverEntry &address) |
virtual bool | listen (int backlog=5) |
virtual bool | connect (const KResolverEntry &address) |
virtual KSocketDevice * | accept () |
virtual bool | disconnect () |
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 |
virtual KSocketAddress | externalAddress () const |
QSocketNotifier * | readNotifier () const |
QSocketNotifier * | writeNotifier () const |
QSocketNotifier * | exceptionNotifier () const |
virtual bool | poll (bool *input, bool *output, bool *exception=0L, int timeout=-1, bool *timedout=0L) |
bool | poll (int timeout=-1, bool *timedout=0L) |
Static Public Member Functions | |
static KSocketDevice * | createDefault (KSocketBase *parent) |
static KSocketDevice * | createDefault (KSocketBase *parent, int capabilities) |
static KSocketDeviceFactoryBase * | setDefaultImpl (KSocketDeviceFactoryBase *factory) |
static void | addNewImpl (KSocketDeviceFactoryBase *factory, int capabilities) |
Protected Member Functions | |
KSocketDevice (bool, const KSocketBase *parent=0L) | |
virtual QSocketNotifier * | createNotifier (QSocketNotifier::Type type) const |
Protected Attributes | |
int | m_sockfd |
Detailed Description
Low-level socket functionality.This class provides low-level socket functionality.
Most users will prefer "cooked" interfaces like those of KStreamSocket or KServerSocket.
Descended classes from this one provide some other kinds of socket functionality, like proxying or specific socket types.
- Author:
- Thiago Macieira <thiago.macieira@kdemail.net>
Definition at line 50 of file ksocketdevice.h.
Member Enumeration Documentation
|
Capabilities for the socket implementation. KSocketDevice-derived classes can implement certain capabilities that are not available in the default class. These capabilities are described by these flags. The default KSocketDevice class has none of these capabilities. For the negative capabilities (inabilities, the CanNot* forms), when a capability is not present, the implementation will default to the original behaviour.
Definition at line 63 of file ksocketdevice.h. |
Constructor & Destructor Documentation
|
Default constructor. The parameter is used to specify which socket this object is used as a device for. Definition at line 76 of file ksocketdevice.cpp. References KNetwork::KSocketBase::setSocketDevice(), setSocketOptions(), and KNetwork::KSocketBase::socketOptions(). Referenced by accept(), and createDefault(). |
|
Constructs a new object around an already-open socket. Note: you should write programs that create sockets through the classes whenever possible. Definition at line 84 of file ksocketdevice.cpp. References QIODevice::setFlags(), KNetwork::KSocketBase::setSocketDevice(), and QIODevice::setState(). |
|
Destructor. This closes the socket if it's open. Definition at line 100 of file ksocketdevice.cpp. References close(). |
|
Special constructor. This constructor will cause the internal socket device NOT to be set. Use this if your socket device class takes another underlying socket device.
Definition at line 92 of file ksocketdevice.cpp. References setSocketOptions(), and KNetwork::KSocketBase::socketOptions(). |
Member Function Documentation
|
Returns the file descriptor for this socket.
Definition at line 122 of file ksocketdevice.h. References m_sockfd. |
|
Returns the set of capabilities this socket class implements. The set of capabilities is defined as an OR-ed mask of Capabilities bits. The default implementation is guaranteed to always return 0. That is, derived implementations always return bits where they differ from the system standard sockets. Reimplemented in KNetwork::KHttpProxySocketDevice, KNetwork::KMulticastSocketImpl, and KNetwork::KSocksSocketDevice. Definition at line 134 of file ksocketdevice.h. |
|
This implementation sets the options on the socket.
Reimplemented from KNetwork::KSocketBase. Definition at line 107 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KSocketBase::mutex(), KNetwork::KActiveSocketBase::setError(), and KNetwork::KSocketBase::setSocketOptions(). Referenced by create(), KSocketDevice(), KNetwork::KServerSocket::setSocketOptions(), and KNetwork::KClientSocketBase::setSocketOptions(). |
|
Reimplementation from QIODevice. You should not call this function in sockets. Reimplemented from QIODevice. Definition at line 171 of file ksocketdevice.cpp. References KNetwork::KActiveSocketBase::resetError(). |
|
Closes the socket. Reimplemented from QIODevice. Use this function to close the socket this object is holding open. Implements KNetwork::KPassiveSocketBase. Reimplemented in KNetwork::KHttpProxySocketDevice. Definition at line 177 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), and QIODevice::setState(). Referenced by KNetwork::KServerSocket::close(), KNetwork::KHttpProxySocketDevice::close(), KNetwork::KClientSocketBase::close(), and ~KSocketDevice(). |
|
This call is not supported on sockets. Reimplemented from QIODevice. Reimplemented from QIODevice. Definition at line 157 of file ksocketdevice.h. |
|
Creates a socket but don't connect or bind anywhere. This function is the equivalent of the system call socket(2). Reimplemented in KNetwork::KMulticastSocketImpl. Definition at line 195 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), KNetwork::KActiveSocketBase::setError(), setSocketOptions(), and KNetwork::KSocketBase::socketOptions(). Referenced by KNetwork::KSocksSocketDevice::bind(), bind(), KNetwork::KSocksSocketDevice::connect(), connect(), and create(). |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Creates a socket but don't connect or bind anywhere.
Definition at line 220 of file ksocketdevice.cpp. References create(), KNetwork::KResolverEntry::family(), KNetwork::KResolverEntry::protocol(), and KNetwork::KResolverEntry::socketType(). |
|
Binds this socket to the given address.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 225 of file ksocketdevice.cpp. References KNetwork::KResolverEntry::address(), create(), KNetwork::KResolverEntry::length(), m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). |
|
Puts this socket into listening mode.
Implements KNetwork::KPassiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 248 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), KNetwork::KActiveSocketBase::setError(), QIODevice::setFlags(), and QIODevice::setState(). |
|
Connect to a remote host.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KHttpProxySocketDevice, KNetwork::KMulticastSocketImpl, and KNetwork::KSocksSocketDevice. Definition at line 270 of file ksocketdevice.cpp. References KNetwork::KResolverEntry::address(), create(), KNetwork::KResolverEntry::length(), m_sockfd, KNetwork::KActiveSocketBase::resetError(), KNetwork::KActiveSocketBase::setError(), QIODevice::setFlags(), and QIODevice::setState(). Referenced by KNetwork::KHttpProxySocketDevice::connect(), and KNetwork::KClientSocketBase::connect(). |
|
Accepts a new incoming connection. Note: this function returns a socket of type KSocketDevice. Implements KNetwork::KPassiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 304 of file ksocketdevice.cpp. References KSocketDevice(), m_sockfd, and KNetwork::KActiveSocketBase::setError(). Referenced by KNetwork::KServerSocket::accept(). |
|
Disconnects this socket.
Implements KNetwork::KActiveSocketBase. Definition at line 328 of file ksocketdevice.cpp. References KNetwork::KSocketAddress::address(), KNetwork::KSocketAddress::length(), m_sockfd, KNetwork::KActiveSocketBase::resetError(), KNetwork::KActiveSocketBase::setError(), KNetwork::KSocketAddress::setFamily(), QIODevice::setFlags(), and QIODevice::setState(). Referenced by KNetwork::KClientSocketBase::disconnect(). |
|
Returns the number of bytes available for reading without blocking.
Implements KNetwork::KActiveSocketBase. Definition at line 362 of file ksocketdevice.cpp. References m_sockfd. Referenced by KNetwork::KClientSocketBase::bytesAvailable(), and waitForMore(). |
|
Waits up to This function is a wrapper against poll. This function will wait for any read events. Implements KNetwork::KActiveSocketBase. Definition at line 374 of file ksocketdevice.cpp. References bytesAvailable(), m_sockfd, and poll(). Referenced by KNetwork::KDatagramSocket::receive(), and KNetwork::KClientSocketBase::waitForMore(). |
|
Reads data from this socket.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 412 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). Referenced by KNetwork::KClientSocketBase::readBlock(). |
|
Reads data and the source address from this socket.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 433 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). |
|
Peeks data in the socket.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 454 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). Referenced by KNetwork::KClientSocketBase::peekBlock(). |
|
Peeks the data in the socket and the source address.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 475 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). |
|
Writes data to the socket.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 496 of file ksocketdevice.cpp. Referenced by KNetwork::KClientSocketBase::writeBlock(). |
|
Writes the given data to the given destination address.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 501 of file ksocketdevice.cpp. References KNetwork::KSocketAddress::address(), KNetwork::KSocketAddress::length(), m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). |
|
Returns this socket's local address.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 525 of file ksocketdevice.cpp. References KNetwork::KSocketAddress::address(), KNetwork::KSocketAddress::length(), m_sockfd, and KNetwork::KSocketAddress::setLength(). Referenced by externalAddress(), KNetwork::KServerSocket::localAddress(), and KNetwork::KClientSocketBase::localAddress(). |
|
Returns this socket's peer address. If this implementation does proxying of some sort, this is the real external address, not the proxy's address. Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KHttpProxySocketDevice, and KNetwork::KSocksSocketDevice. Definition at line 554 of file ksocketdevice.cpp. References KNetwork::KSocketAddress::address(), KNetwork::KSocketAddress::length(), m_sockfd, and KNetwork::KSocketAddress::setLength(). Referenced by KNetwork::KClientSocketBase::peerAddress(). |
|
Returns this socket's externally visible local address. If this socket has a local address visible externally different from the normal local address (as returned by localAddress), then return it. Certain implementations will use proxies and thus have externally visible addresses different from the local socket values. The default implementation returns the same value as localAddress.
Implements KNetwork::KActiveSocketBase. Reimplemented in KNetwork::KHttpProxySocketDevice, and KNetwork::KSocksSocketDevice. Definition at line 583 of file ksocketdevice.cpp. References localAddress(). Referenced by KNetwork::KServerSocket::externalAddress(). |
|
Returns a socket notifier for input on this socket. The notifier is created only when requested. Whether it is enabled or not depends on the implementation. This function might return NULL. Definition at line 590 of file ksocketdevice.cpp. References createNotifier(), m_sockfd, and KNetwork::KSocketBase::mutex(). Referenced by KNetwork::KBufferedSocket::close(), KNetwork::KClientSocketBase::enableRead(), KNetwork::KBufferedSocket::enableRead(), and KNetwork::KClientSocketBase::stateChanging(). |
|
Returns a socket notifier for output on this socket. The is created only when requested. This function might return NULL. Definition at line 608 of file ksocketdevice.cpp. References createNotifier(), m_sockfd, and KNetwork::KSocketBase::mutex(). Referenced by KNetwork::KClientSocketBase::enableWrite(), KNetwork::KBufferedSocket::enableWrite(), KNetwork::KBufferedSocket::slotWriteActivity(), KNetwork::KClientSocketBase::stateChanging(), and KNetwork::KBufferedSocket::writeBlock(). |
|
Returns a socket notifier for exceptional events on this socket. The is created only when requested. This function might return NULL. Definition at line 626 of file ksocketdevice.cpp. References createNotifier(), m_sockfd, and KNetwork::KSocketBase::mutex(). |
|
Executes a poll in the socket, via select(2) or poll(2). The events polled are returned in the parameters pointers. Set any of them to NULL to disable polling of that event.
On exit,
Reimplemented in KNetwork::KSocksSocketDevice. Definition at line 644 of file ksocketdevice.cpp. References m_sockfd, KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). Referenced by KNetwork::KStreamSocket::connect(), poll(), and waitForMore(). |
|
Shorter version to poll for any events in a socket. This call polls for input, output and exceptional events in a socket but does not return their states. This is useful if you need to wait for any event, but don't need to know which; or for timeouts.
Definition at line 766 of file ksocketdevice.cpp. References poll(). |
|
Creates a socket notifier of the given type. This function is called by readNotifier, writeNotifier and exceptionNotifier when they need to create a socket notifier (i.e., the first call to those functions after the socket is open). After that call, those functions cache the socket notifier and will not need to call this function again. Reimplement this function in your derived class if your socket type requires a different kind of QSocketNotifier. The return value should be deleteable with delete. (close deletes them).
Definition at line 772 of file ksocketdevice.cpp. References m_sockfd. Referenced by exceptionNotifier(), readNotifier(), and writeNotifier(). |
|
Creates a new default KSocketDevice object given the parent object. The capabilities flag indicates the desired capabilities the object being created should possess. Those capabilities are not guaranteed: if no factory can provide such an object, a default object will be created.
Definition at line 820 of file ksocketdevice.cpp. References KNetwork::KSocketDeviceFactoryBase::create(), and KSocketDevice(). Referenced by 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. This will create an object only if the requested capabilities match.
Definition at line 835 of file ksocketdevice.cpp. References QMap::constBegin(), QMap::constEnd(), and QMap::ConstIterator(). |
|
Sets the default KSocketDevice implementation to use and return the old factory.
Definition at line 852 of file ksocketdevice.cpp. |
|
Adds a factory of KSocketDevice objects to the list, along with its capabilities flag.
Definition at line 860 of file ksocketdevice.cpp. References QMap::contains(), and QMap::insert(). |
Member Data Documentation
|
The socket file descriptor. It is used throughout the implementation and subclasses. Definition at line 95 of file ksocketdevice.h. Referenced by KNetwork::KSocksSocketDevice::accept(), accept(), KNetwork::KSocksSocketDevice::bind(), bind(), bytesAvailable(), close(), KNetwork::KSocksSocketDevice::connect(), connect(), KNetwork::KHttpProxySocketDevice::connect(), create(), createNotifier(), disconnect(), exceptionNotifier(), KNetwork::KSocksSocketDevice::listen(), listen(), KNetwork::KSocksSocketDevice::localAddress(), localAddress(), KNetwork::KSocksSocketDevice::peekBlock(), peekBlock(), KNetwork::KSocksSocketDevice::peerAddress(), peerAddress(), KNetwork::KSocksSocketDevice::poll(), poll(), KNetwork::KSocksSocketDevice::readBlock(), readBlock(), readNotifier(), setSocketOptions(), socket(), waitForMore(), KNetwork::KSocksSocketDevice::writeBlock(), writeBlock(), and writeNotifier(). |
The documentation for this class was generated from the following files: