[Top][All Lists]
[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, 04 Aug 2005 18:43:19 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Jon Daniel <address@hidden> 05/08/04 22:43:19
Modified files:
src : network_worker.cpp
Log message:
Factor send_buf code.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network_worker.cpp.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
Patches:
Index: wesnoth/src/network_worker.cpp
diff -u wesnoth/src/network_worker.cpp:1.33 wesnoth/src/network_worker.cpp:1.34
--- wesnoth/src/network_worker.cpp:1.33 Thu Aug 4 22:05:12 2005
+++ wesnoth/src/network_worker.cpp Thu Aug 4 22:43:19 2005
@@ -1,4 +1,4 @@
-/* $Id: network_worker.cpp,v 1.33 2005/08/04 22:05:12 j_daniel Exp $ */
+/* $Id: network_worker.cpp,v 1.34 2005/08/04 22:43:19 j_daniel Exp $ */
/*
Copyright (C) 2003-5 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -64,6 +64,33 @@
std::vector<threading::thread*> threads;
+SOCKET_STATE send_buf(TCPsocket sock, std::vector<char>& buf) {
+ size_t upto = 0;
+ size_t size = buf.size();
+
+ current_transfer_stats.first = 0;
+ current_transfer_stats.second = static_cast<int>(size);
+
+ while(upto < size) {
+ {
+ // check if the socket is still locked
+ const threading::lock lock(*global_mutex);
+ if(sockets_locked[sock] != SOCKET_LOCKED)
+ return SOCKET_ERROR;
+ }
+ const int bytes_to_send = static_cast<int>(size - upto);
+ const int res = SDLNet_TCP_Send(sock, &buf[upto],
bytes_to_send);
+
+ current_transfer_stats.first += res;
+
+ if(res < 0 || res != bytes_to_send && errno != EAGAIN)
+ return SOCKET_ERROR;
+
+ upto += res;
+ }
+ return SOCKET_READY;
+}
+
SOCKET_STATE receive_buf(TCPsocket sock, std::vector<char>& buf)
{
char num_buf[4];
@@ -171,25 +198,7 @@
std::vector<char> buf;
if(sent_buf != NULL) {
- std::vector<char> &v = sent_buf->buf;
- for(size_t upto = 0, size = v.size(); result !=
SOCKET_ERROR && upto < size; ) {
- {
- // check if the socket is still locked
- const threading::lock
lock(*global_mutex);
- if(sockets_locked[sent_buf->sock] !=
SOCKET_LOCKED) {
- result = SOCKET_ERROR;
- break;
- }
- }
- const int bytes_to_send = int(size - upto);
- const int res = SDLNet_TCP_Send(sent_buf->sock,
&v[upto], bytes_to_send);
- if(res < 0 || res != bytes_to_send && errno !=
EAGAIN) {
- result = SOCKET_ERROR;
- } else {
- upto += res;
- }
- }
-
+ result = send_buf(sent_buf->sock, sent_buf->buf);
delete sent_buf;
sent_buf = NULL;
} else {
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/04
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp,
Jon Daniel <=
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/04
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/05
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/05
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/05
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/06
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/07
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/18
- [Wesnoth-cvs-commits] wesnoth/src network_worker.cpp, Jon Daniel, 2005/08/19