• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • network
k3clientsocketbase.h
Go to the documentation of this file.
1/* -*- C++ -*-
2 * Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org>
3 *
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef KCLIENTSOCKETBASE_H
26#define KCLIENTSOCKETBASE_H
27
28#include <QtCore/QObject>
29#include <QtCore/QString>
30
31#include <kdecore_export.h>
32#include "k3socketbase.h"
33#include "k3resolver.h"
34
35namespace KNetwork {
36
37class KClientSocketBasePrivate;
50class KDECORE_EXPORT_DEPRECATED KClientSocketBase : public KActiveSocketBase
51{
52 Q_OBJECT
53
54public:
72 enum SocketState
73 {
74 Idle,
75 HostLookup,
76 HostFound,
77 Bound,
78 Connecting,
79 Open,
80 Closing,
81
82 Unconnected = Bound,
83 Connected = Open,
84 Connection = Open
85 };
86
87public:
93 KClientSocketBase(QObject* parent);
94
98 virtual ~KClientSocketBase();
99
104 SocketState state() const;
105
106protected:
110 virtual bool setSocketOptions(int opts);
111
112public:
121 KResolver& peerResolver() const;
122
126 const KResolverResults& peerResults() const;
127
136 KResolver& localResolver() const;
137
141 const KResolverResults& localResults() const;
142
157 void setResolutionEnabled(bool enable);
158
165 void setFamily(int families);
166
184 virtual bool lookup();
185
205 virtual bool bind(const QString& node = QString(),
206 const QString& service = QString()) = 0;
207
216 virtual bool bind(const KResolverEntry& address);
217
247 virtual bool connect(const QString& node = QString(),
248 const QString& service = QString(),
249 OpenMode mode = ReadWrite) = 0;
250
255 virtual bool connect(const KResolverEntry& address,
256 OpenMode mode = ReadWrite);
257
262 virtual bool disconnect();
263
269 virtual bool open(OpenMode mode);
270
277 virtual void close();
278
283 virtual bool flush();
284
289 virtual qint64 bytesAvailable() const;
290
294 virtual qint64 waitForMore(int msecs, bool *timeout = 0L);
295
299 virtual KSocketAddress localAddress() const;
300
304 virtual KSocketAddress peerAddress() const;
305
309 bool emitsReadyRead() const;
310
317 virtual void enableRead(bool enable);
318
322 bool emitsReadyWrite() const;
323
330 virtual void enableWrite(bool enable);
331
332protected Q_SLOTS:
333 // protected slots
334
344 virtual void slotReadActivity();
345
355 virtual void slotWriteActivity();
356
357private Q_SLOTS:
358 void lookupFinishedSlot();
359
360Q_SIGNALS:
369 void stateChanged(int newstate);
370
376 void gotError(int code);
377
381 void hostFound();
382
389 void bound(const KNetwork::KResolverEntry& local);
390
406 void aboutToConnect(const KNetwork::KResolverEntry& remote, bool& skip);
407
414 void connected(const KNetwork::KResolverEntry& remote);
415
420 void closed();
421
422#if 0
423 // QIODevice already has this
432 void readyRead();
433#endif
434
446 void readyWrite();
447
448protected:
452 virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress *from);
453
457 virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from);
458
463 virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress* to);
464
469 void setState(SocketState state);
470
480 virtual void stateChanging(SocketState newState);
481
486 void copyError();
487
488private:
489 KClientSocketBase(const KClientSocketBase&);
490 KClientSocketBase& operator=(const KClientSocketBase&);
491
492 KClientSocketBasePrivate* const d;
493};
494
495} // namespace KNetwork
496
497#endif
KNetwork::KActiveSocketBase::KActiveSocketBase
KActiveSocketBase(QObject *parent)
Constructor.
Definition k3socketbase.cpp:325
KNetwork::KClientSocketBase
Abstract client socket class.
Definition k3clientsocketbase.h:51
KNetwork::KClientSocketBase::readData
virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress *from)
Reads data from a socket.
Definition k3clientsocketbase.cpp:316
KNetwork::KClientSocketBase::waitForMore
virtual qint64 waitForMore(int msecs, bool *timeout=0L)
Waits for more data.
Definition k3clientsocketbase.cpp:304
KNetwork::KClientSocketBase::emitsReadyWrite
bool emitsReadyWrite() const
Returns true if the readyWrite signal is set to be emitted.
Definition k3clientsocketbase.cpp:379
KNetwork::KClientSocketBase::SocketState
SocketState
Socket states.
Definition k3clientsocketbase.h:73
KNetwork::KClientSocketBase::Connected
@ Connected
Definition k3clientsocketbase.h:83
KNetwork::KClientSocketBase::HostLookup
@ HostLookup
Definition k3clientsocketbase.h:75
KNetwork::KClientSocketBase::Unconnected
@ Unconnected
Definition k3clientsocketbase.h:82
KNetwork::KClientSocketBase::Open
@ Open
Definition k3clientsocketbase.h:79
KNetwork::KClientSocketBase::Bound
@ Bound
Definition k3clientsocketbase.h:77
KNetwork::KClientSocketBase::Connection
@ Connection
Definition k3clientsocketbase.h:84
KNetwork::KClientSocketBase::Connecting
@ Connecting
Definition k3clientsocketbase.h:78
KNetwork::KClientSocketBase::Idle
@ Idle
Definition k3clientsocketbase.h:74
KNetwork::KClientSocketBase::HostFound
@ HostFound
Definition k3clientsocketbase.h:76
KNetwork::KClientSocketBase::Closing
@ Closing
Definition k3clientsocketbase.h:80
KNetwork::KClientSocketBase::bind
virtual bool bind(const QString &node=QString(), const QString &service=QString())=0
Binds this socket to the given nodename and service, or use the default ones if none are given.
KNetwork::KClientSocketBase::stateChanging
virtual void stateChanging(SocketState newState)
This function is called by setState() whenever the state changes.
Definition k3clientsocketbase.cpp:429
KNetwork::KClientSocketBase::enableRead
virtual void enableRead(bool enable)
Enables the emission of the readyRead signal.
Definition k3clientsocketbase.cpp:369
KNetwork::KClientSocketBase::aboutToConnect
void aboutToConnect(const KNetwork::KResolverEntry &remote, bool &skip)
This signal is emitted when the socket is about to connect to an address (but before doing so).
KNetwork::KClientSocketBase::slotReadActivity
virtual void slotReadActivity()
This slot is connected to the read notifier's signal meaning the socket can read more data.
Definition k3clientsocketbase.cpp:394
KNetwork::KClientSocketBase::KClientSocketBase
KClientSocketBase(QObject *parent)
Default constructor.
Definition k3clientsocketbase.cpp:52
KNetwork::KClientSocketBase::connected
void connected(const KNetwork::KResolverEntry &remote)
This socket is emitted when the socket successfully connects to a remote address.
KNetwork::KClientSocketBase::enableWrite
virtual void enableWrite(bool enable)
Enables the emission of the readyWrite signal.
Definition k3clientsocketbase.cpp:384
KNetwork::KClientSocketBase::setState
void setState(SocketState state)
Sets the socket state to state.
Definition k3clientsocketbase.cpp:71
KNetwork::KClientSocketBase::disconnect
virtual bool disconnect()
Disconnects the socket.
Definition k3clientsocketbase.cpp:248
KNetwork::KClientSocketBase::open
virtual bool open(OpenMode mode)
Opens the socket.
Definition k3clientsocketbase.cpp:265
KNetwork::KClientSocketBase::close
virtual void close()
Closes the socket.
Definition k3clientsocketbase.cpp:270
KNetwork::KClientSocketBase::closed
void closed()
This signal is emitted when the socket completes the closing/shut down process.
KNetwork::KClientSocketBase::emitsReadyRead
bool emitsReadyRead() const
Returns true if the readyRead signal is set to be emitted.
Definition k3clientsocketbase.cpp:364
KNetwork::KClientSocketBase::state
SocketState state() const
Returns the current state for this socket.
Definition k3clientsocketbase.cpp:66
KNetwork::KClientSocketBase::bytesAvailable
virtual qint64 bytesAvailable() const
Returns the number of bytes available on this socket.
Definition k3clientsocketbase.cpp:296
KNetwork::KClientSocketBase::readyWrite
void readyWrite()
This signal is emitted whenever the socket is ready for writing – i.e., whenever there's space availa...
KNetwork::KClientSocketBase::writeData
virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress *to)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition k3clientsocketbase.cpp:340
KNetwork::KClientSocketBase::peerAddress
virtual KSocketAddress peerAddress() const
Returns the peer socket address.
Definition k3clientsocketbase.cpp:359
KNetwork::KClientSocketBase::gotError
void gotError(int code)
This signal is emitted when this object finds an error.
KNetwork::KClientSocketBase::peekData
virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from)
Peeks data from the socket.
Definition k3clientsocketbase.cpp:328
KNetwork::KClientSocketBase::copyError
void copyError()
Convenience function to set this object's error code to match that of the socket device.
Definition k3clientsocketbase.cpp:453
KNetwork::KClientSocketBase::hostFound
void hostFound()
This signal is emitted when the lookup is successfully completed.
KNetwork::KClientSocketBase::bound
void bound(const KNetwork::KResolverEntry &local)
This signal is emitted when the socket successfully binds to an address.
KNetwork::KClientSocketBase::slotWriteActivity
virtual void slotWriteActivity()
This slot is connected to the write notifier's signal meaning the socket can write more data.
Definition k3clientsocketbase.cpp:400
KNetwork::KClientSocketBase::localAddress
virtual KSocketAddress localAddress() const
Returns the local socket address.
Definition k3clientsocketbase.cpp:354
KNetwork::KClientSocketBase::stateChanged
void stateChanged(int newstate)
This signal is emitted whenever the socket state changes.
KNetwork::KClientSocketBase::connect
virtual bool connect(const QString &node=QString(), const QString &service=QString(), OpenMode mode=ReadWrite)=0
Attempts to connect to a given hostname and service, or use the default ones if none are given.
KNetwork::KClientSocketBase::flush
virtual bool flush()
This call is not supported on unbuffered sockets.
Definition k3clientsocketbase.cpp:290
KNetwork::KResolverEntry
One resolution entry.
Definition k3resolver.h:69
KNetwork::KResolverResults
Name and service resolution results.
Definition k3resolver.h:213
KNetwork::KResolver
Name and service resolution class.
Definition k3resolver.h:313
KNetwork::KSocketAddress
A generic socket address.
Definition k3socketaddress.h:415
QObject
QString
qint64
k3resolver.h
k3socketbase.h
lookup
static QByteArray lookup(const KConfigIniBackend::BufferFragment &fragment, QHash< KConfigIniBackend::BufferFragment, QByteArray > *cache)
Definition kconfigini.cpp:43
kdecore_export.h
timeout
int timeout
Definition kkernel_mac.cpp:46
KNetwork
A namespace to store all networking-related (socket) classes.
Definition k3bufferedsocket.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Tue Mar 25 2025 00:00:00 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal