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

tdecore

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 "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 // 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 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     // BCI: remove in libtdecore.so.4
00157     unsigned long ipv4_addr() KDE_DEPRECATED;
00158 
00159     // BCI: remove in libtdecore.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( 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      * 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     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     // BCI: remove in libtdecore.so.4
00313     unsigned long ipv4_addr();
00314 #endif
00315 
00316 public slots:
00320     virtual void slotAccept( int ); // why is this virtual?
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     // HACK
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

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.7.1
This website is maintained by Timothy Pearson.