#include <kclientsocketbase.h>
Public Types | |
enum | SocketState { Idle , HostLookup , HostFound , Bound , Connecting , Open , Closing , Unconnected = Bound , Connected = Open , Connection = Open } |
Public Types inherited from KNetwork::TDESocketBase | |
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 } |
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 (TQObject *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 TQString &node=TQString::null, const TQString &service=TQString::null)=0 |
virtual bool | bind (const KResolverEntry &address) |
virtual bool | connect (const TQString &node=TQString::null, const TQString &service=TQString::null)=0 |
virtual bool | connect (const KResolverEntry &address) |
void | connectToHost (const TQString &host, TQ_UINT16 port) |
virtual bool | disconnect () |
virtual bool | open (int) |
virtual void | close () |
virtual void | flush () |
virtual TQ_LONG | bytesAvailable () const |
virtual TQ_LONG | waitForMore (int msecs, bool *timeout=0L) |
virtual TQ_LONG | readBlock (char *data, TQ_ULONG maxlen) |
virtual TQ_LONG | readBlock (char *data, TQ_ULONG maxlen, TDESocketAddress &from) |
virtual TQ_LONG | peekBlock (char *data, TQ_ULONG maxlen) |
virtual TQ_LONG | peekBlock (char *data, TQ_ULONG maxlen, TDESocketAddress &from) |
virtual TQ_LONG | writeBlock (const char *data, TQ_ULONG len) |
virtual TQ_LONG | writeBlock (const char *data, TQ_ULONG len, const TDESocketAddress &to) |
virtual TDESocketAddress | localAddress () const |
virtual TDESocketAddress | peerAddress () const |
bool | emitsReadyRead () const |
virtual void | enableRead (bool enable) |
bool | emitsReadyWrite () const |
virtual void | enableWrite (bool enable) |
Public Member Functions inherited from KNetwork::KActiveSocketBase | |
KActiveSocketBase () | |
virtual | ~KActiveSocketBase () |
virtual Offset | size () const |
virtual Offset | at () const |
virtual bool | at (Offset) |
virtual bool | atEnd () const |
virtual int | getch () |
virtual int | putch (int ch) |
virtual int | ungetch (int) |
Public Member Functions inherited from KNetwork::TDESocketBase | |
TDESocketBase () | |
virtual | ~TDESocketBase () |
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 |
TDESocketDevice * | socketDevice () const |
virtual void | setSocketDevice (TDESocketDevice *device) |
int | setRequestedCapabilities (int add, int remove=0) |
SocketError | error () const |
TQString | errorString () const |
TQMutex * | mutex () const |
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 () |
Protected Member Functions inherited from KNetwork::KActiveSocketBase | |
void | setError (int status, SocketError error) |
void | resetError () |
Protected Member Functions inherited from KNetwork::TDESocketBase | |
virtual int | socketOptions () const |
bool | hasDevice () const |
void | setError (SocketError error) |
Additional Inherited Members | |
Static Public Member Functions inherited from KNetwork::TDESocketBase | |
static TQString | errorString (SocketError code) |
static bool | isFatalError (int code) |
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 TDEBufferedSocket
Definition at line 49 of file kclientsocketbase.h.
Member Enumeration Documentation
◆ SocketState
Socket states.
These are the possible states for a KClientSocketBase:
- Idle: socket is not connected
- HostLookup: socket is doing host lookup prior to connecting
- HostFound: name lookup is complete
- Bound: the socket is locally bound
- Connecting: socket is attempting connection
- Open: socket is open
- Connected (=Open): socket is connected
- Connection (=Open): yet another name for a connected socket
- Closing: socket is shutting down
Whenever the socket state changes, the stateChanged(int) signal will be emitted.
Definition at line 72 of file kclientsocketbase.h.
Constructor & Destructor Documentation
◆ KClientSocketBase()
KClientSocketBase::KClientSocketBase | ( | TQObject * | parent, |
const char * | name | ||
) |
Default constructor.
- Parameters
-
parent the parent TQObject object name the name of this object
Definition at line 50 of file kclientsocketbase.cpp.
◆ ~KClientSocketBase()
|
virtual |
Destructor.
Definition at line 58 of file kclientsocketbase.cpp.
Member Function Documentation
◆ aboutToConnect
|
signal |
This signal is emitted when the socket is about to connect to an address (but before doing so).
The skip
parameter can be used to make the loop skip this address. Its value is initially false: change it to true if you want to skip the current address (as given by remote
).
This function is also useful if one wants to reset the timeout.
- Parameters
-
remote the address we're about to connect to skip set to true if you want to skip this address
- Note
- if the connection is successful, the connected signal will be emitted.
◆ bind() [1/2]
|
virtual |
Reimplemented from TDESocketBase.
Connect this socket to this specific address.
Unlike bind(const TQString&, const TQString&) above, this function really does bind the socket. No lookup is performed. The bound signal will be emitted.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::KStreamSocket, and KNetwork::KDatagramSocket.
Definition at line 189 of file kclientsocketbase.cpp.
◆ bind() [2/2]
|
pure virtual |
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.
- Note
- Due to the internals of the name lookup and binding mechanism, some (if not most) implementations of this function do not actually bind the socket until the connection is requested (see connect). They only set the values for future reference.
This function returns true on success.
- Parameters
-
node the nodename service the service
Implemented in KNetwork::KStreamSocket, and KNetwork::KDatagramSocket.
◆ bound
|
signal |
This signal is emitted when the socket successfully binds to an address.
- Parameters
-
local the local address we bound to
◆ bytesAvailable()
|
virtual |
Returns the number of bytes available on this socket.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 281 of file kclientsocketbase.cpp.
◆ close()
|
virtual |
Closes the socket.
Reimplemented from TQIODevice.
The closing of the socket causes the emission of the signal closed.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 261 of file kclientsocketbase.cpp.
◆ closed
|
signal |
This signal is emitted when the socket completes the closing/shut down process.
◆ connect() [1/2]
|
virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::KStreamSocket, and KNetwork::KDatagramSocket.
Definition at line 210 of file kclientsocketbase.cpp.
◆ connect() [2/2]
|
pure virtual |
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.
- Note for derived classes:
- Derived classes must implement this function. The implementation will set the parameters for the lookup (using the peer KResolver object) and call lookup to start it.
- The implementation should use the hostFound signal to be notified of the completion of the lookup process and then proceed to start the connection itself. Care should be taken regarding the value of blocking flag.
- Parameters
-
node the nodename service the service
Implemented in KNetwork::KStreamSocket, and KNetwork::KDatagramSocket.
◆ connected
|
signal |
This socket is emitted when the socket successfully connects to a remote address.
- Parameters
-
remote the remote address we did connect to
◆ connectToHost()
|
inline |
- Deprecated:
- This is a convenience function provided to ease migrating from Qt 3.x's TQSocket class.
Definition at line 261 of file kclientsocketbase.h.
◆ copyError()
|
protected |
Convenience function to set this object's error code to match that of the socket device.
Definition at line 472 of file kclientsocketbase.cpp.
◆ disconnect()
|
virtual |
Disconnects the socket.
Note that not all socket types can disconnect.
Implements KNetwork::KActiveSocketBase.
Definition at line 244 of file kclientsocketbase.cpp.
◆ emitsReadyRead()
bool KClientSocketBase::emitsReadyRead | ( | ) | const |
Returns true if the readyRead signal is set to be emitted.
Definition at line 383 of file kclientsocketbase.cpp.
◆ emitsReadyWrite()
bool KClientSocketBase::emitsReadyWrite | ( | ) | const |
Returns true if the readyWrite signal is set to be emitted.
Definition at line 398 of file kclientsocketbase.cpp.
◆ enableRead()
|
virtual |
Enables the emission of the readyRead signal.
By default, this signal is enabled.
- Parameters
-
enable whether to enable the signal
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 388 of file kclientsocketbase.cpp.
◆ enableWrite()
|
virtual |
Enables the emission of the readyWrite signal.
By default, this signal is disabled.
- Parameters
-
enable whether to enable the signal
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 403 of file kclientsocketbase.cpp.
◆ flush()
|
inlinevirtual |
This call is not supported on sockets.
Reimplemented from TQIODevice.
Definition at line 289 of file kclientsocketbase.h.
◆ gotError
|
signal |
This signal is emitted when this object finds an error.
The code
parameter contains the error code that can also be found by calling error.
◆ hostFound
|
signal |
This signal is emitted when the lookup is successfully completed.
◆ localAddress()
|
virtual |
Returns the local socket address.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Definition at line 373 of file kclientsocketbase.cpp.
◆ localResolver()
KResolver & KClientSocketBase::localResolver | ( | ) | const |
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.
◆ localResults()
const KResolverResults & KClientSocketBase::localResults | ( | ) | const |
Returns the internal list of resolved results for the local address.
Definition at line 106 of file kclientsocketbase.cpp.
◆ lookup()
|
virtual |
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 TDESocketBase::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.
◆ open()
|
inlinevirtual |
Opens the socket.
Reimplemented from TQIODevice.
You should not call this function; instead, use connect
Definition at line 275 of file kclientsocketbase.h.
◆ peekBlock() [1/2]
|
virtual |
Peeks data from the socket.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 325 of file kclientsocketbase.cpp.
◆ peekBlock() [2/2]
|
virtual |
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 TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 337 of file kclientsocketbase.cpp.
◆ peerAddress()
|
virtual |
Returns the peer socket address.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Definition at line 378 of file kclientsocketbase.cpp.
◆ peerResolver()
KResolver & KClientSocketBase::peerResolver | ( | ) | const |
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.
◆ peerResults()
const KResolverResults & KClientSocketBase::peerResults | ( | ) | const |
Returns the internal list of resolved results for the peer address.
Definition at line 96 of file kclientsocketbase.cpp.
◆ readBlock() [1/2]
|
virtual |
Reads data from a socket.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 301 of file kclientsocketbase.cpp.
◆ readBlock() [2/2]
|
virtual |
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 TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 313 of file kclientsocketbase.cpp.
◆ readyRead
|
signal |
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.
◆ readyWrite
|
signal |
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.
◆ setFamily()
void KClientSocketBase::setFamily | ( | int | families | ) |
Sets the allowed families for the resolutions.
- Parameters
-
families the families that we want/accept
- See also
- KResolver::SocketFamilies for possible values
Definition at line 125 of file kclientsocketbase.cpp.
◆ setResolutionEnabled()
void KClientSocketBase::setResolutionEnabled | ( | bool | enable | ) |
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 TDESocketAddress.
- Parameters
-
enable whether to enable
Definition at line 111 of file kclientsocketbase.cpp.
◆ setSocketOptions()
|
protectedvirtual |
Sets the socket options.
Reimplemented from TDESocketBase.
Reimplemented from KNetwork::TDESocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 75 of file kclientsocketbase.cpp.
◆ setState()
|
protected |
Sets the socket state to state
.
This function does not emit the stateChanged signal.
Definition at line 69 of file kclientsocketbase.cpp.
◆ slotReadActivity
|
protectedvirtualslot |
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.
Definition at line 413 of file kclientsocketbase.cpp.
◆ slotWriteActivity
|
protectedvirtualslot |
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).
Definition at line 419 of file kclientsocketbase.cpp.
◆ state()
KClientSocketBase::SocketState KClientSocketBase::state | ( | ) | const |
Returns the current state for this socket.
- See also
- SocketState
Definition at line 64 of file kclientsocketbase.cpp.
◆ stateChanged
|
signal |
This signal is emitted whenever the socket state changes.
Note: do not delete this object inside the slot called by this signal.
- Parameters
-
newstate the new state of the socket object
◆ stateChanging()
|
protectedvirtual |
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:
- Connected: it sets up the socket notifiers to fire readyRead and readyWrite signals.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 448 of file kclientsocketbase.cpp.
◆ waitForMore()
|
virtual |
Waits for more data.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 289 of file kclientsocketbase.cpp.
◆ writeBlock() [1/2]
|
virtual |
Writes data to the socket.
Reimplemented from TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::TDEBufferedSocket.
Definition at line 349 of file kclientsocketbase.cpp.
◆ writeBlock() [2/2]
|
virtual |
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 TDESocketBase.
Implements KNetwork::KActiveSocketBase.
Reimplemented in KNetwork::KDatagramSocket, and KNetwork::TDEBufferedSocket.
Definition at line 361 of file kclientsocketbase.cpp.
The documentation for this class was generated from the following files: