mail[Wesnoth-commits] r44153 - in /trunk/src: ./ ana/api/ ana/src/


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

Header


Content

Posted by billybiset on July 14, 2010 - 00:44:
Author: billynux
Date: Wed Jul 14 00:44:06 2010
New Revision: 44153

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44153&view=rev
Log:
Improved implementation of the asio_sender to log during sending in ana. Bug 
in network_manager_ana.cpp:876 remains.

Modified:
    trunk/src/ana/api/buffers.hpp
    trunk/src/ana/api/stats.hpp
    trunk/src/ana/src/asio_sender.cpp
    trunk/src/ana/src/asio_sender.hpp
    trunk/src/network_ana.cpp
    trunk/src/network_manager_ana.cpp

Modified: trunk/src/ana/api/buffers.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ana/api/buffers.hpp?rev=44153&r1=44152&r2=44153&view=diff
==============================================================================
--- trunk/src/ana/api/buffers.hpp (original)
+++ trunk/src/ana/api/buffers.hpp Wed Jul 14 00:44:06 2010
@@ -154,7 +154,7 @@
 
                 inline void*  base() const { return base_; }
 
-                inline void*  base_char() const { return 
reinterpret_cast<char*>(base_); }
+                inline char*  base_char() const { return 
reinterpret_cast<char*>(base_); }
 
                 ~copying_buffer()
                 {

Modified: trunk/src/ana/api/stats.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ana/api/stats.hpp?rev=44153&r1=44152&r2=44153&view=diff
==============================================================================
--- trunk/src/ana/api/stats.hpp (original)
+++ trunk/src/ana/api/stats.hpp Wed Jul 14 00:44:06 2010
@@ -90,6 +90,13 @@
                     bytes_out_ += buffer->size() + HEADER_LENGTH;
                 }
 
+                void log_send( size_t size, bool finished_packet = false )
+                {
+                    bytes_out_ += size;
+                    if (finished_packet)
+                        ++packets_out_;
+                }
+
                 void log_receive( detail::read_buffer buffer )
                 {
                     ++packets_in_;
@@ -209,6 +216,18 @@
                 log_current_packet_out(buffer->size(), true);
             }
 
+            void log_send( size_t size, bool finished_packet = false )
+            {
+                accumulator_.log_send  ( size, finished_packet );
+                seconds_stats_.log_send( size, finished_packet );
+                minutes_stats_.log_send( size, finished_packet );
+                hours_stats_.log_send  ( size, finished_packet );
+                days_stats_.log_send   ( size, finished_packet );
+
+                log_current_packet_out(size, finished_packet);
+            }
+
+
             void log_receive( detail::read_buffer buffer )
             {
                 accumulator_.log_receive  ( buffer );
@@ -257,7 +276,6 @@
                     current_packet_in_total_ += size;
                 }
             }
