KDECore
k3socketdevice.h
Go to the documentation of this file.
00001 /* -*- C++ -*- 00002 * Copyright (C) 2003,2005 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 KSOCKETDEVICE_H 00026 #define KSOCKETDEVICE_H 00027 00028 #include <QtCore/QSocketNotifier> 00029 #include "k3socketbase.h" 00030 00031 namespace KNetwork { 00032 00033 class KSocketDevice; 00034 class KSocketDeviceFactoryBase; 00035 00036 class KSocketDevicePrivate; 00051 class KDECORE_EXPORT KSocketDevice: public KActiveSocketBase, public KPassiveSocketBase 00052 { 00053 public: 00064 enum Capabilities 00065 { 00068 CanConnectString = 0x01, 00069 00072 CanBindString = 0x02, 00073 00076 CanNotBind = 0x04, 00077 00080 CanNotListen = 0x08, 00081 00085 CanMulticast = 0x10, 00086 00091 CanNotUseDatagrams = 0x20 00092 }; 00093 protected: 00096 int m_sockfd; 00097 00098 public: 00105 explicit KSocketDevice(const KSocketBase* = 0L, QObject* objparent = 0L); 00106 00113 explicit KSocketDevice(int fd, OpenMode mode = ReadWrite); 00114 00118 KSocketDevice(QObject* parent); 00119 00123 virtual ~KSocketDevice(); 00124 00128 int socket() const; 00129 00139 virtual int capabilities() const; 00140 00144 virtual bool setSocketOptions(int opts); 00145 00151 virtual void close(); 00152 00156 virtual bool flush(); 00157 00162 virtual bool create(int family, int type, int protocol); 00163 00168 bool create(const KResolverEntry& address); 00169 00173 virtual bool bind(const KResolverEntry& address); 00174 00178 virtual bool listen(int backlog = 5); // 5 is arbitrary 00179 00183 virtual bool connect(const KResolverEntry& address, 00184 OpenMode mode = ReadWrite); 00185 00190 virtual KSocketDevice* accept(); 00191 00195 virtual bool disconnect(); 00196 00200 virtual qint64 bytesAvailable() const; 00201 00208 virtual qint64 waitForMore(int msecs, bool *timeout = 0L); 00209 00213 virtual KSocketAddress localAddress() const; 00214 00219 virtual KSocketAddress peerAddress() const; 00220 00235 virtual KSocketAddress externalAddress() const; 00236 00244 QSocketNotifier* readNotifier() const; 00245 00252 QSocketNotifier* writeNotifier() const; 00253 00260 QSocketNotifier* exceptionNotifier() const; 00261 00265 virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress* from = 0L); 00266 00270 virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress* from = 0L); 00271 00275 virtual qint64 writeData(const char *data, qint64 len, 00276 const KSocketAddress* to = 0L); 00277 00296 virtual bool poll(bool* input, bool* output, bool* exception = 0L, 00297 int timeout = -1, bool* timedout = 0L); 00298 00310 bool poll(int timeout = -1, bool* timedout = 0L); 00311 00312 protected: 00320 explicit KSocketDevice(bool, const KSocketBase* parent = 0L); 00321 00337 virtual QSocketNotifier* createNotifier(QSocketNotifier::Type type) const; 00338 00339 public: 00350 static KSocketDevice* createDefault(KSocketBase* parent); 00351 00360 static KSocketDevice* createDefault(KSocketBase* parent, int capabilities); 00361 00368 static KSocketDeviceFactoryBase* setDefaultImpl(KSocketDeviceFactoryBase* factory); 00369 00374 static void addNewImpl(KSocketDeviceFactoryBase* factory, int capabilities); 00375 00376 private: 00377 KSocketDevice(const KSocketDevice&); 00378 KSocketDevice& operator=(const KSocketDevice&); 00379 00380 KSocketDevicePrivate* const d; 00381 }; 00382 00387 class KSocketDeviceFactoryBase 00388 { 00389 public: 00390 KSocketDeviceFactoryBase() {} 00391 virtual ~KSocketDeviceFactoryBase() {} 00392 00393 virtual KSocketDevice* create(KSocketBase*) const = 0; 00394 }; 00395 00400 template<class Impl> 00401 class KSocketDeviceFactory: public KSocketDeviceFactoryBase 00402 { 00403 public: 00404 KSocketDeviceFactory() {} 00405 virtual ~KSocketDeviceFactory() {} 00406 00411 virtual KSocketDevice* create(KSocketBase* parent) const 00412 { return new Impl(parent); } 00413 }; 00414 00415 } // namespaces 00416 00417 #endif
KDE 4.6 API Reference