fix QueueingSocketSink to update the IOEvent when the handle is modified. tihgtened...
mtk [Tue, 13 Jul 2010 12:49:01 +0000 (12:49 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1645 270642c3-0616-0410-b53a-bc976706d245

senf/PPI/QueueingSocketSink.cc
senf/PPI/QueueingSocketSink.ct
senf/PPI/QueueingSocketSink.cti
senf/PPI/QueueingSocketSink.test.cc

index 4267bb8..c21eeb8 100644 (file)
@@ -92,7 +92,7 @@ prefix_ senf::Packet senf::ppi::FIFOQueueingAlgorithm::v_dequeue()
 
 prefix_ bool senf::ppi::FIFOQueueingAlgorithm::v_enqueue(Packet const & packet)
 {
-    if (queue_.size() == max_size_)
+    if (queue_.size() >= max_size_)
         queue_.pop();
     queue_.push( packet);
     return true;
index 3ae8cbf..93a412e 100644 (file)
@@ -85,7 +85,7 @@ prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::write()
     }
     if (! writer_( handle_, p)) {
         if (qAlgo_->enqueue( p) && !event_.enabled()) {
-            event_.enabled( true);
+          event_.enabled( true);
         }
     }
 }
index f1ae028..481ff99 100644 (file)
@@ -59,6 +59,7 @@ template <class Writer>
 prefix_ void senf::ppi::module::PassiveQueueingSocketSink<Writer>::handle(Handle handle)
 {
     handle_ = handle;
+    event_.set( handle_, IOEvent::Write);
     qAlgo_->clear();
     checkThrottle();
 }
index 38cfcff..972d1ee 100644 (file)
@@ -75,15 +75,25 @@ namespace {
                 return false;
             return ConnectedDgramWriter::operator()( handle, packet);
         }
+
+        TestingConnectedDgramWriter(){
+            throttled = false;
+        }
     };
 }
 
 SENF_AUTO_UNIT_TEST(passiveQueueingSocketSink)
 {
+    senf::ConnectedUDPv4ClientSocketHandle os(senf::noinit); 
+
     senf::ConnectedUDPv4ClientSocketHandle outputSocket (
             senf::INet4SocketAddress( localhost4str(0)));
     module::PassiveQueueingSocketSink<TestingConnectedDgramWriter> udpSink (
-            outputSocket, ppi::FIFOQueueingAlgorithm::create());
+            os, ppi::FIFOQueueingAlgorithm::create());
+    
+    // test re-assignment of socket
+    udpSink.handle( outputSocket);
+    
     udpSink.writer().throttled = false;
     debug::ActiveSource source;
     ppi::connect(source, udpSink);
@@ -106,6 +116,12 @@ SENF_AUTO_UNIT_TEST(passiveQueueingSocketSink)
     source.submit(p);
     BOOST_CHECK_EQUAL( udpSink.qAlgorithm().size(), 1);
 
+    for( int n = 0; n < 100; n++){
+        source.submit(p);
+    }
+    // queue default size is 64
+    BOOST_CHECK_EQUAL( udpSink.qAlgorithm().size(), 64);
+
     udpSink.writer().throttled = false;
 
     runPPI( senf::ClockService::milliseconds(200));