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

tdecore

  • tdecore
ksock.h
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 1997 Torben Weis (weis@kde.org)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifndef KSOCK_H
21 #define KSOCK_H
22 
23 #include "tdelibs_export.h"
24 
25 #ifdef Q_MOC_RUN
26 #define Q_OS_UNIX
27 #endif // Q_MOC_RUN
28 
29 #ifdef Q_OS_UNIX
30 
31 #include <tqobject.h>
32 #include <sys/types.h>
33 // we define STRICT_ANSI to get rid of some warnings in glibc
34 #ifndef __STRICT_ANSI__
35 #define __STRICT_ANSI__
36 #define _WE_DEFINED_IT_
37 #endif
38 #include <sys/socket.h>
39 #ifdef _WE_DEFINED_IT_
40 #undef __STRICT_ANSI__
41 #undef _WE_DEFINED_IT_
42 #endif
43 
44 #include <sys/un.h>
45 
46 #include <netinet/in.h>
47 class TQSocketNotifier;
48 
49 #ifdef KSOCK_NO_BROKEN
50 // This is here for compatibility with old applications still using the constants
51 // Never use them in new programs
52 
53 // Here are a whole bunch of hackish macros that allow one to
54 // get at the correct member of ksockaddr_in
55 // But since ksockaddr_in is IPv4-only, and deprecated...
56 
57 typedef sockaddr_in ksockaddr_in;
58 #define get_sin_addr(x) x.sin_addr
59 #define get_sin_port(x) x.sin_port
60 #define get_sin_family(x) x.sin_family
61 #define get_sin_paddr(x) x->sin_addr
62 #define get_sin_pport(x) x->sin_port
63 #define get_sin_pfamily(x) x->sin_family
64 #endif
65 
66 #define KSOCK_DEFAULT_DOMAIN PF_INET
67 
68 class TDESocketPrivate;
69 class TDEServerSocketPrivate;
70 
91 class TDECORE_EXPORT TDESocket : public TQObject
92 {
93  Q_OBJECT
94 public:
99  TDESocket( int _sock ) KDE_DEPRECATED;
106  TDESocket( const char *_host, unsigned short int _port, int timeOut = 30) KDE_DEPRECATED;
107 
112  TDESocket( const char * _path ) KDE_DEPRECATED;
113 
117  virtual ~TDESocket();
118 
123  int socket() const { return sock; }
124 
133  void enableRead( bool enable );
134 
146  void enableWrite( bool enable );
147 
148 #ifdef KSOCK_NO_BROKEN
149  // BCI: remove in libtdecore.so.4
157  unsigned long ipv4_addr() KDE_DEPRECATED;
158 
159  // BCI: remove in libtdecore.so.4
165  static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) KDE_DEPRECATED;
166 #endif
167 
168 signals:
176  void readEvent( TDESocket *s );
177 
189  void writeEvent( TDESocket *s );
190 
195  void closeEvent( TDESocket *s );
196 
197 public slots:
205  void slotWrite( int x);
206 
214  void slotRead( int x );
215 
216 protected:
217  bool connect( const TQString& _host, unsigned short int _port, int timeout = 0 );
218  bool connect( const char *_path );
219 
220  /******************************************************
221  * The file descriptor for this socket. sock may be -1.
222  * This indicates that it is not connected.
223  */
224  int sock;
225 
226 private:
227  TDESocket(const TDESocket&);
228  TDESocket& operator=(const TDESocket&);
229 
230  TDESocketPrivate *d;
231 
232 };
233 
234 
254 class TDECORE_EXPORT TDEServerSocket : public TQObject
255 {
256  Q_OBJECT
257 public:
265  TDEServerSocket( unsigned short int _port, bool _bind = true );
266 
274  TDEServerSocket( const char *_path, bool _bind = true);
275 
279  virtual ~TDEServerSocket();
280 
290  bool bindAndListen(bool suppressFailureMessages = false);
291 
297  int socket() const { return sock; }
298 
303  unsigned short int port();
304 
305 #ifdef KSOCK_NO_BROKEN
306  // BCI: remove in libtdecore.so.4
313  unsigned long ipv4_addr();
314 #endif
315 
316 public slots:
320  virtual void slotAccept( int ); // why is this virtual?
321 
322 signals:
332  void accepted( TDESocket*s );
333 
334 protected:
335  bool init( unsigned short int );
336  bool init( const char *_path );
337 
342  int sock;
343 
344 private:
345  // HACK
346 #ifdef TDESOCKET_BINARY_COMPAT_HACK
347  KDE_EXPORT bool bindAndListen();
348 #endif // TDESOCKET_BINARY_COMPAT_HACK
349 
350  TDEServerSocket(const TDEServerSocket&);
351  TDEServerSocket& operator=(const TDEServerSocket&);
352 
353  TDEServerSocketPrivate *d;
354 };
355 
356 #endif //Q_OS_UNIX
357 
358 #endif
TDEServerSocket
Monitors a port for incoming TCP/IP connections.
Definition: ksock.h:254
TDESocket
A TCP/IP client socket.
Definition: ksock.h:91
TDEServerSocket::sock
int sock
The file descriptor for this socket.
Definition: ksock.h:342
TDEServerSocket::socket
int socket() const
Returns the file descriptor associated with the socket.
Definition: ksock.h:297
TDESocket::socket
int socket() const
Returns a file descriptor for this socket.
Definition: ksock.h:123

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.