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

KDECore

  • kdecore
  • network
k3socketbase.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/*
26 * Even before our #ifdef, clean up the namespace
27 */
28#ifdef socket
29#undef socket
30#endif
31
32#ifdef bind
33#undef bind
34#endif
35
36#ifdef listen
37#undef listen
38#endif
39
40#ifdef connect
41#undef connect
42#endif
43
44#ifdef accept
45#undef accept
46#endif
47
48#ifdef getpeername
49#undef getpeername
50#endif
51
52#ifdef getsockname
53#undef getsockname
54#endif
55
56#ifndef KSOCKETBASE_H
57#define KSOCKETBASE_H
58
59#include <QtCore/QIODevice>
60#include <QtCore/QString>
61
62#include <kdecore_export.h>
63#include "k3socketaddress.h"
64
65class QMutex;
66
67namespace KNetwork {
68
69class KResolverEntry;
70class KSocketDevice;
71
72class KSocketBasePrivate;
85class KDECORE_EXPORT_DEPRECATED KSocketBase
86{
87public:
108 enum SocketOptions
109 {
110 Blocking = 0x01,
111 AddressReuseable = 0x02,
112 IPv6Only = 0x04,
113 Keepalive = 0x08,
114 Broadcast = 0x10,
115 NoDelay = 0x20
116 };
117
143 enum SocketError
144 {
145 NoError = 0,
146 LookupFailure,
147 AddressInUse,
148 AlreadyCreated,
149 AlreadyBound,
150 AlreadyConnected,
151 NotConnected,
152 NotBound,
153 NotCreated,
154 WouldBlock,
155 ConnectionRefused,
156 ConnectionTimedOut,
157 InProgress,
158 NetFailure,
159 NotSupported,
160 Timeout,
161 UnknownError,
162 RemotelyDisconnected
163 };
164
165public:
169 KSocketBase();
170
174 virtual ~KSocketBase();
175
176 /*
177 * The following functions are shared by all descended classes and will have
178 * to be reimplemented.
179 */
180
181protected:
195 virtual bool setSocketOptions(int opts);
196
206 virtual int socketOptions() const;
207
208public:
224 virtual bool setBlocking(bool enable);
225
232 bool blocking() const;
233
248 virtual bool setAddressReuseable(bool enable);
249
256 bool addressReuseable() const;
257
273 virtual bool setIPv6Only(bool enable);
274
281 bool isIPv6Only() const;
282
294 virtual bool setBroadcast(bool enable);
295
302 bool broadcast() const;
303
317 virtual bool setNoDelay(bool enable);
318
324 bool noDelay() const;
325
332 KSocketDevice* socketDevice() const;
333
347 virtual void setSocketDevice(KSocketDevice* device);
348
370 int setRequestedCapabilities(int add, int remove = 0);
371
372protected:
377 bool hasDevice() const;
378
384 void setError(SocketError error);
385
389 void resetError();
390
391public:
396 SocketError error() const;
397
401 QString errorString() const;
402
418 QMutex* mutex() const;
419
420public:
426 static QString errorString(SocketError code);
427
436 static bool isFatalError(int code);
437
438private:
441 void unsetSocketDevice();
442
443 KSocketBase(const KSocketBase&);
444 KSocketBase& operator =(const KSocketBase&);
445
446 KSocketBasePrivate* const d;
447
448 friend class KSocketDevice;
449};
450
461class KDECORE_EXPORT_DEPRECATED KActiveSocketBase: public QIODevice, virtual public KSocketBase
462{
463 Q_OBJECT
464public:
468 KActiveSocketBase(QObject* parent);
469
473 virtual ~KActiveSocketBase();
474
478 QString errorString() const;
479
483 virtual void setSocketDevice(KSocketDevice* device);
484
488 virtual bool open(OpenMode mode);
489
500 virtual bool bind(const KResolverEntry& address) = 0;
501
520 virtual bool connect(const KResolverEntry& address,
521 OpenMode mode = ReadWrite) = 0;
522
538 virtual bool disconnect() = 0;
539
543 virtual bool isSequential() const;
544
549 virtual qint64 size() const;
550
555 virtual qint64 pos() const;
556
561 virtual bool seek(qint64);
562
567 virtual bool atEnd() const;
568
575 qint64 read(char *data, qint64 maxlen);
576
583 QByteArray read(qint64 len);
584
596 qint64 read(char *data, qint64 maxlen, KSocketAddress& from);
597
609 qint64 peek(char *data, qint64 maxlen);
610
624 qint64 peek(char *data, qint64 maxlen, KSocketAddress& from);
625
632 qint64 write(const char *data, qint64 len);
633
640 qint64 write(const QByteArray& data);
641
653 qint64 write(const char *data, qint64 len, const KSocketAddress& to);
654
666 virtual qint64 waitForMore(int msecs, bool *timeout = 0L) = 0;
667
671 void ungetChar(char);
672
676 virtual KSocketAddress localAddress() const = 0;
677
683 virtual KSocketAddress peerAddress() const = 0;
684
685 // FIXME KDE 4.0:
686 // enable this function
687#if 0
691 virtual KSocketAddress externalAddress() const = 0;
692#endif
693
694protected:
701 virtual qint64 readData(char *data, qint64 len);
702
714 virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress* from) = 0;
715
728 virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress* from) = 0;
729
736 virtual qint64 writeData(const char *data, qint64 len);
737
749 virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress* to) = 0;
750
756 void setError(SocketError error);
757
761 void resetError();
762};
763
774class KDECORE_EXPORT_DEPRECATED KPassiveSocketBase: virtual public KSocketBase
775{
776public:
780 KPassiveSocketBase();
781
785 virtual ~KPassiveSocketBase();
786
797 virtual bool bind(const KResolverEntry& address) = 0;
798
813 virtual bool listen(int backlog) = 0;
814
819 virtual void close() = 0;
820
834 virtual KActiveSocketBase* accept() = 0;
835
839 virtual KSocketAddress localAddress() const = 0;
840
844 virtual KSocketAddress externalAddress() const = 0;
845
846private:
847 KPassiveSocketBase(const KPassiveSocketBase&);
848 KPassiveSocketBase& operator = (const KPassiveSocketBase&);
849};
850
851} // namespace KNetwork
852
853#endif
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: k3socketbase.h:462
KNetwork::KActiveSocketBase::disconnect
virtual bool disconnect()=0
Disconnects this socket from a connection, if possible.
KNetwork::KActiveSocketBase::connect
virtual bool connect(const KResolverEntry &address, OpenMode mode=ReadWrite)=0
Connect to a remote host.
KNetwork::KActiveSocketBase::readData
virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress *from)=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
KNetwork::KActiveSocketBase::localAddress
virtual KSocketAddress localAddress() const =0
Returns this socket's local address.
KNetwork::KActiveSocketBase::writeData
virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress *to)=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
KNetwork::KActiveSocketBase::peerAddress
virtual KSocketAddress peerAddress() const =0
Return this socket's peer address, if we are connected.
KNetwork::KActiveSocketBase::bind
virtual bool bind(const KResolverEntry &address)=0
Binds this socket to the given address.
KNetwork::KActiveSocketBase::peekData
virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from)=0
Peeks the data in the socket and the source address.
KNetwork::KActiveSocketBase::waitForMore
virtual qint64 waitForMore(int msecs, bool *timeout=0L)=0
Waits up to msecs for more data to be available on this socket.
KNetwork::KPassiveSocketBase
Abstract base class for passive sockets.
Definition: k3socketbase.h:775
KNetwork::KPassiveSocketBase::listen
virtual bool listen(int backlog)=0
Puts this socket into listening mode.
KNetwork::KPassiveSocketBase::localAddress
virtual KSocketAddress localAddress() const =0
Returns this socket's local address.
KNetwork::KPassiveSocketBase::externalAddress
virtual KSocketAddress externalAddress() const =0
Returns this socket's externally-visible address if known.
KNetwork::KPassiveSocketBase::close
virtual void close()=0
Closes this socket.
KNetwork::KPassiveSocketBase::bind
virtual bool bind(const KResolverEntry &address)=0
Binds this socket to the given address.
KNetwork::KPassiveSocketBase::accept
virtual KActiveSocketBase * accept()=0
Accepts a new incoming connection.
KNetwork::KResolverEntry
One resolution entry.
Definition: k3resolver.h:69
KNetwork::KSocketAddress
A generic socket address.
Definition: k3socketaddress.h:415
KNetwork::KSocketBase
Basic socket functionality.
Definition: k3socketbase.h:86
KNetwork::KSocketBase::SocketOptions
SocketOptions
Possible socket options.
Definition: k3socketbase.h:109
KNetwork::KSocketBase::SocketError
SocketError
Possible socket error codes.
Definition: k3socketbase.h:144
KNetwork::KSocketBase::NotSupported
@ NotSupported
Definition: k3socketbase.h:159
KNetwork::KSocketBase::AlreadyCreated
@ AlreadyCreated
Definition: k3socketbase.h:148
KNetwork::KSocketBase::InProgress
@ InProgress
Definition: k3socketbase.h:157
KNetwork::KSocketBase::NotCreated
@ NotCreated
Definition: k3socketbase.h:153
KNetwork::KSocketBase::NotBound
@ NotBound
Definition: k3socketbase.h:152
KNetwork::KSocketBase::UnknownError
@ UnknownError
Definition: k3socketbase.h:161
KNetwork::KSocketBase::ConnectionRefused
@ ConnectionRefused
Definition: k3socketbase.h:155
KNetwork::KSocketBase::AddressInUse
@ AddressInUse
Definition: k3socketbase.h:147
KNetwork::KSocketBase::LookupFailure
@ LookupFailure
Definition: k3socketbase.h:146
KNetwork::KSocketBase::NetFailure
@ NetFailure
Definition: k3socketbase.h:158
KNetwork::KSocketBase::ConnectionTimedOut
@ ConnectionTimedOut
Definition: k3socketbase.h:156
KNetwork::KSocketBase::Timeout
@ Timeout
Definition: k3socketbase.h:160
KNetwork::KSocketBase::NotConnected
@ NotConnected
Definition: k3socketbase.h:151
KNetwork::KSocketBase::WouldBlock
@ WouldBlock
Definition: k3socketbase.h:154
KNetwork::KSocketBase::AlreadyBound
@ AlreadyBound
Definition: k3socketbase.h:149
KNetwork::KSocketBase::AlreadyConnected
@ AlreadyConnected
Definition: k3socketbase.h:150
KNetwork::KSocketDevice
Low-level socket functionality.
Definition: k3socketdevice.h:52
QIODevice
QObject
QString
qint64
k3socketaddress.h
kdecore_export.h
timeout
int timeout
Definition: kkernel_mac.cpp:46
setError
static void setError(QAbstractSocket *socket, QAbstractSocket::SocketError error, const QString &errorString)
Definition: ksocketfactory.cpp:44
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-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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
  • Modules
  • 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