KNetwork::KSocketBase Class Reference
Basic socket functionality. More...
#include <ksocketbase.h>
Inheritance diagram for KNetwork::KSocketBase:

Public Types | |
enum | SocketOptions { Blocking = 0x01, AddressReuseable = 0x02, IPv6Only = 0x04, Keepalive = 0x08, Broadcast = 0x10 } |
enum | SocketError { NoError = 0, LookupFailure, AddressInUse, AlreadyCreated, AlreadyBound, AlreadyConnected, NotConnected, NotBound, NotCreated, WouldBlock, ConnectionRefused, ConnectionTimedOut, InProgress, NetFailure, NotSupported, Timeout, UnknownError } |
Public Member Functions | |
KSocketBase () | |
virtual | ~KSocketBase () |
virtual bool | setBlocking (bool enable) |
bool | blocking () const |
virtual bool | setAddressReuseable (bool enable) |
bool | addressReuseable () const |
virtual bool | setIPv6Only (bool enable) |
bool | isIPv6Only () const |
virtual bool | setBroadcast (bool enable) |
bool | broadcast () const |
KSocketDevice * | socketDevice () const |
virtual void | setSocketDevice (KSocketDevice *device) |
int | setRequestedCapabilities (int add, int remove=0) |
SocketError | error () const |
QString | errorString () const |
QMutex * | mutex () const |
Static Public Member Functions | |
QString | errorString (SocketError code) |
bool | isFatalError (int code) |
Protected Member Functions | |
virtual bool | setSocketOptions (int opts) |
virtual int | socketOptions () const |
bool | hasDevice () const |
void | setError (SocketError error) |
Detailed Description
Basic socket functionality.This class provides the basic socket functionlity for descended classes. Socket classes are thread-safe and provide a recursive mutex should it be needed.
- Note:
- This class is abstract.
- Author:
- Thiago Macieira <thiago.macieira@kdemail.net>
Definition at line 96 of file ksocketbase.h.
Member Enumeration Documentation
|
Possible socket options. These are the options that may be set on a socket:
|
|
Possible socket error codes. This is a list of possible error conditions that socket classes may be expected to find.
|
Constructor & Destructor Documentation
|
Default constructor. Definition at line 50 of file ksocketbase.cpp. |
|
Destructor. Definition at line 59 of file ksocketbase.cpp. |
Member Function Documentation
|
Set the given socket options. The default implementation does nothing but store the mask internally. Descended classes must override this function to achieve functionality and must also call this implementation.
Reimplemented in KNetwork::KBufferedSocket, KNetwork::KClientSocketBase, KNetwork::KServerSocket, and KNetwork::KSocketDevice. Definition at line 65 of file ksocketbase.cpp. Referenced by setAddressReuseable(), setBlocking(), setBroadcast(), setIPv6Only(), KNetwork::KSocketDevice::setSocketOptions(), and KNetwork::KClientSocketBase::setSocketOptions(). |
|
Retrieves the socket options that have been set. The default implementation just retrieves the mask from an internal variable. Descended classes may choose to override this function to read the values from the operating system.
Referenced by addressReuseable(), blocking(), broadcast(), KNetwork::KSocketDevice::create(), isIPv6Only(), KNetwork::KSocketDevice::KSocketDevice(), setAddressReuseable(), setBlocking(), setBroadcast(), and setIPv6Only(). |
|
Sets this socket's blocking mode. In blocking operation, all I/O functions are susceptible to blocking -- i.e., will not return unless the I/O can be satisfied. In non-blocking operation, if the I/O would block, the function will return an error and set the corresponding error code. The default implementation toggles the Blocking flag with the current socket options and calls setSocketOptions.
References setSocketOptions(), and socketOptions(). Referenced by KNetwork::KStreamSocket::connect(), KNetwork::KBufferedSocket::KBufferedSocket(), KNetwork::KStreamSocket::KStreamSocket(), and KNetwork::KBufferedSocket::setSocketDevice(). |
|
Retrieves this socket's blocking mode.
References socketOptions(). Referenced by KNetwork::KStreamSocket::connect(), KNetwork::KClientSocketBase::lookup(), and KNetwork::KDatagramSocket::receive(). |
|
Sets this socket's address reuseable flag. When the address reuseable flag is active, the address used by this socket is left reuseable for other sockets to bind. If the flag is not active, no other sockets may reuse the same address. The default implementation toggles the AddressReuseable flag with the current socket options and calls setSocketOptions.
References setSocketOptions(), and socketOptions(). |
|
Retrieves this socket's address reuseability flag.
References socketOptions(). |
|
Sets this socket's IPv6 Only flag. When this flag is on, an IPv6 socket will only accept, connect, send to or receive from IPv6 addresses. When it is off, it will also talk to IPv4 addresses through v4-mapped addresses. This option has no effect on non-IPv6 sockets. The default implementation toggles the IPv6Only flag with the current socket options and calls setSocketOptions.
References setSocketOptions(), and socketOptions(). |
|
Retrieves this socket's IPv6 Only flag.
References socketOptions(). |
|
Sets this socket Broadcast flag. Datagram-oriented sockets cannot normally send packets to broadcast addresses, nor will they receive packets that were sent to a broadcast address. To do so, you need to enable the Broadcast flag. This option has no effect on stream-oriented sockets.
References setSocketOptions(), and socketOptions(). |
|
Retrieves this socket's Broadcast flag.
References socketOptions(). |
|
|
Sets the socket implementation to be used on this socket. Note: it is an error to set this if the socket device has already been set once. This function is provided virtual so that derived classes can catch the setting of a device and properly set their own states and internal variables. The parent class must be called. This function is called by socketDevice above when the socket is first created. Reimplemented in KNetwork::KBufferedSocket. Definition at line 136 of file ksocketbase.cpp. References mutex(). Referenced by KNetwork::KSocketDevice::KSocketDevice(), KNetwork::KBufferedSocket::setSocketDevice(), and socketDevice(). |
|
Sets the internally requested capabilities for a socket device. Most socket classes can use any back-end implementation. However, a few may require specific capabilities not provided in the default implementation. By using this function, derived classes can request that a backend with those capabilities be created when necessary. For the possible flags, see KSocketDevice::Capabilities. However, note that only the Can* flags make sense in this context.
|
|
Returns true if the socket device has been initialised in this object, either by calling socketDevice() or setSocketDevice. Definition at line 150 of file ksocketbase.cpp. Referenced by KNetwork::KClientSocketBase::setSocketOptions(). |
|
Sets the socket's error code.
Referenced by KNetwork::KActiveSocketBase::resetError(), and KNetwork::KActiveSocketBase::setError(). |
|
Retrieves the socket error code.
Referenced by KNetwork::KStreamSocket::connect(), KNetwork::KClientSocketBase::connect(), KNetwork::KClientSocketBase::copyError(), errorString(), KNetwork::KBufferedSocket::slotReadActivity(), and KNetwork::KBufferedSocket::slotWriteActivity(). |
|
Returns the error string corresponding to this error condition. Definition at line 380 of file ksocketbase.h. References error(). |
|
Returns the internal mutex for this class. Note on multithreaded use of sockets: the socket classes are thread-safe by design, but you should be aware of problems regarding socket creation, connection and destruction in multi-threaded programs. The classes are guaranteed to work while the socket exists, but it's not wise to call connect in multiple threads. Also, this mutex must be unlocked before the object is destroyed, which means you cannot use it to guard against other threads accessing the object while destroying it. You must ensure there are no further references to this object when deleting it. Definition at line 271 of file ksocketbase.cpp. Referenced by KNetwork::KClientSocketBase::enableRead(), KNetwork::KClientSocketBase::enableWrite(), KNetwork::KSocketDevice::exceptionNotifier(), KNetwork::KSocketDevice::readNotifier(), KNetwork::KBufferedSocket::setInputBuffering(), KNetwork::KBufferedSocket::setOutputBuffering(), setSocketDevice(), KNetwork::KSocketDevice::setSocketOptions(), KNetwork::KClientSocketBase::setSocketOptions(), KNetwork::KBufferedSocket::slotReadActivity(), KNetwork::KBufferedSocket::slotWriteActivity(), socketDevice(), and KNetwork::KSocketDevice::writeNotifier(). |
|
Returns the string describing the given error code, i18n'ed.
|
|
Returns true if the given error code is a fatal one, false otherwise. The parameter here is of type int so that casting isn't necessary when using the parameter to signal QClientSocketBase::gotError.
|
The documentation for this class was generated from the following files: