diff options
author | Christian Pointner <equinox@anytun.org> | 2007-06-22 16:49:55 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2007-06-22 16:49:55 +0000 |
commit | 7ca7a28a058b6644913f6e50eb944d657246ada0 (patch) | |
tree | 92ff77371cbcc98a0aa1149700f4d17f10b026fb | |
parent | broken makefile fixed (diff) |
seqWindow test
-rw-r--r-- | anytun.cpp | 5 | ||||
-rw-r--r-- | seqWindow.cpp | 30 | ||||
-rw-r--r-- | seqWindow.h | 10 |
3 files changed, 32 insertions, 13 deletions
@@ -64,7 +64,7 @@ void* sender(void* p) seq_nr_t seq = 0; while(1) { - Packet pack(1600); + Packet pack(1600); // fix me... mtu size // read packet from device int len = param->dev.read(pack); @@ -105,7 +105,8 @@ void* receiver(void* p) { string remote_host; u_int16_t remote_port; - Packet pack(1600); + Packet pack(1600); // fix me... mtu size + // read packet from socket u_int32_t len = param->src.recv(pack, remote_host, remote_port); pack.resizeBack(len); diff --git a/seqWindow.cpp b/seqWindow.cpp index 2179762..9736f53 100644 --- a/seqWindow.cpp +++ b/seqWindow.cpp @@ -39,30 +39,48 @@ SeqWindow::SeqWindow(window_size_t w) : window_size_(w) SeqWindow::~SeqWindow() { - } -SeqWindow::SeqQueue::size_type SeqWindow::getLength(sender_id_t sender) +SeqWindow::SeqDeque::size_type SeqWindow::getLength(sender_id_t sender) { - return 0; + Lock lock(mutex_); + SenderMap::const_iterator s = sender_.find(sender); + if(s == sender_.end()) + return 0; + + return s->second.size(); } bool SeqWindow::hasSeqNr(sender_id_t sender, seq_nr_t seq) { + Lock lock(mutex_); + SenderMap::const_iterator s = sender_.find(sender); + if(s == sender_.end()) + return false; + + SeqDeque::const_iterator it; + for(it = s->second.begin(); it != s->second.end(); it++) + if(*it == seq) + return true; + return false; } void SeqWindow::addSeqNr(sender_id_t sender, seq_nr_t seq) { - + Lock lock(mutex_); + sender_[sender].push_back(seq); } void SeqWindow::clear(sender_id_t sender) { - + Lock lock(mutex_); + sender_[sender].clear(); + sender_.erase(sender); } void SeqWindow::clear() { - + Lock lock(mutex_); + sender_.clear(); } diff --git a/seqWindow.h b/seqWindow.h index 9fb88dd..77af418 100644 --- a/seqWindow.h +++ b/seqWindow.h @@ -32,7 +32,7 @@ #define _SEQ_WINDOW_H_ #include <map> -#include <queue> +#include <deque> #include "threadUtils.hpp" #include "datatypes.h" @@ -40,13 +40,13 @@ class SeqWindow { public: - typedef std::queue<seq_nr_t> SeqQueue; - typedef std::map<sender_id_t, SeqQueue> SenderMap; + typedef std::deque<seq_nr_t> SeqDeque; + typedef std::map<sender_id_t, SeqDeque> SenderMap; SeqWindow(window_size_t w); ~SeqWindow(); - SeqQueue::size_type getLength(sender_id_t sender); + SeqDeque::size_type getLength(sender_id_t sender); bool hasSeqNr(sender_id_t sender, seq_nr_t seq); void addSeqNr(sender_id_t sender, seq_nr_t seq); void clear(sender_id_t sender); @@ -58,7 +58,7 @@ private: window_size_t window_size_; Mutex mutex_; - SenderMap sender; + SenderMap sender_; }; #endif |