KDELibs4Support

k3clientsocketbase.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 KCLIENTSOCKETBASE_H
26 #define KCLIENTSOCKETBASE_H
27 
28 #include <QObject>
29 #include <QString>
30 
31 #include <kdelibs4support_export.h>
32 #include "k3socketbase.h"
33 #include "k3resolver.h"
34 
35 namespace KNetwork
36 {
37 
38 class KClientSocketBasePrivate;
51 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KClientSocketBase : public KActiveSocketBase
52 {
53  Q_OBJECT
54 
55 public:
73  enum SocketState {
74  Idle,
75  HostLookup,
76  HostFound,
77  Bound,
78  Connecting,
79  Open,
80  Closing,
81 
82  Unconnected = Bound,
83  Connected = Open,
84  Connection = Open
85  };
86 
87 public:
93  KClientSocketBase(QObject *parent);
94 
98  virtual ~KClientSocketBase();
99 
104  SocketState state() const;
105 
106 protected:
110  bool setSocketOptions(int opts) override;
111 
112 public:
121  KResolver &peerResolver() const;
122 
126  const KResolverResults &peerResults() const;
127 
136  KResolver &localResolver() const;
137 
141  const KResolverResults &localResults() const;
142 
157  void setResolutionEnabled(bool enable);
158 
165  void setFamily(int families);
166 
184  virtual bool lookup();
185 
205  virtual bool bind(const QString &node = QString(),
206  const QString &service = QString()) = 0;
207 
216  bool bind(const KResolverEntry &address) override;
217 
247  virtual bool connect(const QString &node = QString(),
248  const QString &service = QString(),
249  OpenMode mode = ReadWrite) = 0;
250 
255  virtual bool connect(const KResolverEntry &address,
256  OpenMode mode = ReadWrite) override;
257 
262  bool disconnect() override;
263 
269  bool open(OpenMode mode) override;
270 
277  void close() override;
278 
283  virtual bool flush();
284 
289  qint64 bytesAvailable() const override;
290 
294  qint64 waitForMore(int msecs, bool *timeout = nullptr) override;
295 
299  KSocketAddress localAddress() const override;
300 
304  KSocketAddress peerAddress() const override;
305 
309  bool emitsReadyRead() const;
310 
317  virtual void enableRead(bool enable);
318 
322  bool emitsReadyWrite() const;
323 
330  virtual void enableWrite(bool enable);
331 
332 protected Q_SLOTS:
333  // protected slots
334 
344  virtual void slotReadActivity();
345 
355  virtual void slotWriteActivity();
356 
357 private Q_SLOTS:
358  void lookupFinishedSlot();
359 
360 Q_SIGNALS:
369  void stateChanged(int newstate);
370 
376  void gotError(int code);
377 
381  void hostFound();
382 
389  void bound(const KNetwork::KResolverEntry &local);
390 
406  void aboutToConnect(const KNetwork::KResolverEntry &remote, bool &skip);
407 
414  void connected(const KNetwork::KResolverEntry &remote);
415 
420  void closed();
421 
422 #if 0
423  // QIODevice already has this
432  void readyRead();
433 #endif
434 
446  void readyWrite();
447 
448 protected:
452  qint64 readData(char *data, qint64 maxlen, KSocketAddress *from) override;
453 
457  qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from) override;
458 
463  qint64 writeData(const char *data, qint64 len, const KSocketAddress *to) override;
464 
469  void setState(SocketState state);
470 
480  virtual void stateChanging(SocketState newState);
481 
486  void copyError();
487 
488 private:
490  KClientSocketBase &operator=(const KClientSocketBase &);
491 
492  KClientSocketBasePrivate *const d;
493 };
494 
495 } // namespace KNetwork
496 
497 #endif
Abstract class for active sockets.
Definition: k3socketbase.h:460
One resolution entry.
Definition: k3resolver.h:72
Name and service resolution class.
Definition: k3resolver.h:312
A generic socket address.
Name and service resolution results.
Definition: k3resolver.h:212
A namespace to store all networking-related (socket) classes.
int open(const QString &pathname, int flags, mode_t mode=0)
replacement for open()/::open64() to handle filenames in a platform independent way ...
Definition: kde_file.h:199
Abstract client socket class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 23:00:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.