| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# ksocketdevice.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 KSOCKETDEVICE_H
    00026 #define KSOCKETDEVICE_H
    00027
    00028 #include <qsocketnotifier.h>
    00029 #include "ksocketbase.h"
    00030
    00031 namespace KNetwork {
    00032
    00033 class KSocketDevice;
    00034 class KSocketDeviceFactoryBase;
    00035
    00036 class KSocketDevicePrivate;
    00050 class KSocketDevice: public KActiveSocketBase, public KPassiveSocketBase
    00051 {
    00052 public:
    00063   enum Capabilities
    00064     {
    00067       CanConnectString = 0x01,
    00068
    00071       CanBindString = 0x02,
    00072
    00075       CanNotBind = 0x04,
    00076
    00079       CanNotListen = 0x08,
    00080
    00084       CanMulticast = 0x10,
    00085
    00090       CanNotUseDatagrams = 0x20
    00091     };
    00092 protected:
    00095   int m_sockfd;
    00096
    00097 public:
    00104   explicit KSocketDevice(const KSocketBase* = 0L);
    00105
    00112   explicit KSocketDevice(int fd);
    00113
    00117   virtual ~KSocketDevice();
    00118
    00122   inline int socket() const
    00123   { return m_sockfd; }
    00124
    00134   virtual int capabilities() const
    00135   { return 0; }
    00136
    00140   virtual bool setSocketOptions(int opts);
    00141
    00145   virtual bool open(int mode);
    00146
    00152   virtual void close();
    00153
    00157   virtual void flush()
    00158   { }
    00159
    00164   virtual bool create(int family, int type, int protocol);
    00165
    00170   bool create(const KResolverEntry& address);
    00171
    00175   virtual bool bind(const KResolverEntry& address);
    00176
    00180   virtual bool listen(int backlog = 5); // 5 is arbitrary
    00181
    00185   virtual bool connect(const KResolverEntry& address);
    00186
    00191   virtual KSocketDevice* accept();
    00192
    00196   virtual bool disconnect();
    00197
    00201   virtual Q_LONG bytesAvailable() const;
    00202
    00209   virtual Q_LONG waitForMore(int msecs, bool *timeout = 0L);
    00210
    00214   virtual Q_LONG readBlock(char *data, Q_ULONG maxlen);
    00215
    00219   virtual Q_LONG readBlock(char *data, Q_ULONG maxlen, KSocketAddress& from);
    00220
    00224   virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen);
    00225
    00229   virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen, KSocketAddress& from);
    00230
    00234   virtual Q_LONG writeBlock(const char *data, Q_ULONG len);
    00235
    00239   virtual Q_LONG writeBlock(const char *data, Q_ULONG len, const KSocketAddress& to);
    00240
    00244   virtual KSocketAddress localAddress() const;
    00245
    00250   virtual KSocketAddress peerAddress() const;
    00251
    00266   virtual KSocketAddress externalAddress() const;
    00267
    00275   QSocketNotifier* readNotifier() const;
    00276
    00283   QSocketNotifier* writeNotifier() const;
    00284
    00291   QSocketNotifier* exceptionNotifier() const;
    00292
    00311   virtual bool poll(bool* input, bool* output, bool* exception = 0L,
    00312             int timeout = -1, bool* timedout = 0L);
    00313
    00325   bool poll(int timeout = -1, bool* timedout = 0L);
    00326
    00327 protected:
    00335   KSocketDevice(bool, const KSocketBase* parent = 0L);
    00336
    00352   virtual QSocketNotifier* createNotifier(QSocketNotifier::Type type) const;
    00353
    00354 public:
    00365   static KSocketDevice* createDefault(KSocketBase* parent);
    00366
    00375   static KSocketDevice* createDefault(KSocketBase* parent, int capabilities);
    00376
    00383   static KSocketDeviceFactoryBase* setDefaultImpl(KSocketDeviceFactoryBase* factory);
    00384
    00389   static void addNewImpl(KSocketDeviceFactoryBase* factory, int capabilities);
    00390
    00391 private:
    00392   KSocketDevice(const KSocketDevice&);
    00393   KSocketDevice& operator=(const KSocketDevice&);
    00394
    00395   KSocketDevicePrivate *d;
    00396 };
    00397
    00402 class KSocketDeviceFactoryBase
    00403 {
    00404 public:
    00405   virtual KSocketDevice* create(KSocketBase*) const = 0;
    00406 };
    00407
    00412 template<class Impl>
    00413 class KSocketDeviceFactory: public KSocketDeviceFactoryBase
    00414 {
    00415 public:
    00416   virtual KSocketDevice* create(KSocketBase* parent) const
    00417   { return new Impl(parent); }
    00418 };
    00419
    00420 }               // namespaces
    00421
    00422 #endif

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:11 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003