.TH "KNetwork::KSocketBase" kde3 "11 Jun 2005" "Version Version 3.4.1" "kdecore Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KNetwork::KSocketBase \- Basic socket functionality.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <ksocketbase.h>\fP
.PP
Inherited by \fBKNetwork::KActiveSocketBase\fP\fC [virtual]\fP, and \fBKNetwork::KPassiveSocketBase\fP\fC [virtual]\fP.
.PP
.SS "Public Types"

.in +1c
.ti -1c
.RI "enum \fBSocketOptions\fP { \fBBlocking\fP =  0x01, \fBAddressReuseable\fP =  0x02, \fBIPv6Only\fP =  0x04, \fBKeepalive\fP =  0x08, \fBBroadcast\fP =  0x10 }"
.br
.ti -1c
.RI "enum \fBSocketError\fP { \fBNoError\fP =  0, \fBLookupFailure\fP, \fBAddressInUse\fP, \fBAlreadyCreated\fP, \fBAlreadyBound\fP, \fBAlreadyConnected\fP, \fBNotConnected\fP, \fBNotBound\fP, \fBNotCreated\fP, \fBWouldBlock\fP, \fBConnectionRefused\fP, \fBConnectionTimedOut\fP, \fBInProgress\fP, \fBNetFailure\fP, \fBNotSupported\fP, \fBTimeout\fP, \fBUnknownError\fP, \fBRemotelyDisconnected\fP }"
.br
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKSocketBase\fP ()"
.br
.ti -1c
.RI "virtual \fB~KSocketBase\fP ()"
.br
.ti -1c
.RI "virtual bool \fBsetBlocking\fP (bool enable)"
.br
.ti -1c
.RI "bool \fBblocking\fP () const "
.br
.ti -1c
.RI "virtual bool \fBsetAddressReuseable\fP (bool enable)"
.br
.ti -1c
.RI "bool \fBaddressReuseable\fP () const "
.br
.ti -1c
.RI "virtual bool \fBsetIPv6Only\fP (bool enable)"
.br
.ti -1c
.RI "bool \fBisIPv6Only\fP () const "
.br
.ti -1c
.RI "virtual bool \fBsetBroadcast\fP (bool enable)"
.br
.ti -1c
.RI "bool \fBbroadcast\fP () const "
.br
.ti -1c
.RI "\fBKSocketDevice\fP * \fBsocketDevice\fP () const "
.br
.ti -1c
.RI "virtual void \fBsetSocketDevice\fP (\fBKSocketDevice\fP *device)"
.br
.ti -1c
.RI "int \fBsetRequestedCapabilities\fP (int add, int remove=0)"
.br
.ti -1c
.RI "\fBSocketError\fP \fBerror\fP () const "
.br
.ti -1c
.RI "\fBQString\fP \fBerrorString\fP () const "
.br
.ti -1c
.RI "\fBQMutex\fP * \fBmutex\fP () const "
.br
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "static \fBQString\fP \fBerrorString\fP (\fBSocketError\fP code)"
.br
.ti -1c
.RI "static bool \fBisFatalError\fP (int code)"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "virtual bool \fBsetSocketOptions\fP (int opts)"
.br
.ti -1c
.RI "virtual int \fBsocketOptions\fP () const "
.br
.ti -1c
.RI "bool \fBhasDevice\fP () const "
.br
.ti -1c
.RI "void \fBsetError\fP (\fBSocketError\fP error)"
.br
.in -1c
.SS "Friends"

.in +1c
.ti -1c
.RI "class \fBKSocketDevice\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
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.
.PP
\fBNote:\fP
.RS 4
This class is abstract.
.RE
.PP
\fBAuthor:\fP
.RS 4
Thiago Macieira <thiago.macieira@kdemail.net> 
.RE
.PP