-
             void log_current_packet_out(size_t size, bool finished_packet)
             {
                 if (finished_packet)

Modified: trunk/src/ana/src/asio_sender.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ana/src/asio_sender.cpp?rev=44153&r1=44152&r2=44153&view=diff
==============================================================================
--- trunk/src/ana/src/asio_sender.cpp (original)
+++ trunk/src/ana/src/asio_sender.cpp Wed Jul 14 00:44:06 2010
@@ -48,13 +48,10 @@
 
         if ( raw_mode() )
         {
-            if ( stats_collector() != NULL )
-                stats_collector()->start_send_packet( buffer->size() );
-
-            boost::asio::async_write(socket, 
boost::asio::buffer(buffer->base(), buffer->size() ),
-                                     
boost::bind(&asio_sender::handle_send,this,
-                                                 
boost::asio::placeholders::error,
-                                                 buffer, handler, 
running_timer));
+            socket.async_write_some( boost::asio::buffer(buffer->base(), 
buffer->size() ),
+                                     
boost::bind(&asio_sender::handle_partial_send,this,
+                                                 buffer, 
boost::asio::placeholders::error,
+                                                 &socket, handler, 
running_timer, 0, _2 ));
         }
         else
         {
@@ -91,29 +88,59 @@
 {
     delete bos;
 
-    if ( ! ec )
-    {
-        boost::asio::async_write(*socket, 
boost::asio::buffer(buffer->base(), buffer->size() ),
-                                 boost::bind(&asio_sender::handle_send,this,
-                                             
boost::asio::placeholders::error,
-                                             buffer, handler, 
running_timer));
-
-    }
+    if ( ec )
+        handle_send(ec, handler, running_timer);
     else
     {
-        disconnect();
-        delete running_timer;
+        socket->async_write_some( boost::asio::buffer(buffer->base(), 
buffer->size() ),
+                                  
boost::bind(&asio_sender::handle_partial_send,this,
+                                              buffer, 
boost::asio::placeholders::error,
+                                              socket, handler, 
running_timer, 0, _2 ));
+    }
+}
+
+void asio_sender::handle_partial_send( ana::detail::shared_buffer       
buffer,
+                                       const boost::system::error_code& ec,
+                                       tcp::socket*                     
socket,
+                                       ana::send_handler*               
handler,
+                                       ana::timer*                      
timer,
+                                       size_t                           
accumulated,
+                                       size_t                           
last_msg_size)
+{
+    try
+    {
+        if (ec)
+            handle_send(ec, handler, timer);
+        else
+        {
+            accumulated += last_msg_size;
+
+            log_conditional_send( last_msg_size, accumulated == 
buffer->size() );
+
+            if ( accumulated > buffer->size() )
+                throw std::runtime_error("The send operation was too 
large.");
+
+            if ( accumulated == buffer->size() )
+                handle_send( ec, handler, timer );
+            else
+                
socket->async_write_some(boost::asio::buffer(buffer->base_char() + 
accumulated,
+                                                             buffer->size()  
    - accumulated),
+                                         
boost::bind(&asio_sender::handle_partial_send, this,
+                                                     buffer, 
boost::asio::placeholders::error,
+                                                     socket, handler, timer, 
accumulated, _2 ));
+        }
+    }
+    catch(const std::exception& e)
+    {
+        disconnect( );
     }
 }
 
 void asio_sender::handle_send(const boost::system::error_code& ec,
-                              ana::detail::shared_buffer       buffer,
                               ana::send_handler*               handler,
                               ana::timer*                      running_timer)
 {
     delete running_timer;
-
-    log_conditional_send( buffer );
 
     handler->handle_send( ec, id() );
 
@@ -121,16 +148,15 @@
         disconnect();
 }
 
-
-
 void asio_sender::handle_timeout(const boost::system::error_code& ec, 
ana::send_handler* handler)
 {
+    //TODO: check if I shouldn't just call handle_send here
     if ( ec != boost::asio::error::operation_aborted) // The timer wasn't 
cancelled. So: inform this and disconnect
         handler->handle_send( ana::timeout_error , id() );
 }
 
-void asio_sender::log_conditional_send( const ana::detail::shared_buffer& 
buf )
+void asio_sender::log_conditional_send( size_t size, bool finished )
 {
     if (stats_collector() != NULL )
-        stats_collector()->log_send( buf );
+        stats_collector()->log_send( size, finished );
 }

Modified: trunk/src/ana/src/asio_sender.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ana/src/asio_sender.hpp?rev=44153&r1=44152&r2=44153&view=diff
==============================================================================
--- trunk/src/ana/src/asio_sender.hpp (original)
+++ trunk/src/ana/src/asio_sender.hpp Wed Jul 14 00:44:06 2010
@@ -48,16 +48,26 @@
     private:
         void handle_sent_header(const boost::system::error_code& ec,
                                 ana::serializer::bostream*,
-                                tcp::socket*,               // for some 
reason noncopyable complains if it's a ref.
+                                tcp::socket*,
                                 ana::detail::shared_buffer,
                                 ana::send_handler*,
                                 ana::timer*);
 
-        void handle_send(const boost::system::error_code& ec, 
ana::detail::shared_buffer, ana::send_handler*, ana::timer*);
+        void handle_partial_send( ana::detail::shared_buffer,
+                                  const boost::system::error_code&,
+                                  tcp::socket*,
+                                  ana::send_handler*,
+                                  ana::timer*,
+                                  size_t accumulated,
+                                  size_t last_msg_size);
+
+        void handle_send(const boost::system::error_code&,
+                         ana::send_handler*,
+                         ana::timer*);
 
         void handle_timeout(const boost::system::error_code& ec, 
ana::send_handler* handler);
 
-        void log_conditional_send( const ana::detail::shared_buffer& buf );
+        void log_conditional_send( size_t size, bool finished );
 };
 
 #endif

Modified: trunk/src/network_ana.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_ana.cpp?rev=44153&r1=44152&r2=44153&view=diff
==============================================================================
--- trunk/src/network_ana.cpp (original)
+++ trunk/src/network_ana.cpp Wed Jul 14 00:44:06 2010
@@ -275,6 +275,9 @@
 //         std::cout << "DEBUG: Trying to read from connection in " << 
timeout << " milliseconds.\n";
         network::connection read_id = ana_manager.read_from( connection_num, 
cfg, timeout );
 
+        if ( read_id != 0 )
+            std::cout << "Read: " << cfg << "\n";
+
         // TODO: check timeout and return 0, or throw if error occured
 
         return read_id;
@@ -453,6 +456,7 @@
                        connection         connection_num,
                        const std::string& /*packet_type*/)
     {
+        std::cout << "DEBUG: Sending Raw: " << std::string( buf, len ) << 
"\n";
         ana_manager.send_raw_data( buf, size_t( len ), connection_num );
     }
 
@@ -467,6 +471,7 @@
                               const bool          /*gzipped*/,
                               const std::string&  /*packet_type*/)
     {
+        std::cout << "DEBUG: Sending all except " << connection_num << " - " 
<< cfg << "\n";
         ana_manager.send_all_except(cfg, connection_num);
     }
 

Modified: trunk/src/network_manager_ana.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_manager_ana.cpp?rev=44153&r1=44152&r2=44153&view=diff
==============================================================================
--- trunk/src/network_manager_ana.cpp (original)
+++ trunk/src/network_manager_ana.cpp Wed Jul 14 00:44:06 2010
@@ -871,9 +871,10 @@
             if ((*it)->is_server())
             {
                 // TODO: The next lines shouldn't be commented, no way the 
handler isn't called
-//                 ana_send_handler handler( size );
-                (*it)->server()->send_one( id, ana::buffer( base_char, size 
), this, ana::ZERO_COPY);
-//                 handler.wait_completion();
+                ana_send_handler handler( size );
+//                 (*it)->server()->send_one( id, ana::buffer( base_char, 
size ), this, ana::ZERO_COPY);
+                (*it)->server()->send_one( id, ana::buffer( base_char, size 
), &handler, ana::ZERO_COPY);
+                handler.wait_completion();
 //                 if ( handler.error() )
 //                     return 0;
 //                 else




Related Messages


Powered by MHonArc, Updated Wed Jul 14 05:20:10 2010