kdecore Library API Documentation

kclientsocketbase.h

00001 /*  -*- C++ -*-
00002  *  Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
00003  *
00004  *
00005  *  Permission is hereby granted, free of charge, to any person obtaining
00006  *  a copy of this software and associated documentation files (the
00007  *  "Software"), to deal in the Software without restriction, including
00008  *  without limitation the rights to use, copy, modify, merge, publish,
00009  *  distribute, sublicense, and/or sell copies of the Software, and to
00010  *  permit persons to whom the Software is furnished to do so, subject to
00011  *  the following conditions:
00012  *
00013  *  The above copyright notice and this permission notice shall be included 
00014  *  in all copies or substantial portions of the Software.
00015  *
00016  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00017  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00019  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00020  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00021  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00022  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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   // protected slots
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 }               // namespace KNetwork
00515 
00516 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:32:27 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003