.PP
Definition at line 97 of file ksocketbase.h.
.SH "Member Enumeration Documentation"
.PP 
.SS "enum \fBKNetwork::KSocketBase::SocketOptions\fP"
.PP
Possible socket options. 
.PP
These are the options that may be set on a socket:
.IP "\(bu" 2
Blocking: whether the socket shall operate in blocking or non-blocking mode. This flag defaults to on. See \fBsetBlocking\fP.
.IP "\(bu" 2
AddressReusable: whether the address used by this socket will be available for reuse by other sockets. This flag defaults to off. See \fBsetAddressReuseable\fP.
.IP "\(bu" 2
IPv6Only: whether an IPv6 socket will accept IPv4 connections through a mapped address. This flag defaults to off. See \fBsetIPv6Only\fP.
.IP "\(bu" 2
KeepAlive: whether TCP should send keepalive probes when a connection has gone idle for far too long.
.IP "\(bu" 2
Broadcast: whether this socket is allowed to send broadcast packets and will receive packets sent to broadcast. 
.PP

.PP
Definition at line 118 of file ksocketbase.h.
.SS "enum \fBKNetwork::KSocketBase::SocketError\fP"
.PP
Possible socket error codes. 
.PP
This is a list of possible error conditions that socket classes may be expected to find.
.PP
.IP "\(bu" 2
NoError: no error has been detected
.IP "\(bu" 2
LookupFailure: if a name lookup has failed
.IP "\(bu" 2
AddressInUse: address is already in use
.IP "\(bu" 2
AlreadyBound: cannot bind again
.IP "\(bu" 2
AlreadyCreated: cannot recreate the socket
.IP "\(bu" 2
NotBound: operation required socket to be bound and it isn't
.IP "\(bu" 2
NotCreated: operation required socket to exist and it doesn't
.IP "\(bu" 2
WouldBlock: requested I/O operation would block
.IP "\(bu" 2
ConnectionRefused: connection actively refused
.IP "\(bu" 2
ConnectionTimedOut: connection timed out
.IP "\(bu" 2
InProgress: operation (connection) is already in progress
.IP "\(bu" 2
NetFailure: a network failure occurred (no route, host down, host unreachable or similar)
.IP "\(bu" 2
NotSupported: requested operation is not supported
.IP "\(bu" 2
Timeout: a timed operation timed out
.IP "\(bu" 2
UnknownError: an unknown/unexpected error has happened
.IP "\(bu" 2
RemotelyDisconnected: when a connection is disconnected by the other end (since 3.4)
.PP
.PP
\fBSee also:\fP
.RS 4
\fBerror\fP, \fBerrorString\fP 
.RE
.PP

.PP
Definition at line 152 of file ksocketbase.h.
.SH "Constructor & Destructor Documentation"
.PP 
.SS "KSocketBase::KSocketBase ()"
.PP
Default constructor. 
.PP
Definition at line 50 of file ksocketbase.cpp.
.SS "KSocketBase::~\fBKSocketBase\fP ()\fC [virtual]\fP"
.PP
Destructor. 
.PP
Definition at line 59 of file ksocketbase.cpp.
.SH "Member Function Documentation"
.PP 
.SS "bool KSocketBase::setSocketOptions (int opts)\fC [protected, virtual]\fP"
.PP
Set the given socket options. 
.PP
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.
.PP
\fBParameters:\fP
.RS 4
\fIopts\fP a mask of \fBSocketOptions\fP or-ed bits of options to set or unset 
.RE
.PP
\fBReturns:\fP
.RS 4
true on success 
.RE
.PP
\fBNote:\fP
.RS 4
this function sets the options corresponding to the bits enabled in \fCopts\fP but will also unset the optiosn corresponding to the bits not set. 
.RE
.PP

.PP
Reimplemented in \fBKNetwork::KBufferedSocket\fP, \fBKNetwork::KClientSocketBase\fP, \fBKNetwork::KServerSocket\fP, and \fBKNetwork::KSocketDevice\fP.
.PP
Definition at line 65 of file ksocketbase.cpp.
.PP
Referenced by setAddressReuseable(), setBlocking(), setBroadcast(), and setIPv6Only().
.SS "int KSocketBase::socketOptions () const\fC [protected, virtual]\fP"
.PP
Retrieves the socket options that have been set. 
.PP
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.
.PP
\fBReturns:\fP
.RS 4
the mask of the options set 
.RE
.PP

