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;
00051 class KDECORE_EXPORT KSocketDevice: public KActiveSocketBase, public KPassiveSocketBase
00052 {
00053 public:
00064 enum Capabilities
00065 {
00068 CanConnectString = 0x01,
00069
00072 CanBindString = 0x02,
00073
00076 CanNotBind = 0x04,
00077
00080 CanNotListen = 0x08,
00081
00085 CanMulticast = 0x10,
00086
00091 CanNotUseDatagrams = 0x20
00092 };
00093 protected:
00096 int m_sockfd;
00097
00098 public:
00105 explicit KSocketDevice(const KSocketBase* = 0L, QObject* objparent = 0L);
00106
00113 explicit KSocketDevice(int fd, OpenMode mode = ReadWrite);
00114
00118 KSocketDevice(QObject* parent);
00119
00123 virtual ~KSocketDevice();
00124
00128 int socket() const;
00129
00139 virtual int capabilities() const;
00140
00144 virtual bool setSocketOptions(int opts);
00145
00151 virtual void close();
00152
00156 virtual bool flush();
00157
00162 virtual bool create(int family, int type, int protocol);
00163
00168 bool create(const KResolverEntry& address);
00169
00173 virtual bool bind(const KResolverEntry& address);
00174
00178 virtual bool listen(int backlog = 5);
00179
00183 virtual bool connect(const KResolverEntry& address,
00184 OpenMode mode = ReadWrite);
00185
00190 virtual KSocketDevice* accept();
00191
00195 virtual bool disconnect();
00196
00200 virtual qint64 bytesAvailable() const;
00201
00208 virtual qint64 waitForMore(int msecs, bool *timeout = 0L);
00209
00213 virtual KSocketAddress localAddress() const;
00214
00219 virtual KSocketAddress peerAddress() const;
00220
00235 virtual KSocketAddress externalAddress() const;
00236
00244 QSocketNotifier* readNotifier() const;
00245
00252 QSocketNotifier* writeNotifier() const;
00253
00260 QSocketNotifier* exceptionNotifier() const;
00261
00265 virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress* from = 0L);
00266
00270 virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress* from = 0L);
00271
00275 virtual qint64 writeData(const char *data, qint64 len,
00276 const KSocketAddress* to = 0L);
00277
00296 virtual bool poll(bool* input, bool* output, bool* exception = 0L,
00297 int timeout = -1, bool* timedout = 0L);
00298
00310 bool poll(int timeout = -1, bool* timedout = 0L);
00311
00312 protected:
00320 explicit KSocketDevice(bool, const KSocketBase* parent = 0L);
00321
00337 virtual QSocketNotifier* createNotifier(QSocketNotifier::Type type) const;
00338
00339 public:
00350 static KSocketDevice* createDefault(KSocketBase* parent);
00351
00360 static KSocketDevice* createDefault(KSocketBase* parent, int capabilities);
00361
00368 static KSocketDeviceFactoryBase* setDefaultImpl(KSocketDeviceFactoryBase* factory);
00369
00374 static void addNewImpl(KSocketDeviceFactoryBase* factory, int capabilities);
00375
00376 private:
00377 KSocketDevice(const KSocketDevice&);
00378 KSocketDevice& operator=(const KSocketDevice&);
00379
00380 KSocketDevicePrivate* const d;
00381 };
00382
00387 class KSocketDeviceFactoryBase
00388 {
00389 public:
00390 KSocketDeviceFactoryBase() {}
00391 virtual ~KSocketDeviceFactoryBase() {}
00392
00393 virtual KSocketDevice* create(KSocketBase*) const = 0;
00394 };
00395
00400 template<class Impl>
00401 class KSocketDeviceFactory: public KSocketDeviceFactoryBase
00402 {
00403 public:
00404 KSocketDeviceFactory() {}
00405 virtual ~KSocketDeviceFactory() {}
00406
00411 virtual KSocketDevice* create(KSocketBase* parent) const
00412 { return new Impl(parent); }
00413 };
00414
00415 }
00416
00417 #endif