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

KDECore

k3socketbase.h

Go to the documentation of this file.
00001 /*  -*- C++ -*-
00002  *  Copyright (C) 2003,2005 Thiago Macieira <thiago@kde.org>
00003  *
00004  *
00005  *  Permission is hereby granted, free of charge, to any person obtaining
00006  *  a copy of this software and associated documentation files (the
00007  *  "Software"), to deal in the Software without restriction, including
00008  *  without limitation the rights to use, copy, modify, merge, publish,
00009  *  distribute, sublicense, and/or sell copies of the Software, and to
00010  *  permit persons to whom the Software is furnished to do so, subject to
00011  *  the following conditions:
00012  *
00013  *  The above copyright notice and this permission notice shall be included
00014  *  in all copies or substantial portions of the Software.
00015  *
00016  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00017  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00019  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00020  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00021  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00022  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 /*
00026  * Even before our #ifdef, clean up the namespace
00027  */
00028 #ifdef socket
00029 #undef socket
00030 #endif
00031 
00032 #ifdef bind
00033 #undef bind
00034 #endif
00035 
00036 #ifdef listen
00037 #undef listen
00038 #endif
00039 
00040 #ifdef connect
00041 #undef connect
00042 #endif
00043 
00044 #ifdef accept
00045 #undef accept
00046 #endif
00047 
00048 #ifdef getpeername
00049 #undef getpeername
00050 #endif
00051 
00052 #ifdef getsockname
00053 #undef getsockname
00054 #endif
00055 
00056 #ifndef KSOCKETBASE_H
00057 #define KSOCKETBASE_H
00058 
00059 #include <QtCore/QIODevice>
00060 #include <QtCore/QString>
00061 
00062 #include <kdecore_export.h>
00063 #include "k3socketaddress.h"
00064 
00065 class QMutex;
00066 
00067 namespace KNetwork {
00068 
00069 class KResolverEntry;
00070 class KSocketDevice;
00071 
00072 class KSocketBasePrivate;
00084 class KDECORE_EXPORT KSocketBase
00085 {
00086 public:
00107   enum SocketOptions
00108     {
00109       Blocking = 0x01,
00110       AddressReuseable = 0x02,
00111       IPv6Only = 0x04,
00112       Keepalive = 0x08,
00113       Broadcast = 0x10,
00114       NoDelay = 0x20
00115     };
00116 
00142   enum SocketError
00143     {
00144       NoError = 0,
00145       LookupFailure,
00146       AddressInUse,
00147       AlreadyCreated,
00148       AlreadyBound,
00149       AlreadyConnected,
00150       NotConnected,
00151       NotBound,
00152       NotCreated,
00153       WouldBlock,
00154       ConnectionRefused,
00155       ConnectionTimedOut,
00156       InProgress,
00157       NetFailure,
00158       NotSupported,
00159       Timeout,
00160       UnknownError,
00161       RemotelyDisconnected
00162     };
00163 
00164 public:
00168   KSocketBase();
00169 
00173   virtual ~KSocketBase();
00174 
00175   /*
00176    * The following functions are shared by all descended classes and will have
00177    * to be reimplemented.
00178    */
00179 
00180 protected:
00194   virtual bool setSocketOptions(int opts);
00195 
00205   virtual int socketOptions() const;
00206 
00207 public:
00223   virtual bool setBlocking(bool enable);
00224 
00231   bool blocking() const;
00232 
00247   virtual bool setAddressReuseable(bool enable);
00248 
00255   bool addressReuseable() const;
00256 
00272   virtual bool setIPv6Only(bool enable);
00273 
00280   bool isIPv6Only() const;
00281 
00293   virtual bool setBroadcast(bool enable);
00294 
00301   bool broadcast() const;
00302 
00316   virtual bool setNoDelay(bool enable);
00317 
00323   bool noDelay() const;
00324 
00331   KSocketDevice* socketDevice() const;
00332 
00346   virtual void setSocketDevice(KSocketDevice* device);
00347 
00369   int setRequestedCapabilities(int add, int remove = 0);
00370 
00371 protected:
00376   bool hasDevice() const;
00377 
00383   void setError(SocketError error);
00384 
00388   void resetError();
00389 
00390 public:
00395   SocketError error() const;
00396 
00400   QString errorString() const;
00401 
00417   QMutex* mutex() const;
00418 
00419 public:
00425   static QString errorString(SocketError code);
00426 
00435   static bool isFatalError(int code);
00436 
00437 private:
00440   void unsetSocketDevice();
00441 
00442   KSocketBase(const KSocketBase&);
00443   KSocketBase& operator =(const KSocketBase&);
00444 
00445   KSocketBasePrivate* const d;
00446 
00447   friend class KSocketDevice;
00448 };
00449 
00459 class KDECORE_EXPORT KActiveSocketBase: public QIODevice, virtual public KSocketBase
00460 {
00461   Q_OBJECT
00462 public:
00466   KActiveSocketBase(QObject* parent);
00467 
00471   virtual ~KActiveSocketBase();
00472 
00476   QString errorString() const;
00477 
00481   virtual void setSocketDevice(KSocketDevice* device);
00482 
00486   virtual bool open(OpenMode mode);
00487 
00498   virtual bool bind(const KResolverEntry& address) = 0;
00499 
00518   virtual bool connect(const KResolverEntry& address,
00519                OpenMode mode = ReadWrite) = 0;
00520 
00536   virtual bool disconnect() = 0;
00537 
00541   virtual bool isSequential() const;
00542 
00547   virtual qint64 size() const;
00548 
00553   virtual qint64 pos() const;
00554 
00559   virtual bool seek(qint64);
00560 
00565   virtual bool atEnd() const;
00566 
00573   qint64 read(char *data, qint64 maxlen);
00574 
00581   QByteArray read(qint64 len);
00582 
00594   qint64 read(char *data, qint64 maxlen, KSocketAddress& from);
00595 
00607   qint64 peek(char *data, qint64 maxlen);
00608 
00622   qint64 peek(char *data, qint64 maxlen, KSocketAddress& from);
00623 
00630   qint64 write(const char *data, qint64 len);
00631 
00638   qint64 write(const QByteArray& data);
00639 
00651   qint64 write(const char *data, qint64 len, const KSocketAddress& to);
00652 
00664   virtual qint64 waitForMore(int msecs, bool *timeout = 0L) = 0;
00665 
00669   void ungetChar(char);
00670 
00674   virtual KSocketAddress localAddress() const = 0;
00675 
00681   virtual KSocketAddress peerAddress() const = 0;
00682 
00683   // FIXME KDE 4.0:
00684   // enable this function
00685 #if 0
00686 
00689   virtual KSocketAddress externalAddress() const = 0;
00690 #endif
00691 
00692 protected:
00699   virtual qint64 readData(char *data, qint64 len);
00700 
00712   virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress* from) = 0;
00713 
00726   virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress* from) = 0;
00727 
00734   virtual qint64 writeData(const char *data, qint64 len);
00735 
00747   virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress* to) = 0;
00748 
00754   void setError(SocketError error);
00755 
00759   void resetError();
00760 };
00761 
00771 class KDECORE_EXPORT KPassiveSocketBase: virtual public KSocketBase
00772 {
00773 public:
00777   KPassiveSocketBase();
00778 
00782   virtual ~KPassiveSocketBase();
00783 
00794   virtual bool bind(const KResolverEntry& address) = 0;
00795 
00810   virtual bool listen(int backlog) = 0;
00811 
00816   virtual void close() = 0;
00817 
00831   virtual KActiveSocketBase* accept() = 0;
00832 
00836   virtual KSocketAddress localAddress() const = 0;
00837 
00841   virtual KSocketAddress externalAddress() const = 0;
00842 
00843 private:
00844   KPassiveSocketBase(const KPassiveSocketBase&);
00845   KPassiveSocketBase& operator = (const KPassiveSocketBase&);
00846 };
00847 
00848 }               // namespace KNetwork
00849 
00850 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal