mail[Wesnoth-commits] r43995 - in /trunk/src: network_ana.cpp network_manager_ana.cpp


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

Header


Content

Posted by billybiset on July 08, 2010 - 05:36:
Author: billynux
Date: Thu Jul  8 05:36:05 2010
New Revision: 43995

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43995&view=rev
Log:
Fixed an issue while trying to compress a config before sending in ana, it 
now gets to the lobby.

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

Modified: trunk/src/network_ana.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_ana.cpp?rev=43995&r1=43994&r2=43995&view=diff
==============================================================================
--- trunk/src/network_ana.cpp (original)
+++ trunk/src/network_ana.cpp Thu Jul  8 05:36:05 2010
@@ -291,12 +291,13 @@
         }
     }
 
-    connection receive_data(config&           /*cfg*/,
-                            connection        /*connection_num*/,
+    connection receive_data(config&           cfg,
+                            connection        connection_num,
                             bool*             /*gzipped*/,
                             bandwidth_in_ptr* /*bandwidth_in*/)
     {
-        throw std::runtime_error("TODO:Not implemented receive_data1");
+        return receive_data(cfg,connection_num, size_t(0), NULL); // <- just 
call the previous version
+//         throw std::runtime_error("TODO:Not implemented receive_data1");
     }
 
     connection receive_data(std::vector<char>& /*buf*/, bandwidth_in_ptr* 
/*bandwidth_in*/)
@@ -450,6 +451,8 @@
         if(cfg.empty())
             return 0;
 
+        std::cout << "DEBUG: Sending: " << cfg << "\n";
+
         if( connection_num == 0 )
             return ana_manager.send_all( cfg, gzipped );
         else

Modified: trunk/src/network_manager_ana.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_manager_ana.cpp?rev=43995&r1=43994&r2=43995&view=diff
==============================================================================
--- trunk/src/network_manager_ana.cpp (original)
+++ trunk/src/network_manager_ana.cpp Thu Jul  8 05:36:05 2010
@@ -20,6 +20,10 @@
 #include <iostream>
 
 #include <boost/bind.hpp>
+#include <boost/iostreams/filtering_stream.hpp>
+#include <boost/iostreams/filter/gzip.hpp>
+
+#include "serialization/parser.hpp"
 
 #include "network_manager_ana.hpp"
 #include "serialization/binary_or_text.hpp"
@@ -429,7 +433,45 @@
 
 size_t ana_network_manager::send_all( const config& cfg, bool zipped )
 {
-    std::cout << "DEBUG: Sending to everybody...\n";
+    std::cout << "DEBUG: Sending to everybody. " << (zipped ? 
"Zipped":"Raw") << "\n";
+
+    std::ostringstream out;
+    {
+        boost::iostreams::filtering_stream<boost::iostreams::output> filter;
+        filter.push(boost::iostreams::gzip_compressor());
+        filter.push(out);
+        write(filter, cfg);
+    }
+
+    std::set<ana_component*>::iterator it;
+
+    for (it = components_.begin(); it != components_.end(); ++it)
+    {
+        if ( (*it)->is_server() )
+        {
+            const size_t necessary_calls = server_manager_[ (*it)->server() 
]->client_amount();
+            ana_send_handler handler( *it, out.str().size(), necessary_calls 
);
+
+            (*it)->server()->send_all( ana::buffer( out.str() ), &handler, 
ana::ZERO_COPY);
+            handler.wait_completion(); // the handler will release the mutex 
after necessary_calls calls
+        }
+        else
+        {
+            ana_send_handler handler( *it, out.str().size() );
+
+            (*it)->client()->send( ana::buffer( out.str() ), &handler, 
ana::ZERO_COPY );
+            handler.wait_completion(); // the handler will release the mutex 
after necessary_calls calls
+        }
+    }
+    std::cout << "Sent data.\n";
+    return out.str().size();
+}
+
+size_t ana_network_manager::send( network::connection connection_num , const 
config& cfg, bool zipped )
+{
+    std::cout << "DEBUG: Single send...\n";
+    ana::net_id id( connection_num );
+
     std::stringstream out;
     config_writer cfg_writer(out, zipped);
     cfg_writer.write(cfg);
@@ -440,33 +482,6 @@
     {
         if ( (*it)->is_server() )
         {
-            const size_t necessary_calls = server_manager_[ (*it)->server() 
]->client_amount();
-
-            ana_send_handler handler( *it, out.str().size(), necessary_calls 
);
-
-            (*it)->server()->send_all( ana::buffer( out.str() ), &handler, 
ana::ZERO_COPY);
-
-            handler.wait_completion(); // the handler will release the mutex 
after necessary_calls calls
-        }
-    }
-    return out.str().size();
-}
-
-size_t ana_network_manager::send( network::connection connection_num , const 
config& cfg, bool zipped )
-{
-    std::cout << "DEBUG: Single send...\n";
-    ana::net_id id( connection_num );
-
-    std::stringstream out;
-    config_writer cfg_writer(out, zipped);
-    cfg_writer.write(cfg);
-
-    std::set<ana_component*>::iterator it;
-
-    for (it = components_.begin(); it != components_.end(); ++it)
-    {
-        if ( (*it)->is_server() )
-        {
             ana_send_handler handler( *it, out.str().size() );
             (*it)->server()->send_one( id, ana::buffer( out.str() ), 
&handler, ana::ZERO_COPY);
 




Related Messages


Powered by MHonArc, Updated Thu Jul 08 19:00:14 2010