mail[Wesnoth-commits] r44437 - in /trunk/src: network_manager_ana.cpp network_manager_ana.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by billybiset on July 20, 2010 - 20:00:
Author: billynux
Date: Tue Jul 20 20:00:34 2010
New Revision: 44437

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44437&view=rev
Log:
Fixes a concurrency bug in the ana implementation: A receive handler was 
created with a timeout parameter, but if multiple messages were received 
interim only the last one was used, discarding some. The connection bug still 
shows up (less frequently) and the ana server doesn't show anybody in the 
lobby.

Modified:
    trunk/src/network_manager_ana.cpp
    trunk/src/network_manager_ana.hpp

Modified: trunk/src/network_manager_ana.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_manager_ana.cpp?rev=44437&r1=44436&r2=44437&view=diff
==============================================================================
--- trunk/src/network_manager_ana.cpp (original)
+++ trunk/src/network_manager_ana.cpp Tue Jul 20 20:00:34 2010
@@ -90,12 +90,12 @@
 
 // Begin ana_receive_handler implementation 
------------------------------------------------------------
 
-ana_receive_handler::ana_receive_handler( ) :
+ana_receive_handler::ana_receive_handler( ana_component_set::iterator 
iterator ) :
+    iterator_( iterator ),
     mutex_(),
     handler_mutex_(),
     timeout_called_mutex_(),
     error_code_(),
-    buffer_(),
     receive_timer_( NULL ),
     finished_( false )
 {
@@ -134,18 +134,21 @@
     mutex_.unlock();
 }
 
-void ana_receive_handler::handle_message(ana::error_code error_c, 
ana::net_id, ana::detail::read_buffer read_buffer)
+void ana_receive_handler::handle_message(ana::error_code          error_c,
+                                         ana::net_id              client,
+                                         ana::detail::read_buffer 
read_buffer)
 {
     boost::mutex::scoped_lock lock( handler_mutex_);
 
-    delete receive_timer_;
-    receive_timer_ = NULL;
-
-    buffer_ = read_buffer;
-    error_code_ = error_c;
-
     if (! finished_ )
     {
+        delete receive_timer_;
+        receive_timer_ = NULL;
+
+        (*iterator_)->add_buffer( read_buffer, client );
+
+        error_code_ = error_c;
+
         finished_ = true;
         mutex_.unlock();
     }
@@ -155,12 +158,13 @@
 {
     boost::mutex::scoped_lock lock( handler_mutex_);
 
-    delete receive_timer_;
-    receive_timer_ = NULL;
-
-    error_code_ = error_c;
     if (! finished_ )
     {
+        delete receive_timer_;
+        receive_timer_ = NULL;
+
+        error_code_ = error_c;
+
         finished_ = true;
         mutex_.unlock();
     }
@@ -170,15 +174,10 @@
 {
     boost::mutex::scoped_lock lock( handler_mutex_ );
 
-    delete receive_timer_;
-    receive_timer_ = NULL;
-
     if (! finished_ )
     {
-//         if (error_code)
-//             std::cout << "DEBUG: Receive attempt timed out\n";
-//         else
-//             std::cout << "DEBUG: Shouldn't reach here\n";
+        delete receive_timer_;
+        receive_timer_ = NULL;
 
         error_code_ = error_code;
         finished_ = true;
@@ -201,6 +200,7 @@
     receive_timer_( NULL ),
     finished_( false )
 {
+    throw std::runtime_error("Multiple receive handler constructed");
     std::cout << "DEBUG: Constructing a new 
ana_multiple_receive_handler...\n";
 
     ana_component_set::iterator it;
@@ -964,7 +964,7 @@
         return 0;
     else
     {
-        ana_receive_handler handler;
+        ana_receive_handler handler(it);
         (*it)->listener()->set_listener_handler( &handler );
 
         if ( (*it)->is_server() )
@@ -978,7 +978,7 @@
             return 0;
         else
         {
-            read_config( handler.buffer(), cfg);
+            read_config( (*it)->wait_for_element(), cfg );
             return (*it)->get_wesnoth_id();
         }
     }

Modified: trunk/src/network_manager_ana.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_manager_ana.hpp?rev=44437&r1=44436&r2=44437&view=diff
==============================================================================
--- trunk/src/network_manager_ana.hpp (original)
+++ trunk/src/network_manager_ana.hpp Tue Jul 20 20:00:34 2010
@@ -221,7 +221,7 @@
         /**
          * Constructs a reader handler object.
          */
-        ana_receive_handler( );
+        ana_receive_handler( ana_component_set::iterator );
 
         /** Destructor. */
         ~ana_receive_handler();
@@ -244,23 +244,18 @@
             return error_code_;
         }
 
-        /** Returns the buffer from the operation. */
-        ana::detail::read_buffer buffer() const
-        {
-            return buffer_;
-        }
-
     private:
         virtual void handle_message   (ana::error_code, ana::net_id, 
ana::detail::read_buffer);
         virtual void handle_disconnect(ana::error_code, ana::net_id);
 
         void handle_timeout(ana::error_code error_code);
+
+        ana_component_set::iterator iterator_;
 
         boost::mutex             mutex_;
         boost::mutex             handler_mutex_;
         boost::mutex             timeout_called_mutex_;
         ana::error_code          error_code_;
-        ana::detail::read_buffer buffer_;
         ana::timer*              receive_timer_;
         bool                     finished_;
 };




Related Messages


Powered by MHonArc, Updated Tue Jul 20 22:00:12 2010