Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ReceiveWindow Class Reference

A buffer of packets that guarentees that the data is received in order. More...

#include <ReceiveWindow.h>

Inheritance diagram for ReceiveWindow::

BasicObject List of all members.

Public Methods

 ReceiveWindow (int size, SAR *m_sar)
 ~ReceiveWindow ()
 Destroy the receive window. More...

int receive (u_char *buffer, int bufferLength)
 Receive some data from a remote node. More...

bool addReceive (TpPacket *packet)
 Try to add a packet to the window and ACK it. More...

void close ()
 Close the receive window. More...

virtual void toStream (std::ostream &out)
 Print out the state of the sliding window. More...


Private Methods

void removePacket (int seqNum)
 Delete the packet from the buffer and free its memory. More...

int addPacket (TpPacket *packet)
 Add a packet to the buffer. More...

void destroy ()
 Flush the receive window. More...

void setInitialSequenceNumber (int sequenceNumber)
 Once a connection is established, this function should be called to set up the window position pointers. More...

TpPacketgetNext (bool blocking=true)
 Return the next packet in the receive window. More...

bool canAdd (TpPacket *packet)
 Returns true if another packet can be added to the queue. More...

int calcCredits ()
 Calculates the credits. More...

WindowPosition calcMaxAck ()
 Calculate the maximum sequence number to ACK. More...

int reassemble (u_char *buffer, int bufferLength)
 Reassemble a message. More...

void sendAck ()
 ACKs as many packets as possible. More...

void dumpDebug ()
 Dump the table to debug output. More...


Private Attributes

WindowPosition m_nextExpected
 next packet sequence number expected to be received. More...

WindowPosition m_lastAccepted
 last possible sequence number we will accept. More...

WindowPosition m_lastRead
 last packet read by application. More...

vector< u_char > m_excessBuffer
 used as a buffer when reassembling a message. More...

bool m_reading
 true while getNext() is executing. More...

bool m_destroy
 used to signal that we want the object to die. More...

bool m_closed
 used to signal that the connection is closed. More...

bool m_firstAck
 true if we havent sent the first ACK yet. More...

SARm_sar
 a pointer back to our container. More...

Condition m_dataSignal
 signalled when we receive some data. More...

Condition m_terminate
 used to signal that getNext() is done. More...

int m_size
 the size of the sliding window. More...

Mutex m_slidingWindowLock
 a lock for the window while doing stuff to it. More...

vector< TpPacket *> m_window
 The array that stores all the packets. More...


Detailed Description

A buffer of packets that guarentees that the data is received in order.

Todo:
Add in a m_maxSeqNumRecvd for faster calculations.

Definition at line 9 of file ReceiveWindow.h.


Constructor & Destructor Documentation

ReceiveWindow::ReceiveWindow int size,
SAR * sar
 

Parameters:
size   The number of packets this window can hold.
sar   A pointer back to our SAR container.

Definition at line 16 of file ReceiveWindow.cpp.

ReceiveWindow::~ReceiveWindow
 

Destroy the receive window.

Definition at line 41 of file ReceiveWindow.cpp.


Member Function Documentation

int ReceiveWindow::addPacket TpPacket * packet [private]
 

Add a packet to the buffer.

This removes any packet that was in the position that the packet wants to go in.

Returns:
The position which the packet was added to, which is the same as the sequence number.

Definition at line 62 of file ReceiveWindow.cpp.

Referenced by addReceive().

bool ReceiveWindow::addReceive TpPacket * receivedPacket
 

Try to add a packet to the window and ACK it.

If it cannot be addedto the window, delete the packet.

Returns:
true if packet successfully added.

Definition at line 144 of file ReceiveWindow.cpp.

Referenced by SAR::receivePacket().

int ReceiveWindow::calcCredits [private]
 

Calculates the credits.

Credits == number of holes in window from nextExpected to lastAccepted

Note: this function does not lock m_slidingWindowLock because it is private. You must make sure that this is locked before calling this function.

Returns:
The number of credits available in the receive window.

Definition at line 319 of file ReceiveWindow.cpp.

Referenced by sendAck().

WindowPosition ReceiveWindow::calcMaxAck [private]
 

Calculate the maximum sequence number to ACK.

This means there are no holes in the window up to the return value.

Returns:
The max sequence number contained in a WindowPosition object.

Definition at line 347 of file ReceiveWindow.cpp.

Referenced by addReceive(), and sendAck().

bool ReceiveWindow::canAdd TpPacket * packet [private]
 

Returns true if another packet can be added to the queue.

Note: this function does not lock m_slidingWindowLock because it is private. You must make sure that this is locked before calling this function.

Definition at line 296 of file ReceiveWindow.cpp.

Referenced by addReceive().

void ReceiveWindow::close
 

Close the receive window.

The window will no longer accept packets, but if there are any left they will be saved in case "receive" is called.

Definition at line 552 of file ReceiveWindow.cpp.

Referenced by SAR::connectionClosed().

void ReceiveWindow::destroy [private]
 

Flush the receive window.

Used to destroy the receive queue.

Definition at line 532 of file ReceiveWindow.cpp.

Referenced by ~ReceiveWindow().

void ReceiveWindow::dumpDebug [private]
 

Dump the table to debug output.

Definition at line 564 of file ReceiveWindow.cpp.

Referenced by addReceive(), and getNext().

TpPacket * ReceiveWindow::getNext bool blocking = true [private]
 

Return the next packet in the receive window.

Parameters:
blocking   If this is true, then if there are no currently no packets available, the function will block. Otherwise, the function will not block.

Returns:
The next packet in the receive queue.

Definition at line 210 of file ReceiveWindow.cpp.

Referenced by reassemble().

int ReceiveWindow::reassemble u_char * buffer,
int bufferLength
[private]
 

Reassemble a message.

This function will put as much data as it can into the buffer provided. This function will block until it receives at least one data packet. If it is unable to fit the data in the provided buffer, it will copy as much as it can into it, and save the rest for later. On the next call to the function it will continue from where it left off.

Parameters:
buffer   The buffer into which the data will be placed.
bufferLenth   The size of the buffer.

Returns:
The amount of data put into the buffer. PB_UNREACHABLE if the connection has been closed.

Definition at line 404 of file ReceiveWindow.cpp.

Referenced by receive().

int ReceiveWindow::receive u_char * buffer,
int bufferLength
 

Receive some data from a remote node.

Definition at line 96 of file ReceiveWindow.cpp.

Referenced by SAR::receive().

void ReceiveWindow::removePacket int index [private]
 

Delete the packet from the buffer and free its memory.

Parameters:
seqNum   The sequence number to delete.

Definition at line 77 of file ReceiveWindow.cpp.

Referenced by addPacket().

void ReceiveWindow::sendAck [private]
 

ACKs as many packets as possible.

Definition at line 117 of file ReceiveWindow.cpp.

Referenced by addReceive().

void ReceiveWindow::setInitialSequenceNumber int sequenceNumber [private]
 

Once a connection is established, this function should be called to set up the window position pointers.

Definition at line 106 of file ReceiveWindow.cpp.

void ReceiveWindow::toStream std::ostream & out [virtual]
 

Print out the state of the sliding window.

Reimplemented from BasicObject.

Definition at line 577 of file ReceiveWindow.cpp.


Member Data Documentation

bool ReceiveWindow::m_closed [private]
 

used to signal that the connection is closed.

Definition at line 54 of file ReceiveWindow.h.

Condition ReceiveWindow::m_dataSignal [private]
 

signalled when we receive some data.

Definition at line 66 of file ReceiveWindow.h.

bool ReceiveWindow::m_destroy [private]
 

used to signal that we want the object to die.

Definition at line 51 of file ReceiveWindow.h.

vector<u_char> ReceiveWindow::m_excessBuffer [private]
 

used as a buffer when reassembling a message.

Definition at line 45 of file ReceiveWindow.h.

bool ReceiveWindow::m_firstAck [private]
 

true if we havent sent the first ACK yet.

Definition at line 60 of file ReceiveWindow.h.

WindowPosition ReceiveWindow::m_lastAccepted [private]
 

last possible sequence number we will accept.

Definition at line 38 of file ReceiveWindow.h.

WindowPosition ReceiveWindow::m_lastRead [private]
 

last packet read by application.

Definition at line 41 of file ReceiveWindow.h.

WindowPosition ReceiveWindow::m_nextExpected [private]
 

next packet sequence number expected to be received.

Definition at line 35 of file ReceiveWindow.h.

bool ReceiveWindow::m_reading [private]
 

true while getNext() is executing.

Definition at line 48 of file ReceiveWindow.h.

SAR* ReceiveWindow::m_sar [private]
 

a pointer back to our container.

Definition at line 63 of file ReceiveWindow.h.

int ReceiveWindow::m_size [private]
 

the size of the sliding window.

Definition at line 72 of file ReceiveWindow.h.

Mutex ReceiveWindow::m_slidingWindowLock [private]
 

a lock for the window while doing stuff to it.

Definition at line 75 of file ReceiveWindow.h.

Condition ReceiveWindow::m_terminate [private]
 

used to signal that getNext() is done.

Definition at line 69 of file ReceiveWindow.h.

vector<TpPacket*> ReceiveWindow::m_window [private]
 

The array that stores all the packets.

Definition at line 78 of file ReceiveWindow.h.


The documentation for this class was generated from the following files:
Generated at Thu Jul 11 13:31:58 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001