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
00026 #ifndef __STRICT_ANSI__
00027 #define __STRICT_ANSI__
00028 #define _WE_DEFINED_IT_
00029 #endif
00030 #include <sys/socket.h>
00031 #ifdef _WE_DEFINED_IT_
00032 #undef __STRICT_ANSI__
00033 #undef _WE_DEFINED_IT_
00034 #endif
00035
00036 #include <sys/un.h>
00037
00038 #include <netinet/in.h>
00039 class QSocketNotifier;
00040
00041 #ifdef KSOCK_NO_BROKEN
00042
00043
00044
00045
00046
00047
00048
00049 typedef sockaddr_in ksockaddr_in;
00050 #define get_sin_addr(x) x.sin_addr
00051 #define get_sin_port(x) x.sin_port
00052 #define get_sin_family(x) x.sin_family
00053 #define get_sin_paddr(x) x->sin_addr
00054 #define get_sin_pport(x) x->sin_port
00055 #define get_sin_pfamily(x) x->sin_family
00056 #endif
00057
00058 #define KSOCK_DEFAULT_DOMAIN PF_INET
00059
00060 class KSocketPrivate;
00061 class KServerSocketPrivate;
00062
00081 class KSocket : public QObject
00082 {
00083 Q_OBJECT
00084 public:
00089 KSocket( int _sock );
00096 KSocket( const char *_host, unsigned short int _port, int timeOut = 30);
00097
00102 KSocket( const char * _path );
00103
00107 virtual ~KSocket();
00108
00113 int socket() const { return sock; }
00114
00123 void enableRead( bool enable );
00124
00136 void enableWrite( bool enable );
00137
00138 #ifdef KSOCK_NO_BROKEN
00139
00147 unsigned long ipv4_addr();
00148
00149
00155 static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET);
00156 #endif
00157
00158 signals:
00166 void readEvent( KSocket *s );
00167
00179 void writeEvent( KSocket *s );
00180
00185 void closeEvent( KSocket *s );
00186
00187 public slots:
00195 void slotWrite( int x);
00196
00204 void slotRead( int x );
00205
00206 protected:
00207 bool connect( const QString& _host, unsigned short int _port, int timeout = 0 );
00208 bool connect( const char *_path );
00209
00210
00211
00212
00213
00214 int sock;
00215
00216 private:
00217 KSocket(const KSocket&);
00218 KSocket& operator=(const KSocket&);
00219
00220 KSocketPrivate *d;
00221
00222 };
00223
00224
00241 class KServerSocket : public QObject
00242 {
00243 Q_OBJECT
00244 public:
00252 KServerSocket( unsigned short int _port, bool _bind = true );
00253
00261 KServerSocket( const char *_path, bool _bind = true);
00262
00266 virtual ~KServerSocket();
00267
00274 bool bindAndListen();
00275
00281 int socket() const { return sock; }
00282
00287 unsigned short int port();
00288
00289 #ifdef KSOCK_NO_BROKEN
00290
00297 unsigned long ipv4_addr();
00298 #endif
00299
00300 public slots:
00304 virtual void slotAccept( int );
00305
00306 signals:
00316 void accepted( KSocket*s );
00317
00318 protected:
00319 bool init( unsigned short int );
00320 bool init( const char *_path );
00321
00326 int sock;
00327
00328 private:
00329 KServerSocket(const KServerSocket&);
00330 KServerSocket& operator=(const KServerSocket&);
00331
00332 KServerSocketPrivate *d;
00333 };
00334
00335
00336 #endif
This file is part of the documentation for kdelibs Version 3.1.4.