KDECore
k3socketdevice.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef KSOCKETDEVICE_H
00026 #define KSOCKETDEVICE_H
00027
00028 #include <QtCore/QSocketNotifier>
00029 #include "k3socketbase.h"
00030
00031 namespace KNetwork {
00032
00033 class KSocketDevice;
00034 class KSocketDeviceFactoryBase;
00035
00036 class KSocketDevicePrivate;
00050 class KDECORE_EXPORT KSocketDevice: public KActiveSocketBase, public KPassiveSocketBase
00051 {
00052 public:
00063 enum Capabilities
00064 {
00067 CanConnectString = 0x01,
00068
00071 CanBindString = 0x02,
00072
00075 CanNotBind = 0x04,
00076
00079 CanNotListen = 0x08,
00080
00084 CanMulticast = 0x10,
00085
00090 CanNotUseDatagrams = 0x20
00091 };
00092 protected:
00095 int m_sockfd;
00096
00097 public:
00104 explicit KSocketDevice(const KSocketBase* = 0L, QObject* objparent = 0L);
00105
00112 explicit KSocketDevice(int fd, OpenMode mode = ReadWrite);
00113
00117 KSocketDevice(QObject* parent);
00118
00122 virtual ~KSocketDevice();
00123
00127 int socket() const;
00128
00138 virtual int capabilities() const;
00139
00143 virtual bool setSocketOptions(int opts);
00144
00150 virtual void close();
00151
00155 virtual bool flush();
00156
00161 virtual bool create(int family, int type, int protocol);
00162
00167 bool create(const KResolverEntry& address);
00168
00172 virtual bool bind(const KResolverEntry& address);
00173
00177 virtual bool listen(int backlog = 5);
00178
00182 virtual bool connect(const KResolverEntry& address,
00183 OpenMode mode = ReadWrite);
00184
00189 virtual KSocketDevice* accept();
00190
00194 virtual bool disconnect();
00195
00199 virtual qint64 bytesAvailable() const;
00200
00207 virtual qint64 waitForMore(int msecs, bool *timeout = 0L);
00208
00212 virtual KSocketAddress localAddress() const;
00213
00218 virtual KSocketAddress peerAddress() const;
00219
00234 virtual KSocketAddress externalAddress() const;
00235
00243 QSocketNotifier* readNotifier() const;
00244
00251 QSocketNotifier* writeNotifier() const;
00252
00259 QSocketNotifier* exceptionNotifier() const;
00260
00264 virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress* from = 0L);
00265
00269 virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress* from = 0L);
00270
00274 virtual qint64 writeData(const char *data, qint64 len,
00275 const KSocketAddress* to = 0L);
00276
00295 virtual bool poll(bool* input, bool* output, bool* exception = 0L,
00296 int timeout = -1, bool* timedout = 0L);
00297
00309 bool poll(int timeout = -1, bool* timedout = 0L);
00310
00311 protected:
00319 explicit KSocketDevice(bool, const KSocketBase* parent = 0L);
00320
00336 virtual QSocketNotifier* createNotifier(QSocketNotifier::Type type) const;
00337
00338 public:
00349 static KSocketDevice* createDefault(KSocketBase* parent);
00350
00359 static KSocketDevice* createDefault(KSocketBase* parent, int capabilities);
00360
00367 static KSocketDeviceFactoryBase* setDefaultImpl(KSocketDeviceFactoryBase* factory);
00368
00373 static void addNewImpl(KSocketDeviceFactoryBase* factory, int capabilities);
00374
00375 private:
00376 KSocketDevice(const KSocketDevice&);
00377 KSocketDevice& operator=(const KSocketDevice&);
00378
00379 KSocketDevicePrivate* const d;
00380 };
00381
00386 class KSocketDeviceFactoryBase
00387 {
00388 public:
00389 KSocketDeviceFactoryBase() {}
00390 virtual ~KSocketDeviceFactoryBase() {}
00391
00392 virtual KSocketDevice* create(KSocketBase*) const = 0;
00393 };
00394
00399 template<class Impl>
00400 class KSocketDeviceFactory: public KSocketDeviceFactoryBase
00401 {
00402 public:
00403 KSocketDeviceFactory() {}
00404 virtual ~KSocketDeviceFactory() {}
00405
00410 virtual KSocketDevice* create(KSocketBase* parent) const
00411 { return new Impl(parent); }
00412 };
00413
00414 }
00415
00416 #endif