KDELibs4Support

k3socketdevice.h
1 /* -*- C++ -*-
2  * Copyright (C) 2003,2005 Thiago Macieira <[email protected]>
3  *
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef KSOCKETDEVICE_H
26 #define KSOCKETDEVICE_H
27 
28 #include <QSocketNotifier>
29 #include "k3socketbase.h"
30 
31 namespace KNetwork
32 {
33 
34 class KSocketDevice;
35 class KSocketDeviceFactoryBase;
36 
37 class KSocketDevicePrivate;
52 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KSocketDevice: public KActiveSocketBase, public KPassiveSocketBase
53 {
54 public:
65  enum Capabilities {
68  CanConnectString = 0x01,
69 
72  CanBindString = 0x02,
73 
76  CanNotBind = 0x04,
77 
80  CanNotListen = 0x08,
81 
85  CanMulticast = 0x10,
86 
91  CanNotUseDatagrams = 0x20
92  };
93 protected:
96  int m_sockfd;
97 
98 public:
105  KDELIBS4SUPPORT_DEPRECATED explicit KSocketDevice(const KSocketBase * = nullptr, QObject *objparent = nullptr);
106 
113  KDELIBS4SUPPORT_DEPRECATED explicit KSocketDevice(int fd, OpenMode mode = ReadWrite);
114 
118  KSocketDevice(QObject *parent);
119 
123  virtual ~KSocketDevice();
124 
128  int socket() const;
129 
139  virtual int capabilities() const;
140 
144  bool setSocketOptions(int opts) override;
145 
151  void close() override;
152 
156  virtual bool flush();
157 
162  virtual bool create(int family, int type, int protocol);
163 
168  bool create(const KResolverEntry &address);
169 
173  bool bind(const KResolverEntry &address) override;
174 
178  bool listen(int backlog = 5) override; // 5 is arbitrary
179 
183  virtual bool connect(const KResolverEntry &address,
184  OpenMode mode = ReadWrite) override;
185 
190  KSocketDevice *accept() override;
191 
195  bool disconnect() override;
196 
200  qint64 bytesAvailable() const override;
201 
208  qint64 waitForMore(int msecs, bool *timeout = nullptr) override;
209 
213  KSocketAddress localAddress() const override;
214 
219  KSocketAddress peerAddress() const override;
220 
235  KSocketAddress externalAddress() const override;
236 
244  QSocketNotifier *readNotifier() const;
245 
252  QSocketNotifier *writeNotifier() const;
253 
260  QSocketNotifier *exceptionNotifier() const;
261 
265  qint64 readData(char *data, qint64 maxlen, KSocketAddress *from = nullptr) override;
266 
270  qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from = nullptr) override;
271 
275  virtual qint64 writeData(const char *data, qint64 len,
276  const KSocketAddress *to = nullptr) override;
277 
296  virtual bool poll(bool *input, bool *output, bool *exception = nullptr,
297  int timeout = -1, bool *timedout = nullptr);
298 
310  bool poll(int timeout = -1, bool *timedout = nullptr);
311 
312 protected:
320  KDELIBS4SUPPORT_DEPRECATED explicit KSocketDevice(bool, const KSocketBase *parent = nullptr);
321 
337  virtual QSocketNotifier *createNotifier(QSocketNotifier::Type type) const;
338 
339 public:
350  static KSocketDevice *createDefault(KSocketBase *parent);
351 
360  static KSocketDevice *createDefault(KSocketBase *parent, int capabilities);
361 
368  static KSocketDeviceFactoryBase *setDefaultImpl(KSocketDeviceFactoryBase *factory);
369 
374  static void addNewImpl(KSocketDeviceFactoryBase *factory, int capabilities);
375 
376 private:
377  KSocketDevice(const KSocketDevice &);
378  KSocketDevice &operator=(const KSocketDevice &);
379 
380  KSocketDevicePrivate *const d;
381 };
382 
388 {
389 public:
391  virtual ~KSocketDeviceFactoryBase() {}
392 
393  virtual KSocketDevice *create(KSocketBase *) const = 0;
394 };
395 
400 template<class Impl>
402 {
403 public:
405  virtual ~KSocketDeviceFactory() {}
406 
411  KSocketDevice *create(KSocketBase *parent) const override
412  {
413  return new Impl(parent);
414  }
415 };
416 
417 } // namespaces
418 
419 #endif
Abstract class for active sockets.
Definition: k3socketbase.h:460
One resolution entry.
Definition: k3resolver.h:72
KSocketDevice * create(KSocketBase *parent) const override
Create the socket implementation.
A generic socket address.
QString from() const
A namespace to store all networking-related (socket) classes.
QString to() const
This class provides functionality for creating and registering socket implementations.
int m_sockfd
The socket file descriptor.
Capabilities
Capabilities for the socket implementation.
Low-level socket functionality.
Abstract base class for passive sockets.
Definition: k3socketbase.h:773
Basic socket functionality.
Definition: k3socketbase.h:86
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 22:41:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.