• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
  • network
tdesocketbase.h
1 /*
2  * Copyright (C) 2003,2005 Thiago Macieira <thiago.macieira@kdemail.net>
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 TDESOCKETBASE_H
57 #define TDESOCKETBASE_H
58 
59 #include <tqiodevice.h>
60 #include <tqstring.h>
61 
62 #include "tdesocketaddress.h"
63 #include <tdelibs_export.h>
64 
65 /*
66  * This is extending QIODevice's error codes
67  *
68  * According to tqiodevice.h, the last error is IO_UnspecifiedError
69  * These errors will never occur in functions declared in QIODevice
70  * (except open, but you shouldn't call open)
71  */
72 #define IO_ListenError (IO_UnspecifiedError+1)
73 #define IO_AcceptError (IO_UnspecifiedError+2)
74 #define IO_LookupError (IO_UnspecifiedError+3)
75 #define IO_SocketCreateError (IO_UnspecifiedError+4)
76 #define IO_BindError (IO_UnspecifiedError+5)
77 
78 class TQMutex;
79 
80 namespace KNetwork {
81 
82 class KResolverEntry;
83 class TDESocketDevice;
84 
85 class TDESocketBasePrivate;
97 class TDECORE_EXPORT TDESocketBase
98 {
99 public:
118  enum SocketOptions
119  {
120  Blocking = 0x01,
121  AddressReuseable = 0x02,
122  IPv6Only = 0x04,
123  Keepalive = 0x08,
124  Broadcast = 0x10
125  };
126 
152  enum SocketError
153  {
154  NoError = 0,
155  LookupFailure,
156  AddressInUse,
157  AlreadyCreated,
158  AlreadyBound,
159  AlreadyConnected,
160  NotConnected,
161  NotBound,
162  NotCreated,
163  WouldBlock,
164  ConnectionRefused,
165  ConnectionTimedOut,
166  InProgress,
167  NetFailure,
168  NotSupported,
169  Timeout,
170  UnknownError,
171  RemotelyDisconnected
172  };
173 
174 public:
178  TDESocketBase();
179 
183  virtual ~TDESocketBase();
184 
185  /*
186  * The following functions are shared by all descended classes and will have
187  * to be reimplemented.
188  */
189 
190 protected:
204  virtual bool setSocketOptions(int opts);
205 
215  virtual int socketOptions() const;
216 
217 public:
233  virtual bool setBlocking(bool enable);
234 
241  bool blocking() const;
242 
257  virtual bool setAddressReuseable(bool enable);
258 
265  bool addressReuseable() const;
266 
282  virtual bool setIPv6Only(bool enable);
283 
290  bool isIPv6Only() const;
291 
303  virtual bool setBroadcast(bool enable);
304 
311  bool broadcast() const;
312 
319  TDESocketDevice* socketDevice() const;
320 
334  virtual void setSocketDevice(TDESocketDevice* device);
335 
357  int setRequestedCapabilities(int add, int remove = 0);
358 
359 protected:
364  bool hasDevice() const;
365 
371  void setError(SocketError error);
372 
373 public:
378  SocketError error() const;
379 
383  inline TQString errorString() const
384  { return errorString(error()); }
385 
401  TQMutex* mutex() const;
402 
403 public:
409  static TQString errorString(SocketError code);
410 
419  static bool isFatalError(int code);
420 
421 private:
424  void unsetSocketDevice();
425 
426  TDESocketBase(const TDESocketBase&);
427  TDESocketBase& operator =(const TDESocketBase&);
428 
429  TDESocketBasePrivate *d;
430 
431  friend class TDESocketDevice;
432 };
433 
443 class TDECORE_EXPORT KActiveSocketBase: public TQIODevice, virtual public TDESocketBase
444 {
445 public:
449  KActiveSocketBase();
450 
454  virtual ~KActiveSocketBase();
455 
466  virtual bool bind(const KResolverEntry& address) = 0;
467 
484  virtual bool connect(const KResolverEntry& address) = 0;
485 
501  virtual bool disconnect() = 0;
502 
507 #ifdef USE_QT4
508  virtual qint64 size() const
509 #else // USE_QT4
510  virtual Offset size() const
511 #endif // USE_QT4
512  { return 0; }
513 
518  virtual Offset at() const
519  { return 0; }
520 
525  virtual bool at(Offset)
526  { return false; }
527 
532  virtual bool atEnd() const
533  { return true; }
534 
539 #ifdef USE_QT3
540  virtual TQ_LONG bytesAvailable() const = 0;
541 #endif
542 #ifdef USE_QT4
543  virtual qint64 bytesAvailable() const = 0;
544 #endif
545 
557  virtual TQ_LONG waitForMore(int msecs, bool *timeout = 0L) = 0;
558 
565  virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG len) = 0;
566 
578  virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen, TDESocketAddress& from) = 0;
579 
591  virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen) = 0;
592 
605  virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen, TDESocketAddress& from) = 0;
606 
613  virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len) = 0;
614 
626  virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len, const TDESocketAddress& to) = 0;
627 
632  virtual int getch();
633 
638  virtual int putch(int ch);
639 
644  virtual int ungetch(int)
645  { return -1; }
646 
650  virtual TDESocketAddress localAddress() const = 0;
651 
657  virtual TDESocketAddress peerAddress() const = 0;
658 
659  // FIXME KDE 4.0:
660  // enable this function
661 #if 0
662 
665  virtual TDESocketAddress externalAddress() const = 0;
666 #endif
667 
668 protected:
675  void setError(int status, SocketError error);
676 
680  void resetError();
681 };
682 
692 class TDECORE_EXPORT KPassiveSocketBase: virtual public TDESocketBase
693 {
694 public:
698  KPassiveSocketBase();
699 
703  virtual ~KPassiveSocketBase();
704 
715  virtual bool bind(const KResolverEntry& address) = 0;
716 
731  virtual bool listen(int backlog) = 0;
732 
737  virtual void close() = 0;
738 
752  virtual KActiveSocketBase* accept() = 0;
753 
757  virtual TDESocketAddress localAddress() const = 0;
758 
762  virtual TDESocketAddress externalAddress() const = 0;
763 
764 private:
765  KPassiveSocketBase(const KPassiveSocketBase&);
766  KPassiveSocketBase& operator = (const KPassiveSocketBase&);
767 };
768 
769 } // namespace KNetwork
770 
771 #endif
KNetwork::TDESocketAddress
A generic socket address.
Definition: tdesocketaddress.h:423
KNetwork::KActiveSocketBase::atEnd
virtual bool atEnd() const
This call is not supported on sockets.
Definition: tdesocketbase.h:532
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: tdesocketbase.h:443
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:66
KNetwork::TDESocketDevice
Low-level socket functionality.
Definition: tdesocketdevice.h:50
KNetwork
A namespace to store all networking-related (socket) classes.
Definition: kbufferedsocket.h:36
KNetwork::KActiveSocketBase::at
virtual Offset at() const
This call is not supported on sockets.
Definition: tdesocketbase.h:518
KNetwork::KActiveSocketBase::size
virtual Offset size() const
This call is not supported on sockets.
Definition: tdesocketbase.h:510
KNetwork::KActiveSocketBase::ungetch
virtual int ungetch(int)
This call is not supported on sockets.
Definition: tdesocketbase.h:644
KNetwork::KActiveSocketBase::at
virtual bool at(Offset)
This call is not supported on sockets.
Definition: tdesocketbase.h:525
KNetwork::TDESocketBase::SocketOptions
SocketOptions
Possible socket options.
Definition: tdesocketbase.h:118
KNetwork::TDESocketBase::SocketError
SocketError
Possible socket error codes.
Definition: tdesocketbase.h:152
KNetwork::TDESocketBase::errorString
TQString errorString() const
Returns the error string corresponding to this error condition.
Definition: tdesocketbase.h:383
KNetwork::TDESocketBase
Basic socket functionality.
Definition: tdesocketbase.h:97
KNetwork::KPassiveSocketBase
Abstract base class for passive sockets.
Definition: tdesocketbase.h:692

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.