mail[Wesnoth-commits] r28343 - in /trunk/src: campaign_server/campaign_server.cpp network.cpp network_worker.cpp


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

Header


Content

Posted by paniemin on August 06, 2008 - 16:06:
Author: suokko
Date: Wed Aug  6 16:06:08 2008
New Revision: 28343

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28343&view=rev
Log:
Added send size to campaignd log

Modified:
    trunk/src/campaign_server/campaign_server.cpp
    trunk/src/network.cpp
    trunk/src/network_worker.cpp

Modified: trunk/src/campaign_server/campaign_server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/campaign_server/campaign_server.cpp?rev=28343&r1=28342&r2=28343&view=diff
==============================================================================
--- trunk/src/campaign_server/campaign_server.cpp (original)
+++ trunk/src/campaign_server/campaign_server.cpp Wed Aug  6 16:06:08 2008
@@ -376,20 +376,23 @@
                                                
response.add_child("campaigns",campaign_list);
                                                network::send_data(response, 
sock, gzipped);
                                        } else if(const config* req = 
data.child("request_campaign")) {
-                                               LOG_CS << "sending campaign 
'" << (*req)["name"] << "' to " << network::ip_address(sock)  << (gzipped?" 
using gzip":"") << "\n";
+                                               LOG_CS << "sending campaign 
'" << (*req)["name"] << "' to " << network::ip_address(sock)  << (gzipped?" 
using gzip":"");
                                                config* const campaign = 
campaigns().find_child("campaign","name",(*req)["name"]);
                                                if(campaign == NULL) {
                                                        
network::send_data(construct_error("Add-on '" + (*req)["name"] + "'not 
found."), sock, gzipped);
                                                } else {
                                                        if (gzipped)
                                                        {
+                                                               std::cerr << 
" size: " << (file_size((*campaign)["filename"])/1024) << "kb\n";
                                                                
network::send_file((*campaign)["filename"], sock);
                                                        } else {
                                                                
scoped_istream stream = istream_file((*campaign)["filename"]);
                                                                config cfg;
                                                                read_gz(cfg, 
*stream);
-                                                               
network::send_data(cfg, sock, false);
-                                                       }
+                                                               std::cerr << 
" size: " << 
+                                                                       
(network::send_data(cfg, sock, false)/1024)
+                                                                       << 
"kb\n";
+                                                       }
                                                        const int downloads = 
lexical_cast_default<int>((*campaign)["downloads"],0)+1;
                                                        
(*campaign)["downloads"] = lexical_cast<std::string>(downloads);
                                                }

Modified: trunk/src/network.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network.cpp?rev=28343&r1=28342&r2=28343&view=diff
==============================================================================
--- trunk/src/network.cpp (original)
+++ trunk/src/network.cpp Wed Aug  6 16:06:08 2008
@@ -871,38 +871,39 @@
 //! @todo Note the gzipped parameter should be removed later, we want to send
 //! all data gzipped. This can be done once the campaign server is also 
updated
 //! to work with gzipped data.
-void send_data(const config& cfg, connection connection_num, const bool 
gzipped)
+size_t send_data(const config& cfg, connection connection_num, const bool 
gzipped)
 {
        DBG_NW << "in send_data()...\n";
        
        if(cfg.empty()) {
-               return;
+               return 0;
        }
 
        if(bad_sockets.count(connection_num) || bad_sockets.count(0)) {
-               return;
+               return 0;
        }
 
 //     log_scope2(network, "sending data");
        if(!connection_num) {
                DBG_NW << "sockets: " << sockets.size() << "\n";
+               size_t size;
                for(sockets_list::const_iterator i = sockets.begin();
                    i != sockets.end(); ++i) {
                        DBG_NW << "server socket: " << server_socket << 
"\ncurrent socket: " << *i << "\n";
-                       send_data(cfg,*i, gzipped);
-               }
-               return;
+                       size = send_data(cfg,*i, gzipped);
+               }
+               return size;
        }
 
        const connection_map::iterator info = 
connections.find(connection_num);
        if (info == connections.end()) {
                ERR_NW << "Error: socket: " << connection_num
                        << "\tnot found in connection_map. Not sending...\n";
-               return;
+               return 0;
        }
 
        LOG_NW << "SENDING to: " << connection_num << ": " << cfg;
-       network_worker_pool::queue_data(info->second.sock, cfg, gzipped);
+       return network_worker_pool::queue_data(info->second.sock, cfg, 
gzipped);
 }
 
 void send_raw_data(const char* buf, int len, connection connection_num)

Modified: trunk/src/network_worker.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.cpp?rev=28343&r1=28342&r2=28343&view=diff
==============================================================================
--- trunk/src/network_worker.cpp (original)
+++ trunk/src/network_worker.cpp Wed Aug  6 16:06:08 2008
@@ -500,6 +500,8 @@
        // default sendfile implementation 
        // if no system implementation is enabled
        int send_size = 0;
+       // reserve 1024*8 bytes buffer
+       buf->raw_buffer.resize(minimum<size_t>(1024*8, filesize));
        SDLNet_Write32(filesize,&buf->raw_buffer[0]);
        scoped_istream file_stream = istream_file(buf->config_error);
        SOCKET_STATE result = send_buffer(buf->sock, buf->raw_buffer, 4);
@@ -938,23 +940,20 @@
 {
        buffer* queued_buf = new buffer(sock);
        queued_buf->config_error = filename;
-#ifndef USE_SENDFILE
-       // We reserve buffer in main thread
-       // this helps in memory problems with threads
-       // We use 8KB buffer
-       queued_buf->raw_buffer.resize(1024*8);
-#endif
        queue_buffer(sock, queued_buf);
 }
  
-void queue_data(TCPsocket sock,const  config& buf, const bool gzipped)
+size_t queue_data(TCPsocket sock,const  config& buf, const bool gzipped)
 {
        DBG_NW << "queuing data...\n";
 
        buffer* queued_buf = new buffer(sock);
        output_to_buffer(sock, buf, queued_buf->stream, gzipped);
        queued_buf->gzipped = gzipped;
+       const size_t size = queued_buf->stream.str().size();
+
        queue_buffer(sock, queued_buf);
+       return size;
 }
 
 namespace




Related Messages


Powered by MHonArc, Updated Wed Aug 06 16:21:15 2008