KDECore
k3clientsocketbase.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 <QtCore/QObject>
00029 #include <QtCore/QString>
00030
00031 #include <kdecore_export.h>
00032 #include "k3socketbase.h"
00033 #include "k3resolver.h"
00034
00035 namespace KNetwork {
00036
00037 class KClientSocketBasePrivate;
00049 class KDECORE_EXPORT KClientSocketBase : 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:
00092 KClientSocketBase(QObject* parent);
00093
00097 virtual ~KClientSocketBase();
00098
00103 SocketState state() const;
00104
00105 protected:
00109 virtual bool setSocketOptions(int opts);
00110
00111 public:
00120 KResolver& peerResolver() const;
00121
00125 const KResolverResults& peerResults() const;
00126
00135 KResolver& localResolver() const;
00136
00140 const KResolverResults& localResults() const;
00141
00156 void setResolutionEnabled(bool enable);
00157
00164 void setFamily(int families);
00165
00183 virtual bool lookup();
00184
00204 virtual bool bind(const QString& node = QString(),
00205 const QString& service = QString()) = 0;
00206
00215 virtual bool bind(const KResolverEntry& address);
00216
00246 virtual bool connect(const QString& node = QString(),
00247 const QString& service = QString(),
00248 OpenMode mode = ReadWrite) = 0;
00249
00254 virtual bool connect(const KResolverEntry& address,
00255 OpenMode mode = ReadWrite);
00256
00261 virtual bool disconnect();
00262
00268 virtual bool open(OpenMode mode);
00269
00276 virtual void close();
00277
00282 virtual bool flush();
00283
00288 virtual qint64 bytesAvailable() const;
00289
00293 virtual qint64 waitForMore(int msecs, bool *timeout = 0L);
00294
00298 virtual KSocketAddress localAddress() const;
00299
00303 virtual KSocketAddress peerAddress() const;
00304
00308 bool emitsReadyRead() const;
00309
00316 virtual void enableRead(bool enable);
00317
00321 bool emitsReadyWrite() const;
00322
00329 virtual void enableWrite(bool enable);
00330
00331 protected Q_SLOTS:
00332
00333
00343 virtual void slotReadActivity();
00344
00354 virtual void slotWriteActivity();
00355
00356 private Q_SLOTS:
00357 void lookupFinishedSlot();
00358
00359 Q_SIGNALS:
00368 void stateChanged(int newstate);
00369
00375 void gotError(int code);
00376
00380 void hostFound();
00381
00388 void bound(const KNetwork::KResolverEntry& local);
00389
00405 void aboutToConnect(const KNetwork::KResolverEntry& remote, bool& skip);
00406
00413 void connected(const KNetwork::KResolverEntry& remote);
00414
00419 void closed();
00420
00421 #if 0
00422
00431 void readyRead();
00432 #endif
00433
00445 void readyWrite();
00446
00447 protected:
00451 virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress *from);
00452
00456 virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from);
00457
00462 virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress* to);
00463
00468 void setState(SocketState state);
00469
00479 virtual void stateChanging(SocketState newState);
00480
00485 void copyError();
00486
00487 private:
00488 KClientSocketBase(const KClientSocketBase&);
00489 KClientSocketBase& operator=(const KClientSocketBase&);
00490
00491 KClientSocketBasePrivate* const d;
00492 };
00493
00494 }
00495
00496 #endif