ksock.h
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
00088 class KDECORE_EXPORT KSocket : public QObject
00089 {
00090 Q_OBJECT
00091 public:
00096 KSocket( int _sock ) KDE_DEPRECATED;
00103 KSocket( const char *_host, unsigned short int _port, int timeOut = 30) KDE_DEPRECATED;
00104
00109 KSocket( const char * _path ) KDE_DEPRECATED;
00110
00114 virtual ~KSocket();
00115
00120 int socket() const { return sock; }
00121
00130 void enableRead( bool enable );
00131
00143 void enableWrite( bool enable );
00144
00145 #ifdef KSOCK_NO_BROKEN
00146
00154 unsigned long ipv4_addr() KDE_DEPRECATED;
00155
00156
00162 static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) KDE_DEPRECATED;
00163 #endif
00164
00165 signals:
00173 void readEvent( KSocket *s );
00174
00186 void writeEvent( KSocket *s );
00187
00192 void closeEvent( KSocket *s );
00193
00194 public slots:
00202 void slotWrite( int x);
00203
00211 void slotRead( int x );
00212
00213 protected:
00214 bool connect( const QString& _host, unsigned short int _port, int timeout = 0 );
00215 bool connect( const char *_path );
00216
00217
00218
00219
00220
00221 int sock;
00222
00223 private:
00224 KSocket(const KSocket&);
00225 KSocket& operator=(const KSocket&);
00226
00227 KSocketPrivate *d;
00228
00229 };
00230
00231
00252 class KDECORE_EXPORT KServerSocket : public QObject
00253 {
00254 Q_OBJECT
00255 public:
00263 KServerSocket( unsigned short int _port, bool _bind = true );
00264
00272 KServerSocket( const char *_path, bool _bind = true);
00273
00277 virtual ~KServerSocket();
00278
00285 bool bindAndListen();
00286
00292 int socket() const { return sock; }
00293
00298 unsigned short int port();
00299
00300 #ifdef KSOCK_NO_BROKEN
00301
00308 unsigned long ipv4_addr();
00309 #endif
00310
00311 public slots:
00315 virtual void slotAccept( int );
00316
00317 signals:
00327 void accepted( KSocket*s );
00328
00329 protected:
00330 bool init( unsigned short int );
00331 bool init( const char *_path );
00332
00337 int sock;
00338
00339 private:
00340 KServerSocket(const KServerSocket&);
00341 KServerSocket& operator=(const KServerSocket&);
00342
00343 KServerSocketPrivate *d;
00344 };
00345
00346 #endif //Q_OS_UNIX
00347
00348 #endif
This file is part of the documentation for kdecore Library Version 3.3.90.