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 "kdelibs_export.h"
00024 
00025 #ifdef Q_OS_UNIX
00026 
00027 #include <qobject.h>
00028 #include <sys/types.h>
00029 // we define STRICT_ANSI to get rid of some warnings in glibc
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 // This is here for compatibility with old applications still using the constants
00047 // Never use them in new programs
00048 
00049 // Here are a whole bunch of hackish macros that allow one to
00050 // get at the correct member of ksockaddr_in
00051 // But since ksockaddr_in is IPv4-only, and deprecated...
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     // BCI: remove in libkdecore.so.4
00154     unsigned long ipv4_addr() KDE_DEPRECATED;
00155 
00156     // BCI: remove in libkdecore.so.4
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      * The file descriptor for this socket. sock may be -1.
00219      * This indicates that it is not connected.
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     // BCI: remove in libkdecore.so.4
00308     unsigned long ipv4_addr();
00309 #endif
00310 
00311 public slots:
00315     virtual void slotAccept( int ); // why is this virtual?
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
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:09:40 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003