- Additional bug fixes related to network connection code for win32

- print out socket errors to console instead of throw exceptions
This commit is contained in:
Mark Vejvoda
2010-02-21 03:48:05 +00:00
parent 0d53988e99
commit 7657b40a4b
5 changed files with 927 additions and 775 deletions

View File

@@ -141,7 +141,9 @@ void ClientInterface::updateLobby()
{ {
if(networkMessageIntro.getVersionString()!=getNetworkVersionString()) if(networkMessageIntro.getVersionString()!=getNetworkVersionString())
{ {
throw runtime_error("Server and client versions do not match (" + networkMessageIntro.getVersionString() + "). You have to use the same binaries."); string sErr = "Server and client versions do not match (" + networkMessageIntro.getVersionString() + "). You have to use the same binaries.";
printf("%s\n",sErr.c_str());
//throw runtime_error("Server and client versions do not match (" + networkMessageIntro.getVersionString() + "). You have to use the same binaries.");
} }
} }
@@ -482,7 +484,9 @@ void ClientInterface::waitUntilReady(Checksum* checksum)
{ {
if(networkMessageReady.getChecksum() != checksum->getSum()) if(networkMessageReady.getChecksum() != checksum->getSum())
{ {
throw runtime_error("Checksum error, you don't have the same data as the server"); string sErr = "Checksum error, you don't have the same data as the server";
//throw runtime_error("Checksum error, you don't have the same data as the server");
printf("%s\n",sErr.c_str());
} }
} }

View File

@@ -1,110 +1,113 @@
// ============================================================== // ==============================================================
// This file is part of Glest Shared Library (www.glest.org) // This file is part of Glest Shared Library (www.glest.org)
// //
// Copyright (C) 2001-2008 Marti<74>o Figueroa // Copyright (C) 2001-2008 Marti<74>o Figueroa
// //
// You can redistribute this code and/or modify it under // You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published // the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the // by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version // License, or (at your option) any later version
// ============================================================== // ==============================================================
#ifndef _SHARED_PLATFORM_SOCKET_H_ #ifndef _SHARED_PLATFORM_SOCKET_H_
#define _SHARED_PLATFORM_SOCKET_H_ #define _SHARED_PLATFORM_SOCKET_H_
#include <string> #include <string>
#include <winsock.h> #include <winsock.h>
#include <map> #include <map>
using std::string; using std::string;
namespace Shared{ namespace Platform{ const char* WSAGetLastErrorMessage(const char* pcMessagePrefix,int nErrorID = 0);
// ===================================================== namespace Shared{ namespace Platform{
// class IP
// ===================================================== // =====================================================
// class IP
class Ip{ // =====================================================
private:
unsigned char bytes[4]; class Ip{
private:
public: unsigned char bytes[4];
Ip();
Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3); public:
Ip(const string& ipString); Ip();
Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3);
unsigned char getByte(int byteIndex) {return bytes[byteIndex];} Ip(const string& ipString);
string getString() const;
}; unsigned char getByte(int byteIndex) {return bytes[byteIndex];}
string getString() const;
// ===================================================== };
// class Socket
// ===================================================== // =====================================================
// class Socket
class Socket{ // =====================================================
private:
class SocketManager{ class Socket{
public: private:
SocketManager(); class SocketManager{
~SocketManager(); public:
}; SocketManager();
~SocketManager();
protected: };
static SocketManager socketManager;
SOCKET sock; protected:
static SocketManager socketManager;
public: SOCKET sock;
Socket(SOCKET sock);
Socket(); public:
~Socket(); Socket(SOCKET sock);
Socket();
static bool enableDebugText; ~Socket();
// Int lookup is socket fd while bool result is whether or not that socket was signalled for reading static bool enableDebugText;
static bool hasDataToRead(std::map<int,bool> &socketTriggeredList);
static bool hasDataToRead(int socket); // Int lookup is socket fd while bool result is whether or not that socket was signalled for reading
bool hasDataToRead(); static bool hasDataToRead(std::map<int,bool> &socketTriggeredList);
void disconnectSocket(); static bool hasDataToRead(int socket);
bool hasDataToRead();
int getSocketId() const { return sock; } void disconnectSocket();
int getDataToRead(); int getSocketId() const { return sock; }
int send(const void *data, int dataSize);
int receive(void *data, int dataSize); int getDataToRead();
int peek(void *data, int dataSize); int send(const void *data, int dataSize);
int receive(void *data, int dataSize);
void setBlock(bool block); int peek(void *data, int dataSize);
bool isReadable();
bool isWritable(bool waitOnDelayedResponse); void setBlock(bool block);
bool isConnected(); bool isReadable();
bool isWritable(bool waitOnDelayedResponse);
string getHostName() const; bool isConnected();
string getIp() const;
string getHostName() const;
protected: string getIp() const;
static void throwException(const string &str);
}; protected:
static void throwException(const string &str);
// =====================================================
// class ClientSocket };
// =====================================================
// =====================================================
class ClientSocket: public Socket{ // class ClientSocket
public: // =====================================================
void connect(const Ip &ip, int port);
}; class ClientSocket: public Socket{
public:
// ===================================================== void connect(const Ip &ip, int port);
// class ServerSocket };
// =====================================================
// =====================================================
class ServerSocket: public Socket{ // class ServerSocket
public: // =====================================================
void bind(int port);
void listen(int connectionQueueSize= SOMAXCONN); class ServerSocket: public Socket{
Socket *accept(); public:
}; void bind(int port);
void listen(int connectionQueueSize= SOMAXCONN);
}}//end namespace Socket *accept();
};
#endif
}}//end namespace
#endif

View File

@@ -235,9 +235,9 @@ int Socket::getDataToRead(){
if(err < 0 && errno != EAGAIN) if(err < 0 && errno != EAGAIN)
{ {
char szBuf[1024]=""; char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s] ERROR PEEKING SOCKET DATA, err = %d errno = %d [%s]",__FILE__,__FUNCTION__,err,errno,strerror(errno)); sprintf(szBuf,"In [%s::%s] ERROR PEEKING SOCKET DATA, err = %d errno = %d [%s]\n",__FILE__,__FUNCTION__,err,errno,strerror(errno));
//throwException(szBuf);
throwException(szBuf); printf("%s",szBuf);
} }
else if(err == 0) else if(err == 0)
{ {
@@ -257,9 +257,9 @@ int Socket::send(const void *data, int dataSize) {
if(bytesSent < 0 && errno != EAGAIN) if(bytesSent < 0 && errno != EAGAIN)
{ {
char szBuf[1024]=""; char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s] ERROR WRITING SOCKET DATA, err = %d errno = %d [%s]",__FILE__,__FUNCTION__,bytesSent,errno,strerror(errno)); sprintf(szBuf,"In [%s::%s] ERROR WRITING SOCKET DATA, err = %d errno = %d [%s]\n",__FILE__,__FUNCTION__,bytesSent,errno,strerror(errno));
//throwException(szBuf);
throwException(szBuf); printf("%s",szBuf);
} }
else if(bytesSent < 0 && errno == EAGAIN) else if(bytesSent < 0 && errno == EAGAIN)
{ {
@@ -304,8 +304,8 @@ int Socket::receive(void *data, int dataSize)
{ {
char szBuf[1024]=""; char szBuf[1024]="";
sprintf(szBuf,"[%s::%s] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, errno = %d [%s]\n",__FILE__,__FUNCTION__,bytesReceived,errno,strerror(errno)); sprintf(szBuf,"[%s::%s] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, errno = %d [%s]\n",__FILE__,__FUNCTION__,bytesReceived,errno,strerror(errno));
//throwException(szBuf);
throwException(szBuf); printf("%s",szBuf);
} }
else if(bytesReceived < 0 && errno == EAGAIN) else if(bytesReceived < 0 && errno == EAGAIN)
{ {
@@ -346,8 +346,9 @@ int Socket::peek(void *data, int dataSize){
{ {
char szBuf[1024]=""; char szBuf[1024]="";
sprintf(szBuf,"[%s::%s] ERROR PEEKING SOCKET DATA error while sending socket data, bytesSent = %d, errno = %d [%s]\n",__FILE__,__FUNCTION__,err,errno,strerror(errno)); sprintf(szBuf,"[%s::%s] ERROR PEEKING SOCKET DATA error while sending socket data, bytesSent = %d, errno = %d [%s]\n",__FILE__,__FUNCTION__,err,errno,strerror(errno));
//throwException(szBuf);
throwException(szBuf); disconnectSocket();
} }
else if(err < 0 && errno == EAGAIN) else if(err < 0 && errno == EAGAIN)
{ {

View File

@@ -454,6 +454,8 @@ void exceptionMessage(const exception &excp){
message+= excp.what(); message+= excp.what();
title= "Error: Unhandled Exception"; title= "Error: Unhandled Exception";
printf("Error detected with text: %s\n",message.c_str());
MessageBox(NULL, message.c_str(), title.c_str(), MB_ICONSTOP | MB_OK | MB_TASKMODAL); MessageBox(NULL, message.c_str(), title.c_str(), MB_ICONSTOP | MB_OK | MB_TASKMODAL);
} }

File diff suppressed because it is too large Load Diff