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 TDESOCKETDEVICE_H
00026 #define TDESOCKETDEVICE_H
00027
00028 #include <tqsocketnotifier.h>
00029 #include "tdesocketbase.h"
00030
00031 namespace KNetwork {
00032
00033 class TDESocketDevice;
00034 class TDESocketDeviceFactoryBase;
00035
00036 class TDESocketDevicePrivate;
00050 class TDECORE_EXPORT TDESocketDevice: 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 TDESocketDevice(const TDESocketBase* = 0L);
00105
00112 explicit TDESocketDevice(int fd);
00113
00117 virtual ~TDESocketDevice();
00118
00122 inline int socket() const
00123 { return m_sockfd; }
00124
00134 virtual int capabilities() const
00135 { return 0; }
00136
00140 virtual bool setSocketOptions(int opts);
00141
00145 virtual bool open(TQ_OpenMode mode);
00146
00152 virtual void close();
00153
00157 virtual void flush()
00158 { }
00159
00164 virtual bool create(int family, int type, int protocol);
00165
00170 bool create(const KResolverEntry& address);
00171
00175 virtual bool bind(const KResolverEntry& address);
00176
00180 virtual bool listen(int backlog = 5);
00181
00185 virtual bool connect(const KResolverEntry& address);
00186
00191 virtual TDESocketDevice* accept();
00192
00196 virtual bool disconnect();
00197
00201 #ifdef USE_QT3
00202 virtual TQ_LONG bytesAvailable() const;
00203 #endif
00204 #ifdef USE_QT4
00205 virtual qint64 bytesAvailable() const;
00206 #endif
00207
00214 virtual TQ_LONG waitForMore(int msecs, bool *timeout = 0L);
00215
00219 virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen);
00220
00224 virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen, TDESocketAddress& from);
00225
00229 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen);
00230
00234 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen, TDESocketAddress& from);
00235
00239 virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len);
00240
00244 virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len, const TDESocketAddress& to);
00245
00249 virtual TDESocketAddress localAddress() const;
00250
00255 virtual TDESocketAddress peerAddress() const;
00256
00271 virtual TDESocketAddress externalAddress() const;
00272
00280 TQSocketNotifier* readNotifier() const;
00281
00288 TQSocketNotifier* writeNotifier() const;
00289
00296 TQSocketNotifier* exceptionNotifier() const;
00297
00316 virtual bool poll(bool* input, bool* output, bool* exception = 0L,
00317 int timeout = -1, bool* timedout = 0L);
00318
00330 bool poll(int timeout = -1, bool* timedout = 0L);
00331
00332 protected:
00340 TDESocketDevice(bool, const TDESocketBase* parent = 0L);
00341
00357 virtual TQSocketNotifier* createNotifier(TQSocketNotifier::Type type) const;
00358
00359 public:
00370 static TDESocketDevice* createDefault(TDESocketBase* parent);
00371
00380 static TDESocketDevice* createDefault(TDESocketBase* parent, int capabilities);
00381
00388 static TDESocketDeviceFactoryBase* setDefaultImpl(TDESocketDeviceFactoryBase* factory);
00389
00394 static void addNewImpl(TDESocketDeviceFactoryBase* factory, int capabilities);
00395
00396 private:
00397 TDESocketDevice(const TDESocketDevice&);
00398 TDESocketDevice& operator=(const TDESocketDevice&);
00399
00400 TDESocketDevicePrivate *d;
00401 };
00402
00407 class TDESocketDeviceFactoryBase
00408 {
00409 public:
00410 TDESocketDeviceFactoryBase() {}
00411 virtual ~TDESocketDeviceFactoryBase() {}
00412
00413 virtual TDESocketDevice* create(TDESocketBase*) const = 0;
00414 };
00415
00420 template<class Impl>
00421 class TDESocketDeviceFactory: public TDESocketDeviceFactoryBase
00422 {
00423 public:
00424 TDESocketDeviceFactory() {}
00425 virtual ~TDESocketDeviceFactory() {}
00426
00427 virtual TDESocketDevice* create(TDESocketBase* parent) const
00428 { return new Impl(parent); }
00429 };
00430
00431 }
00432
00433 #endif