• 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_OS_UNIX
26
27#include <tqobject.h>
28#include <sys/types.h>
29// we define STRICT_ANSI to get rid of some warnings in glibc
30#ifndef __STRICT_ANSI__
31#define __STRICT_ANSI__
32#define _WE_DEFINED_IT_
33#endif
34#include <sys/socket.h>
35#ifdef _WE_DEFINED_IT_
36#undef __STRICT_ANSI__
37#undef _WE_DEFINED_IT_
38#endif
39
40#include <sys/un.h>
41
42#include <netinet/in.h>
43class TQSocketNotifier;
44
45#ifdef KSOCK_NO_BROKEN
46// This is here for compatibility with old applications still using the constants
47// Never use them in new programs
48
49// Here are a whole bunch of hackish macros that allow one to
50// get at the correct member of ksockaddr_in
51// But since ksockaddr_in is IPv4-only, and deprecated...
52
53typedef sockaddr_in ksockaddr_in;
54#define get_sin_addr(x) x.sin_addr
55#define get_sin_port(x) x.sin_port
56#define get_sin_family(x) x.sin_family
57#define get_sin_paddr(x) x->sin_addr
58#define get_sin_pport(x) x->sin_port
59#define get_sin_pfamily(x) x->sin_family
60#endif
61
62#define KSOCK_DEFAULT_DOMAIN PF_INET
63
64class TDESocketPrivate;
65class TDEServerSocketPrivate;
66
87class TDECORE_EXPORT TDESocket : public TQObject
88{
89 TQ_OBJECT
90public:
95 TDESocket( int _sock ) TDE_DEPRECATED;
102 TDESocket( const char *_host, unsigned short int _port, int timeOut = 30) TDE_DEPRECATED;
103
108 TDESocket( const char * _path ) TDE_DEPRECATED;
109
113 virtual ~TDESocket();
114
119 int socket() const { return sock; }
120
129 void enableRead( bool enable );
130
142 void enableWrite( bool enable );
143
144#ifdef KSOCK_NO_BROKEN
145 // BCI: remove in libtdecore.so.4
153 unsigned long ipv4_addr() TDE_DEPRECATED;
154
155 // BCI: remove in libtdecore.so.4
161 static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) TDE_DEPRECATED;
162#endif
163
164signals:
172 void readEvent( TDESocket *s );
173
185 void writeEvent( TDESocket *s );
186
191 void closeEvent( TDESocket *s );
192
193public slots:
201 void slotWrite( int x);
202
210 void slotRead( int x );
211
212protected:
213 bool connect( const TQString& _host, unsigned short int _port, int timeout = 0 );
214 bool connect( const char *_path );
215
216 /******************************************************
217 * The file descriptor for this socket. sock may be -1.
218 * This indicates that it is not connected.
219 */
220 int sock;
221
222private:
223 TDESocket(const TDESocket&);
224 TDESocket& operator=(const TDESocket&);
225
226 TDESocketPrivate *d;
227
228};
229
230
250class TDECORE_EXPORT TDEServerSocket : public TQObject
251{
252 TQ_OBJECT
253public:
261 TDEServerSocket( unsigned short int _port, bool _bind = true );
262
270 TDEServerSocket( const char *_path, bool _bind = true);
271
275 virtual ~TDEServerSocket();
276
286 bool bindAndListen(bool suppressFailureMessages = false);
287
293 int socket() const { return sock; }
294
299 unsigned short int port();
300
301#ifdef KSOCK_NO_BROKEN
302 // BCI: remove in libtdecore.so.4
309 unsigned long ipv4_addr();
310#endif
311
312public slots:
316 virtual void slotAccept( int ); // why is this virtual?
317
318signals:
328 void accepted( TDESocket*s );
329
330protected:
331 bool init( unsigned short int );
332 bool init( const char *_path );
333
338 int sock;
339
340private:
341 // HACK
342#ifdef TDESOCKET_BINARY_COMPAT_HACK
343 TDE_EXPORT bool bindAndListen();
344#endif // TDESOCKET_BINARY_COMPAT_HACK
345
346 TDEServerSocket(const TDEServerSocket&);
347 TDEServerSocket& operator=(const TDEServerSocket&);
348
349 TDEServerSocketPrivate *d;
350};
351
352#endif //Q_OS_UNIX
353
354#endif
TDEServerSocket
Monitors a port for incoming TCP/IP connections.
Definition: ksock.h:251
TDEServerSocket::sock
int sock
The file descriptor for this socket.
Definition: ksock.h:338
TDEServerSocket::socket
int socket() const
Returns the file descriptor associated with the socket.
Definition: ksock.h:293
TDEServerSocket::accepted
void accepted(TDESocket *s)
A connection has been accepted.
TDESocket
A TCP/IP client socket.
Definition: ksock.h:88
TDESocket::socket
int socket() const
Returns a file descriptor for this socket.
Definition: ksock.h:119
TDESocket::closeEvent
void closeEvent(TDESocket *s)
Raised when the connection is broken.
TDESocket::readEvent
void readEvent(TDESocket *s)
Data has arrived for reading.
TDESocket::writeEvent
void writeEvent(TDESocket *s)
Socket is ready for writing.

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.