• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

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., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
00019  */
00020 #ifndef KSOCK_H
00021 #define KSOCK_H
00022 
00023 #include "kdelibs_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 // we define STRICT_ANSI to get rid of some warnings in glibc
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 // This is here for compatibility with old applications still using the constants
00051 // Never use them in new programs
00052 
00053 // Here are a whole bunch of hackish macros that allow one to
00054 // get at the correct member of ksockaddr_in
00055 // But since ksockaddr_in is IPv4-only, and deprecated...
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 KSocketPrivate;
00069 class KServerSocketPrivate;
00070 
00091 class KDECORE_EXPORT KSocket : public TQObject
00092 {
00093     Q_OBJECT
00094 public:
00099     KSocket( int _sock ) KDE_DEPRECATED;
00106     KSocket( const char *_host, unsigned short int _port, int timeOut = 30) KDE_DEPRECATED;
00107 
00112     KSocket( const char * _path ) KDE_DEPRECATED;
00113 
00117     virtual ~KSocket();
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     // BCI: remove in libkdecore.so.4
00157     unsigned long ipv4_addr() KDE_DEPRECATED;
00158 
00159     // BCI: remove in libkdecore.so.4
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( KSocket *s );
00177 
00189     void writeEvent( KSocket *s );
00190 
00195     void closeEvent( KSocket *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      * The file descriptor for this socket. sock may be -1.
00222      * This indicates that it is not connected.
00223      */
00224     int sock;
00225 
00226 private:
00227     KSocket(const KSocket&);
00228     KSocket& operator=(const KSocket&);
00229 
00230     KSocketPrivate *d;
00231 
00232 };
00233 
00234 
00254 class KDECORE_EXPORT KServerSocket : public TQObject
00255 {
00256     Q_OBJECT
00257 public:
00265     KServerSocket( unsigned short int _port, bool _bind = true );
00266 
00274     KServerSocket( const char *_path, bool _bind = true);
00275 
00279     virtual ~KServerSocket();
00280 
00287     bool bindAndListen();
00288 
00294     int socket() const { return sock; }
00295 
00300     unsigned short int port();
00301 
00302 #ifdef KSOCK_NO_BROKEN
00303     // BCI: remove in libkdecore.so.4
00310     unsigned long ipv4_addr();
00311 #endif
00312 
00313 public slots:
00317     virtual void slotAccept( int ); // why is this virtual?
00318 
00319 signals:
00329     void accepted( KSocket*s );
00330 
00331 protected:
00332     bool init( unsigned short int );
00333     bool init( const char *_path );
00334 
00339     int sock;
00340 
00341 private:
00342     KServerSocket(const KServerSocket&);
00343     KServerSocket& operator=(const KServerSocket&);
00344 
00345     KServerSocketPrivate *d;
00346 };
00347 
00348 #endif //Q_OS_UNIX
00349 
00350 #endif

kdecore

Skip menu "kdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |