ksock.h
/*
* This file is part of the KDE libraries
* Copyright (C) 1997 Torben Weis (weis@kde.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KSOCK_H
#define KSOCK_H
#include "kdelibs_export.h"
#ifdef Q_OS_UNIX
#include <qobject.h>
#include <sys/types.h>
// we define STRICT_ANSI to get rid of some warnings in glibc
#ifndef __STRICT_ANSI__
#define __STRICT_ANSI__
#define _WE_DEFINED_IT_
#endif
#include <sys/socket.h>
#ifdef _WE_DEFINED_IT_
#undef __STRICT_ANSI__
#undef _WE_DEFINED_IT_
#endif
#include <sys/un.h>
#include <netinet/in.h>
class QSocketNotifier;
#ifdef KSOCK_NO_BROKEN
// This is here for compatibility with old applications still using the constants
// Never use them in new programs
// Here are a whole bunch of hackish macros that allow one to
// get at the correct member of ksockaddr_in
// But since ksockaddr_in is IPv4-only, and deprecated...
typedef sockaddr_in ksockaddr_in;
#define get_sin_addr(x) x.sin_addr
#define get_sin_port(x) x.sin_port
#define get_sin_family(x) x.sin_family
#define get_sin_paddr(x) x->sin_addr
#define get_sin_pport(x) x->sin_port
#define get_sin_pfamily(x) x->sin_family
#endif
#define KSOCK_DEFAULT_DOMAIN PF_INET
class KSocketPrivate;
class KServerSocketPrivate;
class KDECORE_EXPORT KSocket : public QObject
{
Q_OBJECT
public:
KSocket( int _sock ) KDE_DEPRECATED;
KSocket( const char *_host, unsigned short int _port, int timeOut = 30) KDE_DEPRECATED;
KSocket( const char * _path ) KDE_DEPRECATED;
virtual ~KSocket();
int socket() const { return sock; }
void enableRead( bool enable );
void enableWrite( bool enable );
#ifdef KSOCK_NO_BROKEN
// BCI: remove in libkdecore.so.4
unsigned long ipv4_addr() KDE_DEPRECATED;
// BCI: remove in libkdecore.so.4
static bool initSockaddr(ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) KDE_DEPRECATED;
#endif
signals:
void readEvent( KSocket *s );
void writeEvent( KSocket *s );
void closeEvent( KSocket *s );
public slots:
void slotWrite( int x);
void slotRead( int x );
protected:
bool connect( const QString& _host, unsigned short int _port, int timeout = 0 );
bool connect( const char *_path );
/******************************************************
* The file descriptor for this socket. sock may be -1.
* This indicates that it is not connected.
*/
int sock;
private:
KSocket(const KSocket&);
KSocket& operator=(const KSocket&);
KSocketPrivate *d;
};
class KDECORE_EXPORT KServerSocket : public QObject
{
Q_OBJECT
public:
KServerSocket( unsigned short int _port, bool _bind = true );
KServerSocket( const char *_path, bool _bind = true);
virtual ~KServerSocket();
bool bindAndListen();
int socket() const { return sock; }
unsigned short int port();
#ifdef KSOCK_NO_BROKEN
// BCI: remove in libkdecore.so.4
unsigned long ipv4_addr();
#endif
public slots:
virtual void slotAccept( int ); // why is this virtual?
signals:
void accepted( KSocket*s );
protected:
bool init( unsigned short int );
bool init( const char *_path );
int sock;
private:
KServerSocket(const KServerSocket&);
KServerSocket& operator=(const KServerSocket&);
KServerSocketPrivate *d;
};
#endif //Q_OS_UNIX
#endif
KServerSocket::sock
int sock
The file descriptor for this socket.
Definition: ksock.h:335
KSocket::socket
int socket() const
Returns a file descriptor for this socket.
Definition: ksock.h:119
KServerSocket::socket
int socket() const
Returns the file descriptor associated with the socket.
Definition: ksock.h:290
KSocket
A TCP/IP client socket.
Definition: ksock.h:87
KServerSocket
Monitors a port for incoming TCP/IP connections.
Definition: ksock.h:250

KDE Home | KDE Accessibility Home | Description of Access Keys