tdecore
kclientsocketbase.h
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 KCLIENTSOCKETBASE_H
00026 #define KCLIENTSOCKETBASE_H
00027
00028 #include <tqobject.h>
00029 #include <tqstring.h>
00030
00031 #include "tdesocketbase.h"
00032 #include "kresolver.h"
00033 #include <tdelibs_export.h>
00034
00035 #ifdef Q_MOC_RUN
00036 #define USE_QT4
00037 #endif // Q_MOC_RUN
00038
00039 namespace KNetwork {
00040
00041 class KClientSocketBasePrivate;
00053 class TDECORE_EXPORT KClientSocketBase :
00054 #ifdef USE_QT4
00055 #else // USE_QT4
00056 public TQObject,
00057 #endif // USE_QT4
00058 public KActiveSocketBase
00059 {
00060 Q_OBJECT
00061
00062
00063 public:
00081 enum SocketState
00082 {
00083 Idle,
00084 HostLookup,
00085 HostFound,
00086 Bound,
00087 Connecting,
00088 Open,
00089 Closing,
00090
00091 Unconnected = Bound,
00092 Connected = Open,
00093 Connection = Open
00094 };
00095
00096 public:
00103 KClientSocketBase(TQObject* parent, const char *name);
00104
00108 virtual ~KClientSocketBase();
00109
00114 SocketState state() const;
00115
00116 protected:
00120 virtual bool setSocketOptions(int opts);
00121
00122 public:
00131 KResolver& peerResolver() const;
00132
00136 const KResolverResults& peerResults() const;
00137
00146 KResolver& localResolver() const;
00147
00151 const KResolverResults& localResults() const;
00152
00167 void setResolutionEnabled(bool enable);
00168
00175 void setFamily(int families);
00176
00194 virtual bool lookup();
00195
00215 virtual bool bind(const TQString& node = TQString::null,
00216 const TQString& service = TQString::null) = 0;
00217
00226 virtual bool bind(const KResolverEntry& address);
00227
00256 virtual bool connect(const TQString& node = TQString::null,
00257 const TQString& service = TQString::null) = 0;
00258
00263 virtual bool connect(const KResolverEntry& address);
00264
00270 inline void connectToHost(const TQString& host, TQ_UINT16 port)
00271 { connect(host, TQString::number(port)); }
00272
00277 virtual bool disconnect();
00278
00284 virtual inline bool open(TQ_OpenMode)
00285 { return connect(); }
00286
00293 virtual void close();
00294
00298 virtual void flush()
00299 { }
00300
00305 #ifdef USE_QT3
00306 virtual TQ_LONG bytesAvailable() const;
00307 #endif
00308 #ifdef USE_QT4
00309 virtual qint64 bytesAvailable() const;
00310 #endif
00311
00315 virtual TQ_LONG waitForMore(int msecs, bool *timeout = 0L);
00316
00320 virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen);
00321
00326 virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen, TDESocketAddress& from);
00327
00331 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen);
00332
00337 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen, TDESocketAddress &from);
00338
00342 virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len);
00343
00348 virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len, const TDESocketAddress& to);
00349
00353 virtual TDESocketAddress localAddress() const;
00354
00358 virtual TDESocketAddress peerAddress() const;
00359
00363 bool emitsReadyRead() const;
00364
00371 virtual void enableRead(bool enable);
00372
00376 bool emitsReadyWrite() const;
00377
00384 virtual void enableWrite(bool enable);
00385
00386 protected slots:
00387
00388
00398 virtual void slotReadActivity();
00399
00409 virtual void slotWriteActivity();
00410
00411 private slots:
00412 void lookupFinishedSlot();
00413
00414 signals:
00423 void stateChanged(int newstate);
00424
00430 void gotError(int code);
00431
00435 void hostFound();
00436
00443 void bound(const KResolverEntry& local);
00444
00460 void aboutToConnect(const KResolverEntry& remote, bool& skip);
00461
00468 void connected(const KResolverEntry& remote);
00469
00474 void closed();
00475
00484 void readyRead();
00485
00497 void readyWrite();
00498
00499 protected:
00504 void setState(SocketState state);
00505
00515 virtual void stateChanging(SocketState newState);
00516
00521 void copyError();
00522
00523 private:
00524 KClientSocketBase(const KClientSocketBase&);
00525 KClientSocketBase& operator=(const KClientSocketBase&);
00526
00527 KClientSocketBasePrivate *d;
00528 };
00529
00530 }
00531
00532 #endif