KDECore
ksock.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KSOCK_H
00021 #define KSOCK_H
00022
00023 #include "kdelibs_export.h"
00024
00025 #ifdef Q_OS_UNIX
00026
00027 #include <qobject.h>
00028 #include <sys/types.h>
00029
00030 #ifndef __STRICT_ANSI__
00031 #define __STRICT_ANSI__
00032 #define _WE_DEFINED_IT_
00033 #endif
00034 #include <sys/socket.h>
00035 #ifdef _WE_DEFINED_IT_
00036 #undef __STRICT_ANSI__
00037 #undef _WE_DEFINED_IT_
00038 #endif
00039
00040 #include <sys/un.h>
00041
00042 #include <netinet/in.h>
00043 class QSocketNotifier;
00044
00045 #ifdef KSOCK_NO_BROKEN
00046
00047
00048
00049
00050
00051
00052
00053 typedef sockaddr_in ksockaddr_in;
00054 #define get_sin_addr(x) x.sin_addr
00055 #define get_sin_port(x) x.sin_port
00056 #define get_sin_family(x) x.sin_family
00057 #define get_sin_paddr(x) x->sin_addr
00058 #define get_sin_pport(x) x->sin_port
00059 #define get_sin_pfamily(x) x->sin_family
00060 #endif
00061
00062 #define KSOCK_DEFAULT_DOMAIN PF_INET
00063
00064 class KSocketPrivate;
00065 class KServerSocketPrivate;
00066
00087 class KDECORE_EXPORT KSocket : public QObject
00088 {
00089 Q_OBJECT
00090 public:
00095 KSocket( int _sock ) KDE_DEPRECATED;
00102 KSocket( const char *_host, unsigned short int _port, int timeOut = 30) KDE_DEPRECATED;
00103
00108 KSocket( const char * _path ) KDE_DEPRECATED;
00109
00113 virtual ~KSocket();
00114
00119 int socket() const { return sock; }
00120
00129 void enableRead( bool enable );
00130
00142 void enableWrite( bool enable );
00143
00144 #ifdef KSOCK_NO_BROKEN
00145
00153 unsigned long ipv4_addr() KDE_DEPRECATED;
00154
00155
00161 static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) KDE_DEPRECATED;
00162 #endif
00163
00164 signals:
00172 void readEvent( KSocket *s );
00173
00185 void writeEvent( KSocket *s );
00186
00191 void closeEvent( KSocket *s );
00192
00193 public slots:
00201 void slotWrite( int x);
00202
00210 void slotRead( int x );
00211
00212 protected:
00213 bool connect( const QString& _host, unsigned short int _port, int timeout = 0 );
00214 bool connect( const char *_path );
00215
00216
00217
00218
00219
00220 int sock;
00221
00222 private:
00223 KSocket(const KSocket&);
00224 KSocket& operator=(const KSocket&);
00225
00226 KSocketPrivate *d;
00227
00228 };
00229
00230
00250 class KDECORE_EXPORT KServerSocket : public QObject
00251 {
00252 Q_OBJECT
00253 public:
00261 KServerSocket( unsigned short int _port, bool _bind = true );
00262
00270 KServerSocket( const char *_path, bool _bind = true);
00271
00275 virtual ~KServerSocket();
00276
00283 bool bindAndListen();
00284
00290 int socket() const { return sock; }
00291
00296 unsigned short int port();
00297
00298 #ifdef KSOCK_NO_BROKEN
00299
00306 unsigned long ipv4_addr();
00307 #endif
00308
00309 public slots:
00313 virtual void slotAccept( int );
00314
00315 signals:
00325 void accepted( KSocket*s );
00326
00327 protected:
00328 bool init( unsigned short int );
00329 bool init( const char *_path );
00330
00335 int sock;
00336
00337 private:
00338 KServerSocket(const KServerSocket&);
00339 KServerSocket& operator=(const KServerSocket&);
00340
00341 KServerSocketPrivate *d;
00342 };
00343
00344 #endif //Q_OS_UNIX
00345
00346 #endif