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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • 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 
65 class QMutex;
66 
67 namespace KNetwork {
68 
69 class KResolverEntry;
70 class KSocketDevice;
71 
72 class KSocketBasePrivate;
85 class KDECORE_EXPORT_DEPRECATED KSocketBase
86 {
87 public:
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 
165 public:
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 
181 protected:
195  virtual bool setSocketOptions(int opts);
196 
206  virtual int socketOptions() const;
207 
208 public:
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 
372 protected:
377  bool hasDevice() const;
378 
384  void setError(SocketError error);
385 
389  void resetError();
390 
391 public:
396  SocketError error() const;
397 
401  QString errorString() const;
402 
418  QMutex* mutex() const;
419 
420 public:
426  static QString errorString(SocketError code);
427 
436  static bool isFatalError(int code);
437 
438 private:
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 
461 class KDECORE_EXPORT_DEPRECATED KActiveSocketBase: public QIODevice, virtual public KSocketBase
462 {
463  Q_OBJECT
464 public:
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
688 
691  virtual KSocketAddress externalAddress() const = 0;
692 #endif
693 
694 protected:
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 
774 class KDECORE_EXPORT_DEPRECATED KPassiveSocketBase: virtual public KSocketBase
775 {
776 public:
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 
846 private:
847  KPassiveSocketBase(const KPassiveSocketBase&);
848  KPassiveSocketBase& operator = (const KPassiveSocketBase&);
849 };
850 
851 } // namespace KNetwork
852 
853 #endif
QIODevice
k3socketaddress.h
KNetwork::KSocketBase::AddressInUse
Definition: k3socketbase.h:147
KNetwork::KSocketBase::AlreadyConnected
Definition: k3socketbase.h:150
QMutex
qint64
KNetwork::KSocketBase::AlreadyCreated
Definition: k3socketbase.h:148
kdecore_export.h
QByteArray
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: k3socketbase.h:461
KNetwork::KSocketBase::NotCreated
Definition: k3socketbase.h:153
timeout
int timeout
Definition: kkernel_mac.cpp:46
KNetwork::KResolverEntry
One resolution entry.
Definition: k3resolver.h:68
KNetwork::KSocketBase::NotBound
Definition: k3socketbase.h:152
KNetwork::KSocketBase::UnknownError
Definition: k3socketbase.h:161
KNetwork::KSocketBase::InProgress
Definition: k3socketbase.h:157
KSocketFactory::listen
QTcpServer * listen(const QString &protocol, const QHostAddress &address=QHostAddress::Any, quint16 port=0, QObject *parent=0)
Opens a TCP/IP socket for listening protocol protocol, binding only at address address.
Definition: ksocketfactory.cpp:115
KNetwork::KSocketAddress
A generic socket address.
Definition: k3socketaddress.h:414
KNetwork::KSocketBase::LookupFailure
Definition: k3socketbase.h:146
setError
static void setError(QAbstractSocket *socket, QAbstractSocket::SocketError error, const QString &errorString)
Definition: ksocketfactory.cpp:44
KNetwork::KSocketBase::NotConnected
Definition: k3socketbase.h:151
KDE::open
int open(const QString &pathname, int flags, mode_t mode)
Definition: kde_file_win.cpp:158
KNetwork::KSocketBase::WouldBlock
Definition: k3socketbase.h:154
KNetwork::KSocketBase::SocketError
SocketError
Possible socket error codes.
Definition: k3socketbase.h:143
QObject
KNetwork::KSocketBase::ConnectionTimedOut
Definition: k3socketbase.h:156
QString
KNetwork::KSocketBase::SocketOptions
SocketOptions
Possible socket options.
Definition: k3socketbase.h:108
KNetwork::KSocketBase::NotSupported
Definition: k3socketbase.h:159
KNetwork::KSocketBase::AlreadyBound
Definition: k3socketbase.h:149
KShell::NoError
Success.
Definition: kshell.h:89
KNetwork::KSocketBase::Timeout
Definition: k3socketbase.h:160
KNetwork::KSocketDevice
Low-level socket functionality.
Definition: k3socketdevice.h:51
KNetwork::KSocketBase::ConnectionRefused
Definition: k3socketbase.h:155
KNetwork::KPassiveSocketBase
Abstract base class for passive sockets.
Definition: k3socketbase.h:774
KNetwork::KSocketBase::NetFailure
Definition: k3socketbase.h:158
KNetwork::KSocketBase
Basic socket functionality.
Definition: k3socketbase.h:85
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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