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 <qobject.h>
00029 #include <qstring.h>
00030
00031 #include "ksocketbase.h"
00032 #include "kresolver.h"
00033
00034 namespace KNetwork {
00035
00036 class KClientSocketBasePrivate;
00048 class KClientSocketBase : public QObject, public KActiveSocketBase
00049 {
00050 Q_OBJECT
00051
00052 public:
00070 enum SocketState
00071 {
00072 Idle,
00073 HostLookup,
00074 HostFound,
00075 Bound,
00076 Connecting,
00077 Open,
00078 Closing,
00079
00080 Unconnected = Bound,
00081 Connected = Open,
00082 Connection = Open
00083 };
00084
00085 public:
00092 KClientSocketBase(QObject* parent, const char *name);
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::null,
00205 const QString& service = QString::null) = 0;
00206
00215 virtual bool bind(const KResolverEntry& address);
00216
00245 virtual bool connect(const QString& node = QString::null,
00246 const QString& service = QString::null) = 0;
00247
00252 virtual bool connect(const KResolverEntry& address);
00253
00259 inline void connectToHost(const QString& host, Q_UINT16 port)
00260 { connect(host, QString::number(port)); }
00261
00266 virtual bool disconnect();
00267
00273 virtual inline bool open(int)
00274 { return connect(); }
00275
00282 virtual void close();
00283
00287 virtual void flush()
00288 { }
00289
00294 virtual Q_LONG bytesAvailable() const;
00295
00299 virtual Q_LONG waitForMore(int msecs, bool *timeout = 0L);
00300
00304 virtual Q_LONG readBlock(char *data, Q_ULONG maxlen);
00305
00310 virtual Q_LONG readBlock(char *data, Q_ULONG maxlen, KSocketAddress& from);
00311
00315 virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen);
00316
00321 virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen, KSocketAddress &from);
00322
00326 virtual Q_LONG writeBlock(const char *data, Q_ULONG len);
00327
00332 virtual Q_LONG writeBlock(const char *data, Q_ULONG len, const KSocketAddress& to);
00333
00337 virtual KSocketAddress localAddress() const;
00338
00342 virtual KSocketAddress peerAddress() const;
00343
00347 bool emitsReadyRead() const;
00348
00355 virtual void enableRead(bool enable);
00356
00360 bool emitsReadyWrite() const;
00361
00368 virtual void enableWrite(bool enable);
00369
00370 protected slots:
00371
00372
00382 virtual void slotReadActivity();
00383
00393 virtual void slotWriteActivity();
00394
00395 private slots:
00396 void lookupFinishedSlot();
00397
00398 signals:
00407 void stateChanged(int newstate);
00408
00414 void gotError(int code);
00415
00419 void hostFound();
00420
00427 void bound(const KResolverEntry& local);
00428
00444 void aboutToConnect(const KResolverEntry& remote, bool& skip);
00445
00452 void connected(const KResolverEntry& remote);
00453
00458 void closed();
00459
00468 void readyRead();
00469
00481 void readyWrite();
00482
00483 protected:
00488 void setState(SocketState state);
00489
00499 virtual void stateChanging(SocketState newState);
00500
00505 void copyError();
00506
00507 private:
00508 KClientSocketBase(const KClientSocketBase&);
00509 KClientSocketBase& operator=(const KClientSocketBase&);
00510
00511 KClientSocketBasePrivate *d;
00512 };
00513
00514 }
00515
00516 #endif
This file is part of the documentation for kdecore Library Version 3.3.2.