.PP
Definition at line 71 of file ksocketbase.cpp.
.PP
Referenced by addressReuseable(), blocking(), broadcast(), KNetwork::KSocketDevice::create(), isIPv6Only(), KNetwork::KStreamSocket::KStreamSocket(), setAddressReuseable(), setBlocking(), setBroadcast(), and setIPv6Only().
.SS "bool KSocketBase::setBlocking (bool enable)\fC [virtual]\fP"
.PP
Sets this socket's blocking mode. 
.PP
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.
.PP
The default implementation toggles the Blocking flag with the current socket options and calls \fBsetSocketOptions\fP.
.PP
\fBParameters:\fP
.RS 4
\fIenable\fP whether to set this socket to blocking mode 
.RE
.PP
\fBReturns:\fP
.RS 4
whether setting this value was successful; it is NOT the final blocking mode. 
.RE
.PP

.PP
Definition at line 76 of file ksocketbase.cpp.
.PP
References setSocketOptions(), and socketOptions().
.PP
Referenced by KNetwork::KStreamSocket::connect(), and KNetwork::KSocksSocketDevice::connect().
.SS "bool KSocketBase::blocking () const"
.PP
Retrieves this socket's blocking mode. 
.PP
\fBReturns:\fP
.RS 4
true if this socket is/will be operated in blocking mode, false if non-blocking. 
.RE
.PP

.PP
Definition at line 81 of file ksocketbase.cpp.
.PP
References socketOptions().
.PP
Referenced by KNetwork::KServerSocket::accept(), KNetwork::KServerSocket::bind(), KNetwork::KStreamSocket::connect(), KNetwork::KSocksSocketDevice::connect(), KNetwork::KServerSocket::lookup(), KNetwork::KClientSocketBase::lookup(), and KNetwork::KDatagramSocket::receive().
.SS "bool KSocketBase::setAddressReuseable (bool enable)\fC [virtual]\fP"
.PP
Sets this socket's address reuseable flag. 
.PP
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.
.PP
The default implementation toggles the AddressReuseable flag with the current socket options and calls \fBsetSocketOptions\fP.
.PP
\fBParameters:\fP
.RS 4
\fIenable\fP whether to set the flag on or off 
.RE
.PP
\fBReturns:\fP
.RS 4
true if setting this flag was successful 
.RE
.PP

.PP
Definition at line 86 of file ksocketbase.cpp.
.PP
References setSocketOptions(), and socketOptions().
.SS "bool KSocketBase::addressReuseable () const"
.PP
Retrieves this socket's address reuseability flag. 
.PP
\fBReturns:\fP
.RS 4
true if this socket's address can be reused, false if it can't. 
.RE
.PP

.PP
Definition at line 91 of file ksocketbase.cpp.
.PP
References socketOptions().
.SS "bool KSocketBase::setIPv6Only (bool enable)\fC [virtual]\fP"
.PP
Sets this socket's IPv6 Only flag. 
.PP
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.
.PP
This option has no effect on non-IPv6 sockets.
.PP
The default implementation toggles the IPv6Only flag with the current socket options and calls \fBsetSocketOptions\fP.
.PP
\fBParameters:\fP
.RS 4
\fIenable\fP whether to set the flag on or off 
.RE
.PP
\fBReturns:\fP
.RS 4
true if setting this flag was successful 
.RE
.PP

.PP
Definition at line 96 of file ksocketbase.cpp.
.PP
References setSocketOptions(), and socketOptions().
.SS "bool KSocketBase::isIPv6Only () const"
.PP
Retrieves this socket's IPv6 Only flag. 
.PP
\fBReturns:\fP
.RS 4
true if this socket will ignore IPv4-compatible and IPv4-mapped addresses, false if it will accept them. 
.RE
.PP

