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 <qobject.h>
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026
00027 #include <sys/un.h>
00028
00029 #include <netinet/in.h>
00030 class QSocketNotifier;
00031
00032 #ifdef KSOCK_NO_BROKEN
00033
00034
00035
00036
00037
00038
00039
00040 typedef sockaddr_in ksockaddr_in;
00041 #define get_sin_addr(x) x.sin_addr
00042 #define get_sin_port(x) x.sin_port
00043 #define get_sin_family(x) x.sin_family
00044 #define get_sin_paddr(x) x->sin_addr
00045 #define get_sin_pport(x) x->sin_port
00046 #define get_sin_pfamily(x) x->sin_family
00047 #endif
00048
00049 #define KSOCK_DEFAULT_DOMAIN PF_INET
00050
00051 class KSocketPrivate;
00052 class KServerSocketPrivate;
00053
00072 class KSocket : public QObject
00073 {
00074 Q_OBJECT
00075 public:
00080 KSocket( int _sock );
00087 KSocket( const char *_host, unsigned short int _port, int timeOut = 30);
00088
00093 KSocket( const char * _path );
00094
00098 virtual ~KSocket();
00099
00104 int socket() const { return sock; }
00105
00114 void enableRead( bool enable );
00115
00127 void enableWrite( bool enable );
00128
00129 #ifdef KSOCK_NO_BROKEN
00130
00138 unsigned long ipv4_addr();
00139
00140
00146 static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET);
00147 #endif
00148
00149 signals:
00157 void readEvent( KSocket *s );
00158
00170 void writeEvent( KSocket *s );
00171
00176 void closeEvent( KSocket *s );
00177
00178 public slots:
00186 void slotWrite( int x);
00187
00195 void slotRead( int x );
00196
00197 protected:
00198 bool connect( const QString& _host, unsigned short int _port, int timeout = 0 );
00199 bool connect( const char *_path );
00200
00201
00202
00203
00204
00205 int sock;
00206
00207 private:
00208 KSocket(const KSocket&);
00209 KSocket& operator=(const KSocket&);
00210
00211 KSocketPrivate *d;
00212
00213 };
00214
00215
00232 class KServerSocket : public QObject
00233 {
00234 Q_OBJECT
00235 public:
00243 KServerSocket( unsigned short int _port, bool _bind = true );
00244
00252 KServerSocket( const char *_path, bool _bind = true);
00253
00257 virtual ~KServerSocket();
00258
00265 bool bindAndListen();
00266
00272 int socket() const { return sock; }
00273
00278 unsigned short int port();
00279
00280 #ifdef KSOCK_NO_BROKEN
00281
00288 unsigned long ipv4_addr();
00289 #endif
00290
00291 public slots:
00295 virtual void slotAccept( int );
00296
00297 signals:
00307 void accepted( KSocket*s );
00308
00309 protected:
00310 bool init( unsigned short int );
00311 bool init( const char *_path );
00312
00317 int sock;
00318
00319 private:
00320 KServerSocket(const KServerSocket&);
00321 KServerSocket& operator=(const KServerSocket&);
00322
00323 KServerSocketPrivate *d;
00324 };
00325
00326
00327 #endif
This file is part of the documentation for kdelibs Version 3.1.4.