kdatagramsocket.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 KDATAGRAMSOCKET_H
#define KDATAGRAMSOCKET_H
#include <qcstring.h>
#include "ksocketaddress.h"
#include "kclientsocketbase.h"
namespace KNetwork {
class KResolverEntry;
class KDECORE_EXPORT KDatagramPacket
{
QByteArray m_data;
KSocketAddress m_address;
public:
KDatagramPacket()
{ }
KDatagramPacket(const QByteArray& content)
: m_data(content)
{ }
KDatagramPacket(const char* content, uint length)
{ setData(content, length); }
KDatagramPacket(const QByteArray& content, const KSocketAddress& addr)
: m_data(content), m_address(addr)
{ }
KDatagramPacket(const char *content, uint length, const KSocketAddress& addr)
: m_address(addr)
{ setData(content, length); }
KDatagramPacket(const KDatagramPacket& other)
{ *this = other; }
~KDatagramPacket()
{ }
const QByteArray& data() const
{ return m_data; }
uint length() const
{ return m_data.size(); }
uint size() const
{ return m_data.size(); }
bool isEmpty() const
{ return m_data.isEmpty(); }
bool isNull() const
{ return m_data.isNull(); }
const KSocketAddress& address() const
{ return m_address; }
void setAddress(const KSocketAddress& addr)
{ m_address = addr; }
void detach()
{ m_data.detach(); }
void setData(const QByteArray& data)
{ m_data = data; }
void setData(const char* data, uint length)
{ m_data.duplicate(data, length); }
};
class KDatagramSocketPrivate;
class KDECORE_EXPORT KDatagramSocket: public KClientSocketBase
{
Q_OBJECT
public:
KDatagramSocket(QObject* parent = 0L, const char *name = 0L);
virtual ~KDatagramSocket();
// virtual bool lookup();
virtual bool bind(const QString& node = QString::null,
const QString& service = QString::null);
virtual bool bind(const KResolverEntry& entry)
{ return KClientSocketBase::bind(entry); }
virtual bool connect(const QString& node = QString::null,
const QString& service = QString::null);
virtual bool connect(const KResolverEntry& entry)
{ return KClientSocketBase::connect(entry); }
virtual Q_LONG writeBlock(const char *data, Q_ULONG len, const KSocketAddress& to);
virtual KDatagramPacket receive();
virtual Q_LONG send(const KDatagramPacket& packet);
private slots:
void lookupFinishedLocal();
void lookupFinishedPeer();
private:
bool doBind();
void setupSignals();
KDatagramSocketPrivate *d;
};
} // namespace KNetwork
#endif
KNetwork::KDatagramPacket::KDatagramPacket
KDatagramPacket()
Default constructor.
Definition: kdatagramsocket.h:60
KNetwork::KDatagramPacket::KDatagramPacket
KDatagramPacket(const char *content, uint length, const KSocketAddress &addr)
Constructs the datagram with the specified content and address.
Definition: kdatagramsocket.h:88
KNetwork::KDatagramPacket::address
const KSocketAddress & address() const
Returns the socket address.
Definition: kdatagramsocket.h:137
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:66
KNetwork::KSocketAddress
A generic socket address.
Definition: ksocketaddress.h:423
KNetwork::KClientSocketBase::connect
virtual bool connect(const QString &node=QString::null, const QString &service=QString::null)=0
Attempts to connect to the these hostname and service, or use the default ones if none are given...
KNetwork::KDatagramPacket::KDatagramPacket
KDatagramPacket(const char *content, uint length)
Constructs the datagram with the specified content.
Definition: kdatagramsocket.h:75
KNetwork::KDatagramPacket::size
uint size() const
Returns the data length.
Definition: kdatagramsocket.h:119
KNetwork::KDatagramSocket::connect
virtual bool connect(const KResolverEntry &entry)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: kdatagramsocket.h:237
KNetwork::KDatagramPacket::data
const QByteArray & data() const
Returns the data.
Definition: kdatagramsocket.h:107
KNetwork::KDatagramPacket::isEmpty
bool isEmpty() const
Returns true if this object is empty.
Definition: kdatagramsocket.h:125
KNetwork::KDatagramPacket::KDatagramPacket
KDatagramPacket(const QByteArray &content, const KSocketAddress &addr)
Constructs the datagram with the specified content and address.
Definition: kdatagramsocket.h:81
KNetwork::KDatagramPacket::~KDatagramPacket
~KDatagramPacket()
Destructor.
Definition: kdatagramsocket.h:101
KNetwork::KDatagramPacket::length
uint length() const
Returns the data length.
Definition: kdatagramsocket.h:113
KNetwork::KDatagramPacket::detach
void detach()
Detaches our data from a shared pool.
Definition: kdatagramsocket.h:150
KNetwork::KDatagramPacket::setAddress
void setAddress(const KSocketAddress &addr)
Sets the address stored to the given value.
Definition: kdatagramsocket.h:143
KNetwork::KDatagramPacket
one datagram
Definition: kdatagramsocket.h:51
KNetwork::KDatagramSocket::bind
virtual bool bind(const KResolverEntry &entry)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: kdatagramsocket.h:215
KNetwork::KClientSocketBase
Abstract client socket class.
Definition: kclientsocketbase.h:49
KNetwork::KDatagramPacket::setData
void setData(const QByteArray &data)
Sets the data to the given value.
Definition: kdatagramsocket.h:156
KNetwork::KClientSocketBase::bind
virtual bool bind(const QString &node=QString::null, const QString &service=QString::null)=0
Binds this socket to the given nodename and service, or use the default ones if none are given...
KNetwork::KDatagramPacket::setData
void setData(const char *data, uint length)
Sets the data to the given buffer and size.
Definition: kdatagramsocket.h:162
KNetwork::KDatagramPacket::KDatagramPacket
KDatagramPacket(const QByteArray &content)
Constructs the datagram with the specified content.
Definition: kdatagramsocket.h:66
KNetwork::KDatagramPacket::isNull
bool isNull() const
Returns true if this object is null.
Definition: kdatagramsocket.h:131
KNetwork::KDatagramSocket
A socket that operates on datagrams.
Definition: kdatagramsocket.h:180
KNetwork::KDatagramPacket::KDatagramPacket
KDatagramPacket(const KDatagramPacket &other)
Copy constructor.
Definition: kdatagramsocket.h:95

KDE Home | KDE Accessibility Home | Description of Access Keys