ksocketdevice.h
/* -*- C++ -*-
* Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef KSOCKETDEVICE_H
#define KSOCKETDEVICE_H
#include <qsocketnotifier.h>
#include "ksocketbase.h"
namespace KNetwork {
class KSocketDevice;
class KSocketDeviceFactoryBase;
class KSocketDevicePrivate;
class KDECORE_EXPORT KSocketDevice: public KActiveSocketBase, public KPassiveSocketBase
{
public:
enum Capabilities
{
CanConnectString = 0x01,
CanBindString = 0x02,
CanNotBind = 0x04,
CanNotListen = 0x08,
CanMulticast = 0x10,
CanNotUseDatagrams = 0x20
};
protected:
int m_sockfd;
public:
explicit KSocketDevice(const KSocketBase* = 0L);
explicit KSocketDevice(int fd);
virtual ~KSocketDevice();
inline int socket() const
{ return m_sockfd; }
virtual int capabilities() const
{ return 0; }
virtual bool setSocketOptions(int opts);
virtual bool open(int mode);
virtual void close();
virtual void flush()
{ }
virtual bool create(int family, int type, int protocol);
bool create(const KResolverEntry& address);
virtual bool bind(const KResolverEntry& address);
virtual bool listen(int backlog = 5); // 5 is arbitrary
virtual bool connect(const KResolverEntry& address);
virtual KSocketDevice* accept();
virtual bool disconnect();
virtual Q_LONG bytesAvailable() const;
virtual Q_LONG waitForMore(int msecs, bool *timeout = 0L);
virtual Q_LONG readBlock(char *data, Q_ULONG maxlen);
virtual Q_LONG readBlock(char *data, Q_ULONG maxlen, KSocketAddress& from);
virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen);
virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen, KSocketAddress& from);
virtual Q_LONG writeBlock(const char *data, Q_ULONG len);
virtual Q_LONG writeBlock(const char *data, Q_ULONG len, const KSocketAddress& to);
virtual KSocketAddress localAddress() const;
virtual KSocketAddress peerAddress() const;
virtual KSocketAddress externalAddress() const;
QSocketNotifier* readNotifier() const;
QSocketNotifier* writeNotifier() const;
QSocketNotifier* exceptionNotifier() const;
virtual bool poll(bool* input, bool* output, bool* exception = 0L,
int timeout = -1, bool* timedout = 0L);
bool poll(int timeout = -1, bool* timedout = 0L);
protected:
KSocketDevice(bool, const KSocketBase* parent = 0L);
virtual QSocketNotifier* createNotifier(QSocketNotifier::Type type) const;
public:
static KSocketDevice* createDefault(KSocketBase* parent);
static KSocketDevice* createDefault(KSocketBase* parent, int capabilities);
static KSocketDeviceFactoryBase* setDefaultImpl(KSocketDeviceFactoryBase* factory);
static void addNewImpl(KSocketDeviceFactoryBase* factory, int capabilities);
private:
KSocketDevice(const KSocketDevice&);
KSocketDevice& operator=(const KSocketDevice&);
KSocketDevicePrivate *d;
};
class KSocketDeviceFactoryBase
{
public:
KSocketDeviceFactoryBase() {}
virtual ~KSocketDeviceFactoryBase() {}
virtual KSocketDevice* create(KSocketBase*) const = 0;
};
template<class Impl>
class KSocketDeviceFactory: public KSocketDeviceFactoryBase
{
public:
KSocketDeviceFactory() {}
virtual ~KSocketDeviceFactory() {}
virtual KSocketDevice* create(KSocketBase* parent) const
{ return new Impl(parent); }
};
} // namespaces
#endif
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: ksocketbase.h:443
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:66
KNetwork::KSocketAddress
A generic socket address.
Definition: ksocketaddress.h:423
KStdAction::create
KAction * create(StdAction id, const char *name, const QObject *recvr, const char *slot, KActionCollection *parent)
KNetwork::KSocketDevice::flush
virtual void flush()
This call is not supported on sockets.
Definition: ksocketdevice.h:157
KNetwork::KSocketDevice::socket
int socket() const
Returns the file descriptor for this socket.
Definition: ksocketdevice.h:122
KNetwork::KSocketDeviceFactory
This class provides functionality for creating and registering socket implementations.
Definition: ksocketdevice.h:416
KNetwork::KSocketDevice::m_sockfd
int m_sockfd
The socket file descriptor.
Definition: ksocketdevice.h:95
KNetwork::KSocketDevice::capabilities
virtual int capabilities() const
Returns the set of capabilities this socket class implements.
Definition: ksocketdevice.h:134
KNetwork::KSocketDevice::Capabilities
Capabilities
Capabilities for the socket implementation.
Definition: ksocketdevice.h:63
KNetwork::KSocketDevice
Low-level socket functionality.
Definition: ksocketdevice.h:50
KNetwork::KPassiveSocketBase
Abstract base class for passive sockets.
Definition: ksocketbase.h:683
KNetwork::KSocketBase
Basic socket functionality.
Definition: ksocketbase.h:97

KDE Home | KDE Accessibility Home | Description of Access Keys