wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src network_worker.cpp


From: Jon Daniel
Subject: [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp
Date: Thu, 18 Aug 2005 13:39:36 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Jon Daniel <address@hidden>     05/08/18 17:39:36

Modified files:
        src            : network_worker.cpp 

Log message:
        make send non-blocking aware

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network_worker.cpp.diff?tr1=1.42&tr2=1.43&r1=text&r2=text

Patches:
Index: wesnoth/src/network_worker.cpp
diff -u wesnoth/src/network_worker.cpp:1.42 wesnoth/src/network_worker.cpp:1.43
--- wesnoth/src/network_worker.cpp:1.42 Wed Aug 17 20:37:20 2005
+++ wesnoth/src/network_worker.cpp      Thu Aug 18 17:39:36 2005
@@ -1,4 +1,4 @@
-/* $Id: network_worker.cpp,v 1.42 2005/08/17 20:37:20 j_daniel Exp $ */
+/* $Id: network_worker.cpp,v 1.43 2005/08/18 17:39:36 j_daniel Exp $ */
 /*
    Copyright (C) 2003-5 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -65,6 +65,7 @@
 std::vector<threading::thread*> threads;
 
 SOCKET_STATE send_buf(TCPsocket sock, std::vector<char>& buf) {
+       int timeout = 15000;
        size_t upto = 0;
        size_t size = buf.size();
        {
@@ -72,7 +73,7 @@
                transfer_stats[sock].first.fresh_current(size);
        }
 
-       while(upto < size) {
+       while(upto < size && timeout > 0) {
                {
                        // check if the socket is still locked
                        const threading::lock lock(*global_mutex);
@@ -82,9 +83,26 @@
                const int bytes_to_send = static_cast<int>(size - upto);
                const int res = SDLNet_TCP_Send(sock, &buf[upto], 
bytes_to_send);
 
-               if(res < 0 || res != bytes_to_send && errno != EAGAIN)
+               if(res == -1) {
+#ifdef EAGAIN
+                       if(errno == EAGAIN) {
+                               SDL_Delay(100);
+                               timeout -= 100;
+                               continue;
+                       }
+#elif defined(EWOULDBLOCK)
+                       if(errno == EWOULDBLOCK) {
+                               SDL_Delay(100);
+                               timeout -= 100;
+                               continue;
+                       }
+#endif
                        return SOCKET_ERROR;
-
+               }
+               if(res != bytes_to_send) {
+                       return SOCKET_ERROR;
+               }
+               timeout = 15000;
                upto += static_cast<size_t>(res);
                {
                        const threading::lock lock(*global_mutex);
@@ -166,9 +184,7 @@
                beg += res;
                {
                        const threading::lock lock(*global_mutex);
-                       network::statistics& stats = 
transfer_stats[sock].second;
-                       stats.total += res;
-                       stats.current += res;
+                       
transfer_stats[sock].second.transfer(static_cast<size_t>(res));
                }
        }
        SDLNet_TCP_DelSocket(set, sock);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]