- 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:
parent
0d53988e99
commit
7657b40a4b
|
@ -141,7 +141,9 @@ void ClientInterface::updateLobby()
|
|||
{
|
||||
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())
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,110 +1,113 @@
|
|||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_SOCKET_H_
|
||||
#define _SHARED_PLATFORM_SOCKET_H_
|
||||
|
||||
#include <string>
|
||||
#include <winsock.h>
|
||||
#include <map>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class IP
|
||||
// =====================================================
|
||||
|
||||
class Ip{
|
||||
private:
|
||||
unsigned char bytes[4];
|
||||
|
||||
public:
|
||||
Ip();
|
||||
Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3);
|
||||
Ip(const string& ipString);
|
||||
|
||||
unsigned char getByte(int byteIndex) {return bytes[byteIndex];}
|
||||
string getString() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Socket
|
||||
// =====================================================
|
||||
|
||||
class Socket{
|
||||
private:
|
||||
class SocketManager{
|
||||
public:
|
||||
SocketManager();
|
||||
~SocketManager();
|
||||
};
|
||||
|
||||
protected:
|
||||
static SocketManager socketManager;
|
||||
SOCKET sock;
|
||||
|
||||
public:
|
||||
Socket(SOCKET sock);
|
||||
Socket();
|
||||
~Socket();
|
||||
|
||||
static bool enableDebugText;
|
||||
|
||||
// Int lookup is socket fd while bool result is whether or not that socket was signalled for reading
|
||||
static bool hasDataToRead(std::map<int,bool> &socketTriggeredList);
|
||||
static bool hasDataToRead(int socket);
|
||||
bool hasDataToRead();
|
||||
void disconnectSocket();
|
||||
|
||||
int getSocketId() const { return sock; }
|
||||
|
||||
int getDataToRead();
|
||||
int send(const void *data, int dataSize);
|
||||
int receive(void *data, int dataSize);
|
||||
int peek(void *data, int dataSize);
|
||||
|
||||
void setBlock(bool block);
|
||||
bool isReadable();
|
||||
bool isWritable(bool waitOnDelayedResponse);
|
||||
bool isConnected();
|
||||
|
||||
string getHostName() const;
|
||||
string getIp() const;
|
||||
|
||||
protected:
|
||||
static void throwException(const string &str);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ClientSocket
|
||||
// =====================================================
|
||||
|
||||
class ClientSocket: public Socket{
|
||||
public:
|
||||
void connect(const Ip &ip, int port);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ServerSocket
|
||||
// =====================================================
|
||||
|
||||
class ServerSocket: public Socket{
|
||||
public:
|
||||
void bind(int port);
|
||||
void listen(int connectionQueueSize= SOMAXCONN);
|
||||
Socket *accept();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
||||
// ==============================================================
|
||||
// This file is part of Glest Shared Library (www.glest.org)
|
||||
//
|
||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef _SHARED_PLATFORM_SOCKET_H_
|
||||
#define _SHARED_PLATFORM_SOCKET_H_
|
||||
|
||||
#include <string>
|
||||
#include <winsock.h>
|
||||
#include <map>
|
||||
|
||||
using std::string;
|
||||
|
||||
const char* WSAGetLastErrorMessage(const char* pcMessagePrefix,int nErrorID = 0);
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// =====================================================
|
||||
// class IP
|
||||
// =====================================================
|
||||
|
||||
class Ip{
|
||||
private:
|
||||
unsigned char bytes[4];
|
||||
|
||||
public:
|
||||
Ip();
|
||||
Ip(unsigned char byte0, unsigned char byte1, unsigned char byte2, unsigned char byte3);
|
||||
Ip(const string& ipString);
|
||||
|
||||
unsigned char getByte(int byteIndex) {return bytes[byteIndex];}
|
||||
string getString() const;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class Socket
|
||||
// =====================================================
|
||||
|
||||
class Socket{
|
||||
private:
|
||||
class SocketManager{
|
||||
public:
|
||||
SocketManager();
|
||||
~SocketManager();
|
||||
};
|
||||
|
||||
protected:
|
||||
static SocketManager socketManager;
|
||||
SOCKET sock;
|
||||
|
||||
public:
|
||||
Socket(SOCKET sock);
|
||||
Socket();
|
||||
~Socket();
|
||||
|
||||
static bool enableDebugText;
|
||||
|
||||
// Int lookup is socket fd while bool result is whether or not that socket was signalled for reading
|
||||
static bool hasDataToRead(std::map<int,bool> &socketTriggeredList);
|
||||
static bool hasDataToRead(int socket);
|
||||
bool hasDataToRead();
|
||||
void disconnectSocket();
|
||||
|
||||
int getSocketId() const { return sock; }
|
||||
|
||||
int getDataToRead();
|
||||
int send(const void *data, int dataSize);
|
||||
int receive(void *data, int dataSize);
|
||||
int peek(void *data, int dataSize);
|
||||
|
||||
void setBlock(bool block);
|
||||
bool isReadable();
|
||||
bool isWritable(bool waitOnDelayedResponse);
|
||||
bool isConnected();
|
||||
|
||||
string getHostName() const;
|
||||
string getIp() const;
|
||||
|
||||
protected:
|
||||
static void throwException(const string &str);
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ClientSocket
|
||||
// =====================================================
|
||||
|
||||
class ClientSocket: public Socket{
|
||||
public:
|
||||
void connect(const Ip &ip, int port);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class ServerSocket
|
||||
// =====================================================
|
||||
|
||||
class ServerSocket: public Socket{
|
||||
public:
|
||||
void bind(int port);
|
||||
void listen(int connectionQueueSize= SOMAXCONN);
|
||||
Socket *accept();
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
||||
|
|
|
@ -235,9 +235,9 @@ int Socket::getDataToRead(){
|
|||
if(err < 0 && errno != EAGAIN)
|
||||
{
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"In [%s::%s] ERROR PEEKING SOCKET DATA, err = %d errno = %d [%s]",__FILE__,__FUNCTION__,err,errno,strerror(errno));
|
||||
|
||||
throwException(szBuf);
|
||||
sprintf(szBuf,"In [%s::%s] ERROR PEEKING SOCKET DATA, err = %d errno = %d [%s]\n",__FILE__,__FUNCTION__,err,errno,strerror(errno));
|
||||
//throwException(szBuf);
|
||||
printf("%s",szBuf);
|
||||
}
|
||||
else if(err == 0)
|
||||
{
|
||||
|
@ -257,9 +257,9 @@ int Socket::send(const void *data, int dataSize) {
|
|||
if(bytesSent < 0 && errno != EAGAIN)
|
||||
{
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"In [%s::%s] ERROR WRITING SOCKET DATA, err = %d errno = %d [%s]",__FILE__,__FUNCTION__,bytesSent,errno,strerror(errno));
|
||||
|
||||
throwException(szBuf);
|
||||
sprintf(szBuf,"In [%s::%s] ERROR WRITING SOCKET DATA, err = %d errno = %d [%s]\n",__FILE__,__FUNCTION__,bytesSent,errno,strerror(errno));
|
||||
//throwException(szBuf);
|
||||
printf("%s",szBuf);
|
||||
}
|
||||
else if(bytesSent < 0 && errno == EAGAIN)
|
||||
{
|
||||
|
@ -304,8 +304,8 @@ int Socket::receive(void *data, int dataSize)
|
|||
{
|
||||
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));
|
||||
|
||||
throwException(szBuf);
|
||||
//throwException(szBuf);
|
||||
printf("%s",szBuf);
|
||||
}
|
||||
else if(bytesReceived < 0 && errno == EAGAIN)
|
||||
{
|
||||
|
@ -346,8 +346,9 @@ int Socket::peek(void *data, int dataSize){
|
|||
{
|
||||
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));
|
||||
//throwException(szBuf);
|
||||
|
||||
throwException(szBuf);
|
||||
disconnectSocket();
|
||||
}
|
||||
else if(err < 0 && errno == EAGAIN)
|
||||
{
|
||||
|
|
|
@ -454,6 +454,8 @@ void exceptionMessage(const exception &excp){
|
|||
message+= excp.what();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue