22 #ifndef UTP_LOCALWINDOW_H
23 #define UTP_LOCALWINDOW_H
26 #include <ktorrent_export.h>
27 #include <util/constants.h>
28 #include <QSharedPointer>
29 #include "packetbuffer.h"
36 const bt::Uint32 DEFAULT_CAPACITY = 64*1024;
40 WindowPacket(bt::Uint16 seq_nr);
41 WindowPacket(bt::Uint16 seq_nr, bt::Buffer::Ptr packet, bt::Uint32 data_off);
44 bt::Uint32 read(bt::Uint8* dst, bt::Uint32 max_len);
45 bool fullyRead()
const;
46 void set(bt::Buffer::Ptr packet, bt::Uint32 data_off);
49 bt::Buffer::Ptr packet;
50 bt::Uint32 bytes_read;
57 class KTORRENT_EXPORT LocalWindow
60 LocalWindow(bt::Uint32 cap = DEFAULT_CAPACITY);
61 virtual ~LocalWindow();
64 bt::Uint32 availableSpace()
const {
return window_space;}
67 bt::Uint32 currentWindow()
const {
return capacity - window_space;}
70 bt::Uint32 windowCapacity()
const {
return capacity;}
73 bool packetReceived(
const Header* hdr, bt::Buffer::Ptr packet, bt::Uint32 data_off);
76 void setLastSeqNr(bt::Uint16 lsn);
79 bt::Uint16 lastSeqNr()
const {
return last_seq_nr;}
82 bool isEmpty()
const {
return incoming_packets.empty();}
85 bt::Uint32 read(bt::Uint8* data, bt::Uint32 max_len);
88 bool isReadable()
const {
return bytes_available > 0;}
91 bt::Uint32 bytesAvailable()
const {
return bytes_available;}
94 bt::Uint32 selectiveAckBits()
const;
100 typedef std::vector<WindowPacket> WindowPacketList;
102 bt::Uint16 last_seq_nr;
103 bt::Uint16 first_seq_nr;
105 WindowPacketList incoming_packets;
106 bt::Uint32 window_space;
107 bt::Uint32 bytes_available;
112 #endif // UTP_LOCALWINDOW_H