00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#ifndef KSOCKETDEVICE_H
00026
#define KSOCKETDEVICE_H
00027
00028
#include <qsocketnotifier.h>
00029
#include "ksocketbase.h"
00030
00031
namespace KNetwork {
00032
00033
class KSocketDevice;
00034
class KSocketDeviceFactoryBase;
00035
00036
class KSocketDevicePrivate;
00050 class KSocketDevice:
public KActiveSocketBase,
public KPassiveSocketBase
00051 {
00052
public:
00063 enum Capabilities
00064 {
00067
CanConnectString = 0x01,
00068
00071
CanBindString = 0x02,
00072
00075
CanNotBind = 0x04,
00076
00079
CanNotListen = 0x08,
00080
00084
CanMulticast = 0x10,
00085
00090
CanNotUseDatagrams = 0x20
00091 };
00092
protected:
00095 int m_sockfd;
00096
00097
public:
00104
explicit KSocketDevice(
const KSocketBase* = 0L);
00105
00112
explicit KSocketDevice(
int fd);
00113
00117
virtual ~KSocketDevice();
00118
00122 inline int socket()
const
00123
{
return m_sockfd; }
00124
00134 virtual int capabilities()
const
00135
{
return 0; }
00136
00140
virtual bool setSocketOptions(
int opts);
00141
00145
virtual bool open(
int mode);
00146
00152
virtual void close();
00153
00157 virtual void flush()
00158 { }
00159
00164
virtual bool create(
int family,
int type,
int protocol);
00165
00170
bool create(
const KResolverEntry& address);
00171
00175
virtual bool bind(
const KResolverEntry& address);
00176
00180
virtual bool listen(
int backlog = 5);
00181
00185
virtual bool connect(
const KResolverEntry& address);
00186
00191
virtual KSocketDevice*
accept();
00192
00196
virtual bool disconnect();
00197
00201
virtual Q_LONG
bytesAvailable() const;
00202
00209 virtual Q_LONG waitForMore(
int msecs,
bool *timeout = 0L);
00210
00214 virtual Q_LONG readBlock(
char *data, Q_ULONG maxlen);
00215
00219 virtual Q_LONG readBlock(
char *data, Q_ULONG maxlen,
KSocketAddress& from);
00220
00224 virtual Q_LONG peekBlock(
char *data, Q_ULONG maxlen);
00225
00229 virtual Q_LONG peekBlock(
char *data, Q_ULONG maxlen,
KSocketAddress& from);
00230
00234 virtual Q_LONG writeBlock(const
char *data, Q_ULONG len);
00235
00239 virtual Q_LONG writeBlock(const
char *data, Q_ULONG len, const
KSocketAddress& to);
00240
00244 virtual
KSocketAddress localAddress() const;
00245
00250 virtual
KSocketAddress peerAddress() const;
00251
00266 virtual
KSocketAddress externalAddress() const;
00267
00275
QSocketNotifier* readNotifier() const;
00276
00283
QSocketNotifier* writeNotifier() const;
00284
00291
QSocketNotifier* exceptionNotifier() const;
00292
00311 virtual
bool poll(
bool* input,
bool* output,
bool* exception = 0L,
00312
int timeout = -1,
bool* timedout = 0L);
00313
00325
bool poll(
int timeout = -1,
bool* timedout = 0L);
00326
00327 protected:
00335
KSocketDevice(
bool, const
KSocketBase* parent = 0L);
00336
00352 virtual
QSocketNotifier* createNotifier(
QSocketNotifier::Type type) const;
00353
00354 public:
00365 static
KSocketDevice* createDefault(
KSocketBase* parent);
00366
00375 static
KSocketDevice* createDefault(
KSocketBase* parent,
int capabilities);
00376
00383 static KSocketDeviceFactoryBase* setDefaultImpl(KSocketDeviceFactoryBase* factory);
00384
00389 static
void addNewImpl(KSocketDeviceFactoryBase* factory,
int capabilities);
00390
00391 private:
00392
KSocketDevice(const
KSocketDevice&);
00393 KSocketDevice& operator=(const KSocketDevice&);
00394
00395 KSocketDevicePrivate *d;
00396 };
00397
00402 class KSocketDeviceFactoryBase
00403 {
00404
public:
00405
virtual KSocketDevice* create(
KSocketBase*) const = 0;
00406 };
00407
00412 template<class Impl>
00413 class
KSocketDeviceFactory: public KSocketDeviceFactoryBase
00414 {
00415
public:
00416
virtual KSocketDevice* create(
KSocketBase* parent)
const
00417
{
return new Impl(parent); }
00418 };
00419
00420 }
00421
00422
#endif