kclientsocketbase.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 KCLIENTSOCKETBASE_H
#define KCLIENTSOCKETBASE_H
#include <qobject.h>
#include <qstring.h>
#include "ksocketbase.h"
#include "kresolver.h"
#include <kdelibs_export.h>
namespace KNetwork {
class KClientSocketBasePrivate;
class KDECORE_EXPORT KClientSocketBase : public QObject, public KActiveSocketBase
{
Q_OBJECT
public:
enum SocketState
{
Idle,
HostLookup,
HostFound,
Bound,
Connecting,
Open,
Closing,
Unconnected = Bound,
Connected = Open,
Connection = Open
};
public:
KClientSocketBase(QObject* parent, const char *name);
virtual ~KClientSocketBase();
SocketState state() const;
protected:
virtual bool setSocketOptions(int opts);
public:
KResolver& peerResolver() const;
const KResolverResults& peerResults() const;
KResolver& localResolver() const;
const KResolverResults& localResults() const;
void setResolutionEnabled(bool enable);
void setFamily(int families);
virtual bool lookup();
virtual bool bind(const QString& node = QString::null,
const QString& service = QString::null) = 0;
virtual bool bind(const KResolverEntry& address);
virtual bool connect(const QString& node = QString::null,
const QString& service = QString::null) = 0;
virtual bool connect(const KResolverEntry& address);
inline void connectToHost(const QString& host, Q_UINT16 port)
{ connect(host, QString::number(port)); }
virtual bool disconnect();
virtual inline bool open(int)
{ return connect(); }
virtual void close();
virtual void flush()
{ }
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;
bool emitsReadyRead() const;
virtual void enableRead(bool enable);
bool emitsReadyWrite() const;
virtual void enableWrite(bool enable);
protected slots:
// protected slots
virtual void slotReadActivity();
virtual void slotWriteActivity();
private slots:
void lookupFinishedSlot();
signals:
void stateChanged(int newstate);
void gotError(int code);
void hostFound();
void bound(const KResolverEntry& local);
void aboutToConnect(const KResolverEntry& remote, bool& skip);
void connected(const KResolverEntry& remote);
void closed();
void readyRead();
void readyWrite();
protected:
void setState(SocketState state);
virtual void stateChanging(SocketState newState);
void copyError();
private:
KClientSocketBase(const KClientSocketBase&);
KClientSocketBase& operator=(const KClientSocketBase&);
KClientSocketBasePrivate *d;
};
} // namespace KNetwork
#endif
KNetwork::KClientSocketBase::connectToHost
void connectToHost(const QString &host, Q_UINT16 port)
Definition: kclientsocketbase.h:260
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: ksocketbase.h:443
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:66
KNetwork::KClientSocketBase::flush
virtual void flush()
This call is not supported on sockets.
Definition: kclientsocketbase.h:288
KNetwork::KClientSocketBase::open
virtual bool open(int)
Opens the socket.
Definition: kclientsocketbase.h:274
KNetwork::KResolver
Name and service resolution class.
Definition: kresolver.h:295
KNetwork::KSocketAddress
A generic socket address.
Definition: ksocketaddress.h:423
KNetwork::KResolverResults
Name and service resolution results.
Definition: kresolver.h:197
KNetwork::KClientSocketBase::SocketState
SocketState
Socket states.
Definition: kclientsocketbase.h:71
KNetwork::KClientSocketBase
Abstract client socket class.
Definition: kclientsocketbase.h:49

KDE Home | KDE Accessibility Home | Description of Access Keys