.PP
Definition at line 101 of file ksocketbase.cpp.
.PP
References socketOptions().
.SS "bool KSocketBase::setBroadcast (bool enable)\fC [virtual]\fP"
.PP
Sets this socket Broadcast flag. 
.PP
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.
.PP
This option has no effect on stream-oriented sockets.
.PP
\fBReturns:\fP
.RS 4
true if setting this flag was successful. 
.RE
.PP

.PP
Definition at line 106 of file ksocketbase.cpp.
.PP
References setSocketOptions(), and socketOptions().
.SS "bool KSocketBase::broadcast () const"
.PP
Retrieves this socket's Broadcast flag. 
.PP
\fBReturns:\fP
.RS 4
true if this socket can send and receive broadcast packets, false if it can't. 
.RE
.PP

.PP
Definition at line 111 of file ksocketbase.cpp.
.PP
References socketOptions().
.SS "\fBKSocketDevice\fP * KSocketBase::socketDevice () const"
.PP
Retrieves the socket implementation used on this socket. 
.PP
This function creates the device if none has been set using the default factory. 
.PP
Definition at line 116 of file ksocketbase.cpp.
.PP
References mutex(), and setSocketDevice().
.PP
Referenced by KNetwork::KServerSocket::accept(), KNetwork::KServerSocket::bind(), KNetwork::KClientSocketBase::bind(), KNetwork::KClientSocketBase::bytesAvailable(), KNetwork::KServerSocket::close(), KNetwork::KClientSocketBase::close(), KNetwork::KBufferedSocket::close(), KNetwork::KStreamSocket::connect(), KNetwork::KClientSocketBase::connect(), KNetwork::KServerSocket::copyError(), KNetwork::KClientSocketBase::copyError(), KNetwork::KClientSocketBase::disconnect(), KNetwork::KClientSocketBase::enableRead(), KNetwork::KBufferedSocket::enableRead(), KNetwork::KClientSocketBase::enableWrite(), KNetwork::KBufferedSocket::enableWrite(), KNetwork::KServerSocket::externalAddress(), KNetwork::KServerSocket::localAddress(), KNetwork::KClientSocketBase::localAddress(), KNetwork::KClientSocketBase::peekBlock(), KNetwork::KClientSocketBase::peerAddress(), KNetwork::KClientSocketBase::readBlock(), KNetwork::KDatagramSocket::receive(), KNetwork::KServerSocket::setSocketOptions(), KNetwork::KClientSocketBase::setSocketOptions(), KNetwork::KBufferedSocket::slotReadActivity(), KNetwork::KBufferedSocket::slotWriteActivity(), KNetwork::KClientSocketBase::stateChanging(), KNetwork::KClientSocketBase::waitForMore(), KNetwork::KClientSocketBase::writeBlock(), and KNetwork::KBufferedSocket::writeBlock().
.SS "void KSocketBase::setSocketDevice (\fBKSocketDevice\fP * device)\fC [virtual]\fP"
.PP
Sets the socket implementation to be used on this socket. 
.PP
Note: it is an error to set this if the socket device has already been set once.
.PP
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.
.PP
This function is called by \fBsocketDevice\fP above when the socket is first created. 
.PP
Reimplemented in \fBKNetwork::KBufferedSocket\fP.
.PP
Definition at line 136 of file ksocketbase.cpp.
.PP
References mutex().
.PP
Referenced by KNetwork::KServerSocket::accept(), KNetwork::KSocketDevice::KSocketDevice(), and socketDevice().
.SS "int KSocketBase::setRequestedCapabilities (int add, int remove = \fC0\fP)"
.PP
Sets the internally requested capabilities for a socket device. 
.PP
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.
.PP
For the possible flags, see \fBKSocketDevice::Capabilities\fP. However, note that only the Can* flags make sense in this context.
.PP
\fBNote:\fP
.RS 4
Since socketDevice must always return a valid backend object, it is is possible that the created device does not conform to all requirements requested. Implementations sensitive to this fact should test the object returned by \fBsocketDevice\fP (through \fBKSocketDevice::capabilities\fP, for instance) the availability.
.RE
.PP
\fBParameters:\fP
.RS 4
\fIadd\fP mask of \fBKSocketDevice::Capabilities\fP to add 
.br
\fIremove\fP mask of bits to remove from the requirements 
.RE
.PP
\fBReturns:\fP
.RS 4
the current mask of requested capabilities 
.RE
.PP

