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 "tdelibs_export.h"
00024
00025 #ifdef Q_MOC_RUN
00026 #define Q_OS_UNIX
00027 #endif // Q_MOC_RUN
00028
00029 #ifdef Q_OS_UNIX
00030
00031 #include <tqobject.h>
00032 #include <sys/types.h>
00033
00034 #ifndef __STRICT_ANSI__
00035 #define __STRICT_ANSI__
00036 #define _WE_DEFINED_IT_
00037 #endif
00038 #include <sys/socket.h>
00039 #ifdef _WE_DEFINED_IT_
00040 #undef __STRICT_ANSI__
00041 #undef _WE_DEFINED_IT_
00042 #endif
00043
00044 #include <sys/un.h>
00045
00046 #include <netinet/in.h>
00047 class TQSocketNotifier;
00048
00049 #ifdef KSOCK_NO_BROKEN
00050
00051
00052
00053
00054
00055
00056
00057 typedef sockaddr_in ksockaddr_in;
00058 #define get_sin_addr(x) x.sin_addr
00059 #define get_sin_port(x) x.sin_port
00060 #define get_sin_family(x) x.sin_family
00061 #define get_sin_paddr(x) x->sin_addr
00062 #define get_sin_pport(x) x->sin_port
00063 #define get_sin_pfamily(x) x->sin_family
00064 #endif
00065
00066 #define KSOCK_DEFAULT_DOMAIN PF_INET
00067
00068 class TDESocketPrivate;
00069 class TDEServerSocketPrivate;
00070
00091 class TDECORE_EXPORT TDESocket : public TQObject
00092 {
00093 Q_OBJECT
00094 public:
00099 TDESocket( int _sock ) KDE_DEPRECATED;
00106 TDESocket( const char *_host, unsigned short int _port, int timeOut = 30) KDE_DEPRECATED;
00107
00112 TDESocket( const char * _path ) KDE_DEPRECATED;
00113
00117 virtual ~TDESocket();
00118
00123 int socket() const { return sock; }
00124
00133 void enableRead( bool enable );
00134
00146 void enableWrite( bool enable );
00147
00148 #ifdef KSOCK_NO_BROKEN
00149
00157 unsigned long ipv4_addr() KDE_DEPRECATED;
00158
00159
00165 static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) KDE_DEPRECATED;
00166 #endif
00167
00168 signals:
00176 void readEvent( TDESocket *s );
00177
00189 void writeEvent( TDESocket *s );
00190
00195 void closeEvent( TDESocket *s );
00196
00197 public slots:
00205 void slotWrite( int x);
00206
00214 void slotRead( int x );
00215
00216 protected:
00217 bool connect( const TQString& _host, unsigned short int _port, int timeout = 0 );
00218 bool connect( const char *_path );
00219
00220
00221
00222
00223
00224 int sock;
00225
00226 private:
00227 TDESocket(const TDESocket&);
00228 TDESocket& operator=(const TDESocket&);
00229
00230 TDESocketPrivate *d;
00231
00232 };
00233
00234
00254 class TDECORE_EXPORT TDEServerSocket : public TQObject
00255 {
00256 Q_OBJECT
00257 public:
00265 TDEServerSocket( unsigned short int _port, bool _bind = true );
00266
00274 TDEServerSocket( const char *_path, bool _bind = true);
00275
00279 virtual ~TDEServerSocket();
00280
00290 bool bindAndListen(bool suppressFailureMessages = false);
00291
00297 int socket() const { return sock; }
00298
00303 unsigned short int port();
00304
00305 #ifdef KSOCK_NO_BROKEN
00306
00313 unsigned long ipv4_addr();
00314 #endif
00315
00316 public slots:
00320 virtual void slotAccept( int );
00321
00322 signals:
00332 void accepted( TDESocket*s );
00333
00334 protected:
00335 bool init( unsigned short int );
00336 bool init( const char *_path );
00337
00342 int sock;
00343
00344 private:
00345
00346 #ifdef TDESOCKET_BINARY_COMPAT_HACK
00347 KDE_EXPORT bool bindAndListen();
00348 #endif // TDESOCKET_BINARY_COMPAT_HACK
00349
00350 TDEServerSocket(const TDEServerSocket&);
00351 TDEServerSocket& operator=(const TDEServerSocket&);
00352
00353 TDEServerSocketPrivate *d;
00354 };
00355
00356 #endif //Q_OS_UNIX
00357
00358 #endif