KNetwork::KSocketBase Class Reference
#include <ksocketbase.h>
Inheritance diagram for KNetwork::KSocketBase:

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 97 of file ksocketbase.h.
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, RemotelyDisconnected } |
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 | |
static QString | errorString (SocketError code) |
static bool | isFatalError (int code) |
Protected Member Functions | |
virtual bool | setSocketOptions (int opts) |
virtual int | socketOptions () const |
bool | hasDevice () const |
void | setError (SocketError error) |
Friends | |
class | KSocketDevice |
Member Enumeration Documentation
|
Possible socket error codes. This is a list of possible error conditions that socket classes may be expected to find.
Definition at line 152 of file ksocketbase.h. |
|
Possible socket options. These are the options that may be set on a socket:
Definition at line 118 of file ksocketbase.h. |
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
|
Retrieves this socket's address reuseability flag.
Definition at line 91 of file ksocketbase.cpp. |
|
Retrieves this socket's blocking mode.
Definition at line 81 of file ksocketbase.cpp. |
|
Retrieves this socket's Broadcast flag.
Definition at line 111 of file ksocketbase.cpp. |
|
Retrieves the socket error code.
Definition at line 160 of file ksocketbase.cpp. |
|
Returns the string describing the given error code, i18n'ed.
Definition at line 166 of file ksocketbase.cpp. |
|
Returns the error string corresponding to this error condition.
Definition at line 383 of file ksocketbase.h. |
|
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. |
|
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.
Definition at line 259 of file ksocketbase.cpp. |
|
Retrieves this socket's IPv6 Only flag.
Definition at line 101 of file ksocketbase.cpp. |
|
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 278 of file ksocketbase.cpp. |
|
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.
Definition at line 86 of file ksocketbase.cpp. |
|
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.
Definition at line 76 of file ksocketbase.cpp. |
|
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.
Definition at line 106 of file ksocketbase.cpp. |
|
Sets the socket's error code.
Definition at line 155 of file ksocketbase.cpp. |
|
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.
Definition at line 96 of file ksocketbase.cpp. |
|
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.
Definition at line 143 of file ksocketbase.cpp. |
|
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. Definition at line 136 of file ksocketbase.cpp. |
|
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.
Definition at line 65 of file ksocketbase.cpp. |
|
Retrieves the socket implementation used on this socket. This function creates the device if none has been set using the default factory. Definition at line 116 of file ksocketbase.cpp. |
|
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.
Definition at line 71 of file ksocketbase.cpp. |
The documentation for this class was generated from the following files: