summaryrefslogtreecommitdiff
path: root/src/net/network.cpp
diff options
context:
space:
mode:
authorCedric Borgese <cedric.borgese@gmail.com>2005-09-27 13:31:15 +0000
committerCedric Borgese <cedric.borgese@gmail.com>2005-09-27 13:31:15 +0000
commit8225942307f8290e5941cdeaff5c7b212f978390 (patch)
treea60d0efb5eaeec89a002d8a58ee485de190e8615 /src/net/network.cpp
parentd56c142c43939657df13f3b7246defe8f181306e (diff)
downloadmana-8225942307f8290e5941cdeaff5c7b212f978390.tar.gz
mana-8225942307f8290e5941cdeaff5c7b212f978390.tar.bz2
mana-8225942307f8290e5941cdeaff5c7b212f978390.tar.xz
mana-8225942307f8290e5941cdeaff5c7b212f978390.zip
Dont crash if there is an unknown error at login.
Remove a bug that do x86_64 arch fail to connect to server : long is 8 bytes on that arch, use int for 4 bytes integer.
Diffstat (limited to 'src/net/network.cpp')
-rw-r--r--src/net/network.cpp35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/net/network.cpp b/src/net/network.cpp
index 6f852529..6e3b6c6c 100644
--- a/src/net/network.cpp
+++ b/src/net/network.cpp
@@ -204,13 +204,31 @@ void close_session()
void flush()
{
+ // Send all available data, waits if not all data can be sent immediately
+ if (out_size > 0)
+ {
+ int ret = SDLNet_TCP_Send(sock, (char*)out, out_size);
+ if (ret < (int)out_size)
+ {
+ logger->log("Error in SDLNet_TCP_Send(): %s", SDLNet_GetError());
+ errorMessage = "You got disconnected from server";
+ state = ERROR_STATE;
+ return;
+ }
+ out_size -= ret;
+ }
+
int numReady = SDLNet_CheckSockets(set, 0);
if (numReady == -1)
{
logger->log("Error: SDLNet_CheckSockets");
return;
}
- else if (numReady)
+ else if (numReady == 0) // any socket ready
+ {
+ return;
+ }
+ else if (numReady == 1) // one socket is ready
{
// Receive data from the socket
int ret = SDLNet_TCP_Recv(sock, in + in_size, buffer_size - in_size);
@@ -225,19 +243,12 @@ void flush()
in_size += ret;
}
}
-
- // Send all available data, waits if not all data can be sent immediately
- if (out_size > 0)
+ else // more than one socket is ready.. this should not happen since we only listen once socket.
{
- int ret = SDLNet_TCP_Send(sock, (char*)out, out_size);
- if (ret < (int)out_size)
- {
- logger->log("Error in SDLNet_TCP_Send(): %s", SDLNet_GetError());
+ logger->log("Error in SDLNet_TCP_Recv(), %d sockets are ready : %s", numReady, SDLNet_GetError());
errorMessage = "You got disconnected from server";
state = ERROR_STATE;
return;
- }
- out_size -= ret;
}
}
@@ -254,7 +265,7 @@ MessageIn
get_next_message()
{
// At least 2 bytes should be received for the message ID
- while (in_size < 2) flush();
+ while (in_size < 2 && state != ERROR_STATE) flush();
int length = packet_lengths[readWord(0)];
@@ -270,7 +281,7 @@ get_next_message()
#endif
// Make sure the whole packet is received
- while (in_size < (unsigned int)length) flush();
+ while (in_size < static_cast<unsigned int>(length) && state != ERROR_STATE) flush();
return MessageIn(in, length);
}