kdecore Library API Documentation

ksock.h

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (C) 1997 Torben Weis (weis@kde.org)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  *  Boston, MA 02111-1307, USA.
00019  */
00020 #ifndef KSOCK_H
00021 #define KSOCK_H
00022 
00023 #include "kdemacros.h"
00024 #include <qobject.h>
00025 #include <sys/types.h>
00026 // we define STRICT_ANSI to get rid of some warnings in glibc
00027 #ifndef __STRICT_ANSI__
00028 #define __STRICT_ANSI__
00029 #define _WE_DEFINED_IT_
00030 #endif
00031 #include <sys/socket.h>
00032 #ifdef _WE_DEFINED_IT_
00033 #undef __STRICT_ANSI__
00034 #undef _WE_DEFINED_IT_
00035 #endif
00036 
00037 #include <sys/un.h>
00038 
00039 #include <netinet/in.h>
00040 class QSocketNotifier;
00041 
00042 #ifdef KSOCK_NO_BROKEN
00043 // This is here for compatibility with old applications still using the constants
00044 // Never use them in new programs
00045 
00046 // Here are a whole bunch of hackish macros that allow one to
00047 // get at the correct member of ksockaddr_in
00048 // But since ksockaddr_in is IPv4-only, and deprecated...
00049 
00050 typedef sockaddr_in ksockaddr_in;
00051 #define get_sin_addr(x) x.sin_addr
00052 #define get_sin_port(x) x.sin_port
00053 #define get_sin_family(x) x.sin_family
00054 #define get_sin_paddr(x) x->sin_addr
00055 #define get_sin_pport(x) x->sin_port
00056 #define get_sin_pfamily(x) x->sin_family
00057 #endif
00058 
00059 #define KSOCK_DEFAULT_DOMAIN PF_INET
00060 
00061 class KSocketPrivate;
00062 class KServerSocketPrivate;
00063 
00085 class KDE_DEPRECATED KSocket : public QObject
00086 {
00087     Q_OBJECT
00088 public:
00093     KSocket( int _sock );
00100     KSocket( const char *_host, unsigned short int _port, int timeOut = 30);
00101 
00106     KSocket( const char * _path );
00107 
00111     virtual ~KSocket();
00112 
00117     int socket() const { return sock; }
00118 
00127     void enableRead( bool enable );
00128 
00140     void enableWrite( bool enable );
00141 
00142 #ifdef KSOCK_NO_BROKEN
00143     // BCI: remove in libkdecore.so.4
00151     unsigned long ipv4_addr() KDE_DEPRECATED;
00152 
00153     // BCI: remove in libkdecore.so.4
00159     static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) KDE_DEPRECATED;
00160 #endif
00161 
00162 signals:
00170     void readEvent( KSocket *s );
00171 
00183     void writeEvent( KSocket *s );
00184 
00189     void closeEvent( KSocket *s );
00190 
00191 public slots:
00199     void slotWrite( int x);
00200 
00208     void slotRead( int x );
00209 
00210 protected:
00211     bool connect( const QString& _host, unsigned short int _port, int timeout = 0 );
00212     bool connect( const char *_path );
00213 
00214     /******************************************************
00215      * The file descriptor for this socket. sock may be -1.
00216      * This indicates that it is not connected.
00217      */
00218     int sock;
00219 
00220 private:
00221     KSocket(const KSocket&);
00222     KSocket& operator=(const KSocket&);
00223 
00224     KSocketPrivate *d;
00225 
00226 };
00227 
00228 
00247 class KServerSocket : public QObject
00248 {
00249     Q_OBJECT
00250 public:
00258     KServerSocket( unsigned short int _port, bool _bind = true );
00259 
00267     KServerSocket( const char *_path, bool _bind = true);
00268 
00272     virtual ~KServerSocket();
00273 
00280     bool bindAndListen();
00281 
00287     int socket() const { return sock; }
00288 
00293     unsigned short int port();
00294 
00295 #ifdef KSOCK_NO_BROKEN
00296     // BCI: remove in libkdecore.so.4
00303     unsigned long ipv4_addr();
00304 #endif
00305 
00306 public slots:
00310     virtual void slotAccept( int ); // why is this virtual?
00311 
00312 signals:
00322     void accepted( KSocket*s );
00323 
00324 protected:
00325     bool init( unsigned short int );
00326     bool init( const char *_path );
00327 
00332     int sock;
00333 
00334 private:
00335     KServerSocket(const KServerSocket&);
00336     KServerSocket& operator=(const KServerSocket&);
00337 
00338     KServerSocketPrivate *d;
00339 };
00340 
00341 
00342 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 30 05:15:54 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003