Protocols::Transports::UdpConnection Class Reference

#include <UdpConnection.h> [code]

Inherits Protocols::Transports::Connection.

Inheritance diagram for Protocols::Transports::UdpConnection:

Inheritance graph
[legend]
Collaboration diagram for Protocols::Transports::UdpConnection:

Collaboration graph
[legend]
List of all members.

Detailed Description

Unreliable datagram connection-oriented data transport over UDP.

This class can be used when you want to transmit packets over UDP. You get unreliable connection-oriented data transport. This class in conjunction with UdpSwitch constitute a thin wrapper around QUdpSocket.

Todo:
The description in the note below is not consistent with the current implementation of dataRead() ! If we change the implementation according to the specification we will also need to change Gnutella::PacketProcessor::PacketReader! Maybe it is a good idea to add a property isStream() or isDatagram() and have each reader/writer use a suitable strategy for the current Connection. If we do like this, then a maxsize packet will always be read from a datagram connection and then the header be parsed, whereas for stream connection the header will be read first, parsed and then the payload read. Making this design decision is not important at this time, so let's keep the the currect system as is and consider these concerns at a later point when necessary for a new feature.
Note:
Make sure you write your complete user packet in a single write() call. If you don't do so, each part you write will be sent in a separate UDP packet. Also, make sure you supply a large enought buffer in a read() call in order to get the complete user packet. If you don't, you will get only a part and the rest will be discarded.
If your application protocol is packet oriented and its PacketWriter and PacketReader fulfill the above requirements, then you can use either a UdpConnection or a TcpConnection to transport your packets. Just be aware that id you use UdpConnection that the arrival of your packets is not guaranteed.

To increase the chance that a UDP packet actually gets delivered, you should not send UDP packets of size bigger that the smalles MTU of any Internet router on your packets' path. No path MTU discovery is currently implemented. To be on the safe side try not to use data packets bigger than 512 bytes.

UdpConnection will buffer incomming data to let UdpSwitch read further packets for other UdpConnection objects.

Todo:
Allow to set buffer size? What to do if buffers get full?
Todo:
Create generic PacketReader and PacketWriter which could be used as base classes by protocols like Gnutella?

Definition at line 79 of file UdpConnection.h.

Public Member Functions

 UdpConnection (UdpSwitch *udpSwitch)
 ~UdpConnection ()

Protected Member Functions

void doConnectToNode (const NodeAddress &)
void doDisconnectFromNode ()
qint64 readData (char *data, qint64 maxSize)
qint64 writeData (const char *data, qint64 maxSize)

Private Member Functions

 UdpConnection (const UdpConnection &)
UdpConnectionoperator= (const UdpConnection &)
void datagramRead (const QByteArray &datagram)
void datagramWritten ()

Private Attributes

auto_ptr< UdpConnectionPrivatep

Friends

class UdpSwitch


Constructor & Destructor Documentation

Protocols::Transports::UdpConnection::UdpConnection const UdpConnection  )  [private]
 

UdpConnection::UdpConnection UdpSwitch udpSwitch  ) 
 

Definition at line 52 of file UdpConnection.cpp.

UdpConnection::~UdpConnection  ) 
 

Definition at line 58 of file UdpConnection.cpp.


Member Function Documentation

void UdpConnection::datagramRead const QByteArray &  datagram  )  [private]
 

Definition at line 85 of file UdpConnection.cpp.

void Protocols::Transports::UdpConnection::datagramWritten  )  [private]
 

void UdpConnection::doConnectToNode const NodeAddress  )  [protected, virtual]
 

Implements Protocols::Transports::Connection.

Definition at line 63 of file UdpConnection.cpp.

void UdpConnection::doDisconnectFromNode  )  [protected, virtual]
 

Implements Protocols::Transports::Connection.

Definition at line 77 of file UdpConnection.cpp.

UdpConnection& Protocols::Transports::UdpConnection::operator= const UdpConnection  )  [private]
 

qint64 UdpConnection::readData char *  data,
qint64  maxSize
[protected, virtual]
 

Implements Protocols::Transports::Connection.

Definition at line 91 of file UdpConnection.cpp.

qint64 UdpConnection::writeData const char *  data,
qint64  maxSize
[protected, virtual]
 

Implements Protocols::Transports::Connection.

Definition at line 113 of file UdpConnection.cpp.


Friends And Related Function Documentation

friend class UdpSwitch [friend]
 

Definition at line 101 of file UdpConnection.h.


Member Data Documentation

auto_ptr<UdpConnectionPrivate> Protocols::Transports::UdpConnection::p [private]
 

Reimplemented from Protocols::Transports::Connection.

Definition at line 99 of file UdpConnection.h.


The documentation for this class was generated from the following files: