KDECore
kclientsocketbase.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 KCLIENTSOCKETBASE_H
00026 #define KCLIENTSOCKETBASE_H
00027
00028 #include <qobject.h>
00029 #include <qstring.h>
00030
00031 #include "ksocketbase.h"
00032 #include "kresolver.h"
00033 #include <kdelibs_export.h>
00034
00035 namespace KNetwork {
00036
00037 class KClientSocketBasePrivate;
00049 class KDECORE_EXPORT KClientSocketBase : public QObject, public KActiveSocketBase
00050 {
00051 Q_OBJECT
00052
00053 public:
00071 enum SocketState
00072 {
00073 Idle,
00074 HostLookup,
00075 HostFound,
00076 Bound,
00077 Connecting,
00078 Open,
00079 Closing,
00080
00081 Unconnected = Bound,
00082 Connected = Open,
00083 Connection = Open
00084 };
00085
00086 public:
00093 KClientSocketBase(QObject* parent, const char *name);
00094
00098 virtual ~KClientSocketBase();
00099
00104 SocketState state() const;
00105
00106 protected:
00110 virtual bool setSocketOptions(int opts);
00111
00112 public:
00121 KResolver& peerResolver() const;
00122
00126 const KResolverResults& peerResults() const;
00127
00136 KResolver& localResolver() const;
00137
00141 const KResolverResults& localResults() const;
00142
00157 void setResolutionEnabled(bool enable);
00158
00165 void setFamily(int families);
00166
00184 virtual bool lookup();
00185
00205 virtual bool bind(const QString& node = QString::null,
00206 const QString& service = QString::null) = 0;
00207
00216 virtual bool bind(const KResolverEntry& address);
00217
00246 virtual bool connect(const QString& node = QString::null,
00247 const QString& service = QString::null) = 0;
00248
00253 virtual bool connect(const KResolverEntry& address);
00254
00260 inline void connectToHost(const QString& host, Q_UINT16 port)
00261 { connect(host, QString::number(port)); }
00262
00267 virtual bool disconnect();
00268
00274 virtual inline bool open(int)
00275 { return connect(); }
00276
00283 virtual void close();
00284
00288 virtual void flush()
00289 { }
00290
00295 virtual Q_LONG bytesAvailable() const;
00296
00300 virtual Q_LONG waitForMore(int msecs, bool *timeout = 0L);
00301
00305 virtual Q_LONG readBlock(char *data, Q_ULONG maxlen);
00306
00311 virtual Q_LONG readBlock(char *data, Q_ULONG maxlen, KSocketAddress& from);
00312
00316 virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen);
00317
00322 virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen, KSocketAddress &from);
00323
00327 virtual Q_LONG writeBlock(const char *data, Q_ULONG len);
00328
00333 virtual Q_LONG writeBlock(const char *data, Q_ULONG len, const KSocketAddress& to);
00334
00338 virtual KSocketAddress localAddress() const;
00339
00343 virtual KSocketAddress peerAddress() const;
00344
00348 bool emitsReadyRead() const;
00349
00356 virtual void enableRead(bool enable);
00357
00361 bool emitsReadyWrite() const;
00362
00369 virtual void enableWrite(bool enable);
00370
00371 protected slots:
00372
00373
00383 virtual void slotReadActivity();
00384
00394 virtual void slotWriteActivity();
00395
00396 private slots:
00397 void lookupFinishedSlot();
00398
00399 signals:
00408 void stateChanged(int newstate);
00409
00415 void gotError(int code);
00416
00420 void hostFound();
00421
00428 void bound(const KResolverEntry& local);
00429
00445 void aboutToConnect(const KResolverEntry& remote, bool& skip);
00446
00453 void connected(const KResolverEntry& remote);
00454
00459 void closed();
00460
00469 void readyRead();
00470
00482 void readyWrite();
00483
00484 protected:
00489 void setState(SocketState state);
00490
00500 virtual void stateChanging(SocketState newState);
00501
00506 void copyError();
00507
00508 private:
00509 KClientSocketBase(const KClientSocketBase&);
00510 KClientSocketBase& operator=(const KClientSocketBase&);
00511
00512 KClientSocketBasePrivate *d;
00513 };
00514
00515 }
00516
00517 #endif