.PP
Definition at line 143 of file ksocketbase.cpp.
.SS "bool KSocketBase::hasDevice () const\fC [protected]\fP"
.PP
Returns true if the socket device has been initialised in this object, either by calling \fBsocketDevice()\fP or \fBsetSocketDevice\fP. 
.PP
Definition at line 150 of file ksocketbase.cpp.
.PP
Referenced by KNetwork::KClientSocketBase::setSocketOptions().
.SS "void KSocketBase::setError (\fBSocketError\fP error)\fC [protected]\fP"
.PP
Sets the socket's error code. 
.PP
\fBParameters:\fP
.RS 4
\fIerror\fP the error code 
.RE
.PP

.PP
Definition at line 155 of file ksocketbase.cpp.
.PP
Referenced by KNetwork::KServerSocket::accept(), KNetwork::KServerSocket::bind(), KNetwork::KServerSocket::copyError(), and KNetwork::KServerSocket::lookup().
.SS "\fBKSocketBase::SocketError\fP KSocketBase::error () const"
.PP
Retrieves the socket error code. 
.PP
\fBSee also:\fP
.RS 4
\fBerrorString\fP 
.RE
.PP

.PP
Definition at line 160 of file ksocketbase.cpp.
.PP
Referenced by KNetwork::KStreamSocket::connect(), KNetwork::KClientSocketBase::connect(), KNetwork::KServerSocket::copyError(), KNetwork::KClientSocketBase::copyError(), KNetwork::KClientSocketBase::peekBlock(), KNetwork::KClientSocketBase::readBlock(), KNetwork::KBufferedSocket::slotReadActivity(), KNetwork::KBufferedSocket::slotWriteActivity(), KNetwork::KClientSocketBase::waitForMore(), and KNetwork::KClientSocketBase::writeBlock().
.SS "\fBQString\fP KNetwork::KSocketBase::errorString () const\fC [inline]\fP"
.PP
Returns the error string corresponding to this error condition. 
.PP
Definition at line 383 of file ksocketbase.h.
.SS "\fBQMutex\fP * KSocketBase::mutex () const"
.PP
Returns the internal mutex for this class. 
.PP
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.
.PP
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. 
.PP
Definition at line 278 of file ksocketbase.cpp.
.PP
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::KServerSocket::setSocketOptions(), KNetwork::KClientSocketBase::setSocketOptions(), KNetwork::KBufferedSocket::slotReadActivity(), KNetwork::KBufferedSocket::slotWriteActivity(), socketDevice(), and KNetwork::KSocketDevice::writeNotifier().
.SS "\fBQString\fP KSocketBase::errorString (\fBSocketError\fP code)\fC [static]\fP"
.PP
Returns the string describing the given error code, i18n'ed. 
.PP
\fBParameters:\fP
.RS 4
\fIcode\fP the error code 
.RE
.PP

.PP
Definition at line 166 of file ksocketbase.cpp.
.SS "bool KSocketBase::isFatalError (int code)\fC [static]\fP"
.PP
Returns true if the given error code is a fatal one, false otherwise. 
.PP
The parameter here is of type int so that casting isn't necessary when using the parameter to signal QClientSocketBase::gotError.
.PP
\fBParameters:\fP
.RS 4
\fIcode\fP the code to test 
.RE
.PP

.PP
Definition at line 259 of file ksocketbase.cpp.

.SH "Author"
.PP 
Generated automatically by Doxygen for kdecore Library from the source code.
