KDELibs4Support

k3socketbase.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 /*
26  * Even before our #ifdef, clean up the namespace
27  */
28 #ifdef socket
29 #undef socket
30 #endif
31 
32 #ifdef bind
33 #undef bind
34 #endif
35 
36 #ifdef listen
37 #undef listen
38 #endif
39 
40 #ifdef connect
41 #undef connect
42 #endif
43 
44 #ifdef accept
45 #undef accept
46 #endif
47 
48 #ifdef getpeername
49 #undef getpeername
50 #endif
51 
52 #ifdef getsockname
53 #undef getsockname
54 #endif
55 
56 #ifndef KSOCKETBASE_H
57 #define KSOCKETBASE_H
58 
59 #include <QIODevice>
60 #include <QString>
61 
62 #include <kdelibs4support_export.h>
63 #include "k3socketaddress.h"
64 
65 class QMutex;
66 
67 namespace KNetwork
68 {
69 
70 class KResolverEntry;
71 class KSocketDevice;
72 
73 class KSocketBasePrivate;
74 /** @class KSocketBase k3socketbase.h k3socketbase.h
75  * @brief Basic socket functionality.
76  *
77  * This class provides the basic socket functionlity for descended classes.
78  * Socket classes are thread-safe and provide a recursive mutex should it be
79  * needed.
80  *
81  * @note This class is abstract.
82  *
83  * @author Thiago Macieira <[email protected]>
84  * @deprecated Use KSocketFactory or KLocalSocket instead
85  */
86 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KSocketBase
87 {
88 public:
89  /**
90  * Possible socket options.
91  *
92  * These are the options that may be set on a socket:
93  * - Blocking: whether the socket shall operate in blocking
94  * or non-blocking mode. This flag defaults to on.
95  * See setBlocking().
96  * - AddressReusable: whether the address used by this socket will
97  * be available for reuse by other sockets. This flag defaults to off.
98  * See setAddressReuseable().
99  * - IPv6Only: whether an IPv6 socket will accept IPv4 connections
100  * through a mapped address. This flag defaults to off.
101  * See setIPv6Only().
102  * - KeepAlive: whether TCP should send keepalive probes when a connection
103  * has gone idle for far too long.
104  * - Broadcast: whether this socket is allowed to send broadcast packets
105  * and will receive packets sent to broadcast.
106  * - NoDelay: disable the Nagle algorithm for socket types that support
107  * it.
108  */
110  Blocking = 0x01,
111  AddressReuseable = 0x02,
112  IPv6Only = 0x04,
113  Keepalive = 0x08,
114  Broadcast = 0x10,
115  NoDelay = 0x20
116  };
117 
118  /**
119  * Possible socket error codes.
120  *
121  * This is a list of possible error conditions that socket classes may
122  * be expected to find.
123  *
124  * - NoError: no error has been detected
125  * - LookupFailure: if a name lookup has failed
126  * - AddressInUse: address is already in use
127  * - AlreadyBound: cannot bind again
128  * - AlreadyCreated: cannot recreate the socket
129  * - NotBound: operation required socket to be bound and it isn't
130  * - NotCreated: operation required socket to exist and it doesn't
131  * - WouldBlock: requested I/O operation would block
132  * - ConnectionRefused: connection actively refused
133  * - ConnectionTimedOut: connection timed out
134  * - InProgress: operation (connection) is already in progress
135  * - NetFailure: a network failure occurred (no route, host down, host unreachable or similar)
136  * - NotSupported: requested operation is not supported
137  * - Timeout: a timed operation timed out
138  * - UnknownError: an unknown/unexpected error has happened
139  * - RemotelyDisconnected: when a connection is disconnected by the other end (since 3.4)
140  *
141  * @sa error, errorString
142  */
143  enum SocketError {
144  NoError = 0,
145  LookupFailure,
146  AddressInUse,
147  AlreadyCreated,
148  AlreadyBound,
149  AlreadyConnected,
150  NotConnected,
151  NotBound,
152  NotCreated,
153  WouldBlock,
154  ConnectionRefused,
155  ConnectionTimedOut,
156  InProgress,
157  NetFailure,
158  NotSupported,
159  Timeout,
160  UnknownError,
161  RemotelyDisconnected
162  };
163 
164 public:
165  /**
166  * Default constructor.
167  */
168  KSocketBase();
169 
170  /**
171  * Destructor.
172  */
173  virtual ~KSocketBase();
174 
175  /*
176  * The following functions are shared by all descended classes and will have
177  * to be reimplemented.
178  */
179 
180 protected:
181  /**
182  * Set the given socket options.
183  *
184  * The default implementation does nothing but store the mask internally.
185  * Descended classes must override this function to achieve functionality and
186  * must also call this implementation.
187  *
188  * @param opts a mask of SocketOptions or-ed bits of options to set
189  * or unset
190  * @returns true on success
191  * @note this function sets the options corresponding to the bits enabled in @p opts
192  * but will also unset the optiosn corresponding to the bits not set.
193  */
194  virtual bool setSocketOptions(int opts);
195 
196  /**
197  * Retrieves the socket options that have been set.
198  *
199  * The default implementation just retrieves the mask from an internal variable.
200  * Descended classes may choose to override this function to read the values
201  * from the operating system.
202  *
203  * @returns the mask of the options set
204  */
205  virtual int socketOptions() const;
206 
207 public:
208  /**
209  * Sets this socket's blocking mode.
210  *
211  * In blocking operation, all I/O functions are susceptible to blocking --
212  * i.e., will not return unless the I/O can be satisfied. In non-blocking
213  * operation, if the I/O would block, the function will return an error
214  * and set the corresponding error code.
215  *
216  * The default implementation toggles the Blocking flag with the current
217  * socket options and calls setSocketOptions().
218  *
219  * @param enable whether to set this socket to blocking mode
220  * @returns whether setting this value was successful; it is NOT the
221  * final blocking mode.
222  */
223  virtual bool setBlocking(bool enable);
224 
225  /**
226  * Retrieves this socket's blocking mode.
227  *
228  * @returns true if this socket is/will be operated in blocking mode,
229  * false if non-blocking.
230  */
231  bool blocking() const;
232 
233  /**
234  * Sets this socket's address reuseable flag.
235  *
236  * When the address reuseable flag is active, the address used by
237  * this socket is left reuseable for other sockets to bind. If
238  * the flag is not active, no other sockets may reuse the same
239  * address.
240  *
241  * The default implementation toggles the AddressReuseable flag with the current
242  * socket options and calls setSocketOptions().
243  *
244  * @param enable whether to set the flag on or off
245  * @returns true if setting this flag was successful
246  */
247  virtual bool setAddressReuseable(bool enable);
248 
249  /**
250  * Retrieves this socket's address reuseability flag.
251  *
252  * @returns true if this socket's address can be reused,
253  * false if it can't.
254  */
255  bool addressReuseable() const;
256 
257  /**
258  * Sets this socket's IPv6 Only flag.
259  *
260  * When this flag is on, an IPv6 socket will only accept, connect, send to or
261  * receive from IPv6 addresses. When it is off, it will also talk to
262  * IPv4 addresses through v4-mapped addresses.
263  *
264  * This option has no effect on non-IPv6 sockets.
265  *
266  * The default implementation toggles the IPv6Only flag with the current
267  * socket options and calls setSocketOptions().
268  *
269  * @param enable whether to set the flag on or off
270  * @returns true if setting this flag was successful
271  */
272  virtual bool setIPv6Only(bool enable);
273 
274  /**
275  * Retrieves this socket's IPv6 Only flag.
276  *
277  * @returns true if this socket will ignore IPv4-compatible and IPv4-mapped
278  * addresses, false if it will accept them.
279  */
280  bool isIPv6Only() const;
281 
282  /**
283  * Sets this socket Broadcast flag.
284  *
285  * Datagram-oriented sockets cannot normally send packets to broadcast
286  * addresses, nor will they receive packets that were sent to a broadcast
287  * address. To do so, you need to enable the Broadcast flag.
288  *
289  * This option has no effect on stream-oriented sockets.
290  *
291  * @returns true if setting this flag was successful.
292  */
293  virtual bool setBroadcast(bool enable);
294 
295  /**
296  * Retrieves this socket's Broadcast flag.
297  *
298  * @returns true if this socket can send and receive broadcast packets,
299  * false if it can't.
300  */
301  bool broadcast() const;
302 
303  /**
304  * Sets this socket's NoDelay flag.
305  *
306  * Stream-oriented protocols, like TCP, have an internal algorithm
307  * (called Nagle's algorithm) that collects data in a buffer so that
308  * the transmission doesn't occur after every single write operation.
309  * The side-effect is that the transmission of short messages is
310  * delayed.
311  *
312  * Setting NoDelay to 'true' will disable this algorithm.
313  *
314  * @returns true if setting this flag was successful.
315  */
316  virtual bool setNoDelay(bool enable);
317 
318  /**
319  * Retrieves this socket's NoDelay flag.
320  *
321  * @returns true if this socket's Nagle algorithm is disabled.
322  */
323  bool noDelay() const;
324 
325  /**
326  * Retrieves the socket implementation used on this socket.
327  *
328  * This function creates the device if none has been set
329  * using the default factory.
330  */
331  KSocketDevice *socketDevice() const;
332 
333  /**
334  * Sets the socket implementation to be used on this socket.
335  *
336  * Note: it is an error to set this if the socket device has
337  * already been set once.
338  *
339  * This function is provided virtual so that derived classes can catch
340  * the setting of a device and properly set their own states and internal
341  * variables. The parent class must be called.
342  *
343  * This function is called by socketDevice() above when the socket is
344  * first created.
345  */
346  virtual void setSocketDevice(KSocketDevice *device);
347 
348  /**
349  * Sets the internally requested capabilities for a socket device.
350  *
351  * Most socket classes can use any back-end implementation. However, a few
352  * may require specific capabilities not provided in the default
353  * implementation. By using this function, derived classes can request
354  * that a backend with those capabilities be created when necessary.
355  *
356  * For the possible flags, see KSocketDevice::Capabilities. However, note
357  * that only the Can* flags make sense in this context.
358  *
359  * @note Since socketDevice must always return a valid backend object, it
360  * is is possible that the created device does not conform to all
361  * requirements requested. Implementations sensitive to this fact
362  * should test the object returned by socketDevice() (through
363  * KSocketDevice::capabilities(), for instance) the availability.
364  *
365  * @param add mask of KSocketDevice::Capabilities to add
366  * @param remove mask of bits to remove from the requirements
367  * @return the current mask of requested capabilities
368  */
369  int setRequestedCapabilities(int add, int remove = 0);
370 
371 protected:
372  /**
373  * Returns true if the socket device has been initialised in this
374  * object, either by calling socketDevice() or setSocketDevice()
375  */
376  bool hasDevice() const;
377 
378  /**
379  * Sets the socket's error code.
380  *
381  * @param error the error code
382  */
383  void setError(SocketError error);
384 
385  /**
386  * Resets the socket error code and the I/O Device's status.
387  */
388  void resetError();
389 
390 public:
391  /**
392  * Retrieves the socket error code.
393  * @sa errorString
394  */
395  SocketError error() const;
396 
397  /**
398  * Returns the error string corresponding to this error condition.
399  */
400  QString errorString() const;
401 
402  /**
403  * Returns the internal mutex for this class.
404  *
405  * Note on multithreaded use of sockets:
406  * the socket classes are thread-safe by design, but you should be aware of
407  * problems regarding socket creation, connection and destruction in
408  * multi-threaded programs. The classes are guaranteed to work while
409  * the socket exists, but it's not wise to call connect in multiple
410  * threads.
411  *
412  * Also, this mutex must be unlocked before the object is destroyed, which
413  * means you cannot use it to guard against other threads accessing the object
414  * while destroying it. You must ensure there are no further references to this
415  * object when deleting it.
416  */
417  QMutex *mutex() const;
418 
419 public:
420  /**
421  * Returns the string describing the given error code, i18n'ed.
422  *
423  * @param code the error code
424  */
425  static QString errorString(SocketError code);
426 
427  /**
428  * Returns true if the given error code is a fatal one, false
429  * otherwise. The parameter here is of type int so that
430  * casting isn't necessary when using the parameter to signal
431  * QClientSocketBase::gotError.
432  *
433  * @param code the code to test
434  */
435  static bool isFatalError(int code);
436 
437 private:
438  /// @internal
439  /// called by KSocketDevice
440  void unsetSocketDevice();
441 
442  KSocketBase(const KSocketBase &);
443  KSocketBase &operator =(const KSocketBase &);
444 
445  KSocketBasePrivate *const d;
446 
447  friend class KSocketDevice;
448 };
449 
450 /**
451  * @class KActiveSocketBase k3socketbase.h k3socketbase.h
452  * @brief Abstract class for active sockets
453  *
454  * This class provides the standard interfaces for active sockets, i.e.,
455  * sockets that are used to connect to external addresses.
456  *
457  * @author Thiago Macieira <[email protected]>
458  * @deprecated Use KSocketFactory or KLocalSocket instead
459  */
460 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KActiveSocketBase: public QIODevice, virtual public KSocketBase
461 {
462  Q_OBJECT
463 public:
464  /**
465  * Constructor.
466  */
467  KActiveSocketBase(QObject *parent);
468 
469  /**
470  * Destructor.
471  */
472  ~KActiveSocketBase() override;
473 
474  /**
475  * Unshadow errorString from QIODevice
476  */
477  QString errorString() const;
478 
479  /**
480  * @reimp
481  */
482  void setSocketDevice(KSocketDevice *device) override;
483 
484  /**
485  * Reimplemented from QIODevice.
486  */
487  bool open(OpenMode mode) override;
488 
489  /**
490  * Binds this socket to the given address.
491  *
492  * The socket will be constructed with the address family,
493  * socket type and protocol as those given in the
494  * @p address object.
495  *
496  * @param address the address to bind to
497  * @returns true if the binding was successful, false otherwise
498  */
499  virtual bool bind(const KResolverEntry &address) = 0;
500 
501  /**
502  * Connect to a remote host.
503  *
504  * This will make this socket try to connect to the remote host.
505  * If the socket is not yet created, it will be created using the
506  * address family, socket type and protocol specified in the
507  * @p address object.
508  *
509  * If this function returns with error InProgress, calling it
510  * again with the same address after a time will cause it to test
511  * if the connection has succeeded in the mean time.
512  *
513  * @param address the address to connect to
514  * @param mode mode for connection, from QIODevice
515  *
516  * @returns true if the connection was successful or has been successfully
517  * queued; false if an error occurred.
518  */
519  virtual bool connect(const KResolverEntry &address,
520  OpenMode mode = ReadWrite) = 0;
521 
522  /**
523  * Disconnects this socket from a connection, if possible.
524  *
525  * If this socket was connected to an endpoint, the connection
526  * is severed, but the socket is not closed. If the socket wasn't
527  * connected, this function does nothing.
528  *
529  * If the socket hadn't yet been created, this function does nothing
530  * either.
531  *
532  * Not all socket types can disconnect. Most notably, only
533  * connectionless datagram protocols such as UDP support this operation.
534  *
535  * @return true if the socket is now disconnected or false on error.
536  */
537  virtual bool disconnect() = 0;
538 
539  /**
540  * Sockets are sequential
541  */
542  bool isSequential() const override;
543 
544  /**
545  * This call is not supported on sockets. Reimplemented from QIODevice.
546  * This will always return 0.
547  */
548  qint64 size() const override;
549 
550  /**
551  * This call is not supported on sockets. Reimplemented from QIODevice.
552  * This will always return 0.
553  */
554  qint64 pos() const override;
555 
556  /**
557  * This call is not supported on sockets. Reimplemented from QIODevice.
558  * This will always return false.
559  */
560  bool seek(qint64) override;
561 
562  /**
563  * This call is not supported on sockets. Reimplemented from QIODevice.
564  * This will always return true.
565  */
566  bool atEnd() const override;
567 
568  /**
569  * Reads data from the socket.
570  *
571  * Reimplemented from QIODevice. See QIODevice::read for
572  * more information.
573  */
574  qint64 read(char *data, qint64 maxlen);
575 
576  /**
577  * Reads data from the socket.
578  *
579  * Reimplemented from QIODevice. See QIODevice::read for
580  * more information.
581  */
582  QByteArray read(qint64 len);
583 
584  /** @overload
585  * Receives data and the source address.
586  *
587  * This call will read data in the socket and will also
588  * place the sender's address in @p from object.
589  *
590  * @param data where to write the read data to
591  * @param maxlen the maximum number of bytes to read
592  * @param from the address of the sender will be stored here
593  * @returns the actual number of bytes read
594  */
595  qint64 read(char *data, qint64 maxlen, KSocketAddress &from);
596 
597  /**
598  * Peeks the data in the socket and the source address.
599  *
600  * This call will allow you to peek the data to be received without actually
601  * receiving it -- that is, it will be available for further peekings and
602  * for the next read call.
603  *
604  * @param data where to write the peeked data to
605  * @param maxlen the maximum number of bytes to peek
606  * @returns the actual number of bytes copied into @p data
607  */
608  qint64 peek(char *data, qint64 maxlen);
609 
610  /**
611  * @overload
612  * Peeks the data in the socket and the source address.
613  *
614  * This call will allow you to peek the data to be received without actually
615  * receiving it -- that is, it will be available for further peekings and
616  * for the next read call.
617  *
618  * @param data where to write the peeked data to
619  * @param maxlen the maximum number of bytes to peek
620  * @param from the address of the sender will be stored here
621  * @returns the actual number of bytes copied into @p data
622  */
623  qint64 peek(char *data, qint64 maxlen, KSocketAddress &from);
624 
625  /**
626  * Writes the given data to the socket.
627  *
628  * Reimplemented from QIODevice. See QIODevice::write for
629  * more information.
630  */
631  qint64 write(const char *data, qint64 len);
632 
633  /**
634  * Writes the given data to the socket.
635  *
636  * Reimplemented from QIODevice. See QIODevice::write for
637  * more information.
638  */
639  qint64 write(const QByteArray &data);
640 
641  /** @overload
642  * Writes the given data to the destination address.
643  *
644  * Note that not all socket connections allow sending data to different
645  * addresses than the one the socket is connected to.
646  *
647  * @param data the data to write
648  * @param len the length of the data
649  * @param to the address to send to
650  * @returns the number of bytes actually sent
651  */
652  qint64 write(const char *data, qint64 len, const KSocketAddress &to);
653 
654  /**
655  * Waits up to @p msecs for more data to be available on this socket.
656  *
657  * If msecs is -1, this call will block indefinetely until more data
658  * is indeed available; if it's 0, this function returns immediately.
659  *
660  * If @p timeout is not NULL, this function will set it to indicate
661  * if a timeout occurred.
662  *
663  * @returns the number of bytes available
664  */
665  virtual qint64 waitForMore(int msecs, bool *timeout = nullptr) = 0;
666 
667  /**
668  * This call is not supported on sockets. Reimplemented from QIODevice.
669  */
670  void ungetChar(char);
671 
672  /**
673  * Returns this socket's local address.
674  */
675  virtual KSocketAddress localAddress() const = 0;
676 
677  /**
678  * Return this socket's peer address, if we are connected.
679  * If the address cannot be retrieved, the returned object will contain
680  * an invalid address.
681  */
682  virtual KSocketAddress peerAddress() const = 0;
683 
684  // FIXME KDE 4.0:
685  // enable this function
686 #if 0
687  /**
688  * Returns this socket's externally-visible address, if known.
689  */
690  virtual KSocketAddress externalAddress() const = 0;
691 #endif
692 
693 protected:
694  /**
695  * Reads data from the socket.
696  *
697  * Reimplemented from QIODevice. See QIODevice::readData for
698  * more information.
699  */
700  qint64 readData(char *data, qint64 len) override;
701 
702  /** @overload
703  * Receives data and the source address.
704  *
705  * This call will read data in the socket and will also
706  * place the sender's address in @p from object.
707  *
708  * @param data where to write the read data to
709  * @param maxlen the maximum number of bytes to read
710  * @param from the address of the sender will be stored here
711  * @returns the actual number of bytes read
712  */
713  virtual qint64 readData(char *data, qint64 maxlen, KSocketAddress *from) = 0;
714 
715  /**
716  * Peeks the data in the socket and the source address.
717  *
718  * This call will allow you to peek the data to be received without actually
719  * receiving it -- that is, it will be available for further peekings and
720  * for the next read call.
721  *
722  * @param data where to write the peeked data to
723  * @param maxlen the maximum number of bytes to peek
724  * @param from the address of the sender will be stored here
725  * @returns the actual number of bytes copied into @p data
726  */
727  virtual qint64 peekData(char *data, qint64 maxlen, KSocketAddress *from) = 0;
728 
729  /**
730  * Writes the given data to the socket.
731  *
732  * Reimplemented from QIODevice. See QIODevice::writeData for
733  * more information.
734  */
735  qint64 writeData(const char *data, qint64 len) override;
736 
737  /** @overload
738  * Writes the given data to the destination address.
739  *
740  * Note that not all socket connections allow sending data to different
741  * addresses than the one the socket is connected to.
742  *
743  * @param data the data to write
744  * @param len the length of the data
745  * @param to the address to send to
746  * @returns the number of bytes actually sent
747  */
748  virtual qint64 writeData(const char *data, qint64 len, const KSocketAddress *to) = 0;
749 
750  /**
751  * Sets the socket's error code.
752  *
753  * @param error the error code
754  */
755  void setError(SocketError error);
756 
757  /**
758  * Resets the socket error code and the I/O Device's status.
759  */
760  void resetError();
761 };
762 
763 /**
764  * @class KPassiveSocketBase k3socketbase.h k3socketbase.h
765  * @brief Abstract base class for passive sockets.
766  *
767  * This socket provides the initial functionality for passive sockets,
768  * i.e., sockets that accept incoming connections.
769  *
770  * @author Thiago Macieira <[email protected]>
771  * @deprecated Use KSocketFactory or KLocalSocket instead
772  */
773 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KPassiveSocketBase: virtual public KSocketBase
774 {
775 public:
776  /**
777  * Constructor
778  */
780 
781  /**
782  * Destructor
783  */
784  ~KPassiveSocketBase() override;
785 
786  /**
787  * Binds this socket to the given address.
788  *
789  * The socket will be constructed with the address family,
790  * socket type and protocol as those given in the
791  * @p address object.
792  *
793  * @param address the address to bind to
794  * @returns true if the binding was successful, false otherwise
795  */
796  virtual bool bind(const KResolverEntry &address) = 0;
797 
798  /**
799  * Puts this socket into listening mode.
800  *
801  * Placing a socket in listening mode means that it will
802  * be allowed to receive incoming connections from
803  * remote hosts.
804  *
805  * Note that some socket types or protocols cannot be
806  * put in listening mode.
807  *
808  * @param backlog the number of accepted connections to
809  * hold before starting to refuse
810  * @returns true if the socket is now in listening mode
811  */
812  virtual bool listen(int backlog) = 0;
813 
814  /**
815  * Closes this socket. All resources used are freed. Note that closing
816  * a passive socket does not close the connections accepted with it.
817  */
818  virtual void close() = 0;
819 
820  /**
821  * Accepts a new incoming connection.
822  *
823  * If this socket was in listening mode, you can call this
824  * function to accept an incoming connection.
825  *
826  * If this function cannot accept a new connection (either
827  * because it is not listening for one or because the operation
828  * would block), it will return NULL.
829  *
830  * Also note that descended classes will override this function
831  * to return specialized socket classes.
832  */
833  virtual KActiveSocketBase *accept() = 0;
834 
835  /**
836  * Returns this socket's local address.
837  */
838  virtual KSocketAddress localAddress() const = 0;
839 
840  /**
841  * Returns this socket's externally-visible address if known.
842  */
843  virtual KSocketAddress externalAddress() const = 0;
844 
845 private:
847  KPassiveSocketBase &operator = (const KPassiveSocketBase &);
848 };
849 
850 } // namespace KNetwork
851 
852 #endif
Abstract class for active sockets.
Definition: k3socketbase.h:460
One resolution entry.
Definition: k3resolver.h:72
A generic socket address.
A namespace to store all networking-related (socket) classes.
SocketError
Possible socket error codes.
Definition: k3socketbase.h:143
SocketOptions
Possible socket options.
Definition: k3socketbase.h:109
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
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-2021 The KDE developers.
Generated on Mon Mar 8 2021 22:58:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.