Author: suokko
Date: Wed Jun 11 21:13:08 2008
New Revision: 27104

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27104&view=rev
Log:
Fixed receive_with_timeout not to use SDL_GetTicks()
Fixed unused variable warning

Modified:
    trunk/src/network_worker.cpp

Modified: trunk/src/network_worker.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.cpp?rev=27104&r1=27103&r2=27104&view=diff
==============================================================================
--- trunk/src/network_worker.cpp (original)
+++ trunk/src/network_worker.cpp Wed Jun 11 21:13:08 2008
@@ -208,8 +208,10 @@
 bool receive_with_timeout(TCPsocket s, char* buf, size_t nbytes,
                bool update_stats=false, int timeout_ms=60000)
 {
+#if !defined(USE_POLL) && !defined(USE_SELECT) 
        int startTicks = SDL_GetTicks();
        int time_used = 0;
+#endif
        while(nbytes > 0) {
                const int bytes_read = receive_bytes(s, buf, nbytes);
                if(bytes_read == 0) {
@@ -224,37 +226,37 @@
                        if(true)
 #endif
                        {
+#ifdef USE_POLL
+                               struct pollfd fd = { ((_TCPsocket*)s)->channel, 
POLLIN, 0 };
+                               int poll_res;
+                               do {
+                                       poll_res = poll(&fd, 1, timeout_ms);
+                               } while(poll_res == -1 && errno == EINTR);
+
+                               if (poll_res < 1)
+                                       return false;
+#elif defined(USE_SELECT)
+                               fd_set readfds;
+                               FD_ZERO(&readfds);
+                               FD_SET(((_TCPsocket*)s)->channel, &readfds);
+                               int retval;
+                               struct timeval tv;
+
+                               tv.tv_sec = timeout_ms/1000;
+                               tv.tv_usec = timeout_ms % 1000;
+                               do {
+                                       retval = 
select(((_TCPsocket*)s)->channel + 1, &readfds, NULL, NULL, &tv);
+                               } while(retval == -1 && errno == EINTR);
+
+                               if (retval < 1)
+                                       return false;
+#elif
                                //TODO: consider replacing this with a select 
call
                                time_used = SDL_GetTicks() - startTicks;
                                if(time_used >= timeout_ms) {
                                        return false;
                                }
-#ifdef USE_POLL
-                               struct pollfd fd = { ((_TCPsocket*)s)->channel, 
POLLIN, 0 };
-                               int poll_res;
-                               do {
-                                       time_used = SDL_GetTicks() - startTicks;
-                                       poll_res = poll(&fd, 1, timeout_ms - 
time_used);
-                               } while(poll_res == -1 && errno == EINTR);
-
-#elif defined(USE_SELECT)
-                               fd_set readfds;
-                               FD_ZERO(&readfds);
-                               FD_SET(((_TCPsocket*)s)->channel, &readfds);
-                               int retval;
-                               int time_left;
-                               struct timeval tv;
-
-                               do {
-                                       time_used = SDL_GetTicks() - startTicks;
-                                       time_left = timeout_ms - time_used;
-                                       tv.tv_sec = time_left/1000;
-                                       tv.tv_usec = time_left % 1000;
-                                       retval = 
select(((_TCPsocket*)s)->channel + 1, &readfds, NULL, NULL, &tv);
-                               } while(retval == -1 && errno == EINTR);
-
-#elif
-                               SDL_Delay(5);
+                               SDL_Delay(20);
 #endif
                        } else {
                                return false;
@@ -272,7 +274,9 @@
                        }
                        nbytes -= bytes_read;
                        // We got some data from server so reset start time so 
slow conenction won't timeout.
+#if !defined(USE_POLL) && !defined(USE_SELECT) 
                        startTicks = SDL_GetTicks();
+#endif
                }
        }
 
@@ -404,7 +408,6 @@
 static SOCKET_STATE send_file(buffer* buf)
 {
        size_t upto = 0;
-       int send_size = 0;
        size_t filesize = file_size(buf->config_error);
 #ifdef USE_SENDFILE
        std::vector<char> buffer;
@@ -436,6 +439,7 @@
        }
        result = SOCKET_READY;
 #else
+       int send_size = 0;
        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);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to