kserversocket.h

00001 /*  -*- C++ -*-
00002  *  Copyright (C) 2003 Thiago Macieira <thiago@kde.org>
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 KSERVERSOCKET_H
00026 #define KSERVERSOCKET_H
00027 
00028 #include <qobject.h>
00029 #include "ksocketbase.h"
00030 
00031 namespace KNetwork {
00032 
00033 class KSocketDevice;
00034 class KStreamSocket; 
00035 class KResolver;
00036 class KResolverResults;
00037 
00038 class KServerSocketPrivate;
00107 class KDECORE_EXPORT KServerSocket: public QObject, public KPassiveSocketBase
00108 {
00109   Q_OBJECT
00110 public:
00121   KServerSocket(QObject* parent = 0L, const char *name = 0L);
00122 
00140   KServerSocket(const QString& service, QObject* parent = 0L, const char *name = 0L);
00141 
00160   KServerSocket(const QString& node, const QString& service,
00161         QObject* parent = 0L, const char *name = 0L);
00162 
00169   ~KServerSocket();
00170 
00171 protected:
00175   virtual bool setSocketOptions(int opts);
00176 
00177 public:
00186   KResolver& resolver() const;
00187 
00191   const KResolverResults& resolverResults() const;
00192 
00207   void setResolutionEnabled(bool enable);
00208 
00215   void setFamily(int families);
00216 
00230   void setAddress(const QString& service);
00231 
00247   void setAddress(const QString& node, const QString& service);
00248 
00256   void setTimeout(int msecs);
00257 
00275   virtual bool lookup();
00276 
00290   virtual bool bind(const QString& node, const QString& service);
00291 
00298   virtual bool bind(const QString& service);
00299 
00305   virtual bool bind();
00306 
00314   virtual bool bind(const KResolverEntry& address);
00315 
00329   virtual bool listen(int backlog = 5); // 5 is arbitrary
00330 
00334   virtual void close();
00335 
00347   void setAcceptBuffered(bool enable);
00348 
00366   virtual KActiveSocketBase* accept();
00367 
00371   virtual KSocketAddress localAddress() const;
00372 
00376   virtual KSocketAddress externalAddress() const;
00377 
00378 private slots:
00379   void lookupFinishedSlot();
00380 
00381 signals:
00387   void gotError(int code);
00388 
00392   void hostFound();
00393 
00400   void bound(const KResolverEntry& local);
00401 
00406   void closed();
00407 
00413   void readyAccept();
00414 
00415 protected:
00420   void copyError();
00421 
00422 private:
00423   bool doBind();
00424   bool doListen();
00425 
00426 private:
00427   KServerSocket(const KServerSocket&);
00428   KServerSocket& operator=(const KServerSocket&);
00429 
00430   KServerSocketPrivate *d;
00431 };
00432 
00433 }               // namespace KNetwork
00434 
00435 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys