Some final fixed related to combined cross platform socket code

This commit is contained in:
Mark Vejvoda
2010-04-13 07:29:48 +00:00
parent 561dd69107
commit 8c438b812d
11 changed files with 108 additions and 1839 deletions

Binary file not shown.

View File

@@ -133,7 +133,7 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
AdditionalIncludeDirectories="../../../deps/include/lua;../../../deps/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/shared_lib/include/tinyxml;../../source/glest_game/ai;../../source/glest_game/facilities;../../source/glest_game/game;../../source/glest_game/global;../../source/glest_game/graphics;../../source/glest_game/gui;../../source/glest_game/main;../../source/glest_game/menu;../../source/glest_game/network;../../source/glest_game/sound;../../source/glest_game/type_instances;../../source/glest_game/types;../../source/glest_game/world;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/SDL-1.2.14/include";../../source/shared_lib/include/platform/sdl;../../source/shared_lib/include/sound/openal;"../../source/win32_deps/openal-soft-1.12.854/include""
AdditionalIncludeDirectories="../../../deps/include/lua;../../../deps/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/shared_lib/include/tinyxml;../../source/glest_game/ai;../../source/glest_game/facilities;../../source/glest_game/game;../../source/glest_game/global;../../source/glest_game/graphics;../../source/glest_game/gui;../../source/glest_game/main;../../source/glest_game/menu;../../source/glest_game/network;../../source/glest_game/sound;../../source/glest_game/type_instances;../../source/glest_game/types;../../source/glest_game/world;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/SDL-1.2.14/include";../../source/shared_lib/include/platform/sdl;../../source/shared_lib/include/sound/openal;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/platform/posix"
AdditionalUsingDirectories=""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;XML_LIBRARY;USE_PCH=1;_CRT_SECURE_NO_WARNINGS"
StringPooling="true"

View File

@@ -113,7 +113,7 @@
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
AdditionalIncludeDirectories="../../../deps/include/lua;../../../deps/include;../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude";../../source/win32_deps/libpng141;"../../source/win32_deps/jpeg-8a";"../../source/win32_deps/SDL-1.2.14/include";../../source/shared_lib/include/platform/sdl;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/sound/openal"
AdditionalIncludeDirectories="../../../deps/include/lua;../../../deps/include;../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;"../../source/win32_deps/xerces-c-3.0.1/src";"../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude";../../source/win32_deps/libpng141;"../../source/win32_deps/jpeg-8a";"../../source/win32_deps/SDL-1.2.14/include";../../source/shared_lib/include/platform/sdl;"../../source/win32_deps/openal-soft-1.12.854/include";../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
@@ -379,6 +379,10 @@
RelativePath="..\..\source\shared_lib\sources\platform\sdl\gl_wrap.cpp"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\platform\posix\socket.cpp"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\platform\sdl\window.cpp"
>
@@ -398,10 +402,6 @@
RelativePath="..\..\source\shared_lib\sources\platform\win32\platform_util.cpp"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\platform\win32\socket.cpp"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\platform\win32\thread.cpp"
>
@@ -661,6 +661,10 @@
RelativePath="..\..\source\shared_lib\include\platform\sdl\sdl_private.h"
>
</File>
<File
RelativePath="..\..\source\shared_lib\include\platform\posix\socket.h"
>
</File>
<File
RelativePath="..\..\source\shared_lib\include\platform\sdl\window.h"
>
@@ -684,10 +688,6 @@
RelativePath="..\..\source\shared_lib\include\platform\win32\platform_util.h"
>
</File>
<File
RelativePath="..\..\source\shared_lib\include\platform\win32\socket.h"
>
</File>
<File
RelativePath="..\..\source\shared_lib\include\platform\win32\thread.h"
>

View File

@@ -98,7 +98,7 @@ int ServerInterface::getConnectedSlotCount(){
void ServerInterface::update()
{
std::map<int,bool> socketTriggeredList;
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
//update all slots
for(int i= 0; i < GameConstants::maxPlayers; ++i)
{

View File

@@ -14,13 +14,8 @@
#include <string>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <map>
#include <vector>
@@ -29,11 +24,14 @@
using std::string;
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
typedef SOCKET PLATFORM_SOCKET;
const char* WSAGetLastErrorMessage(const char* pcMessagePrefix,int nErrorID = 0);
#else
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
typedef int PLATFORM_SOCKET;
@@ -88,7 +86,7 @@ protected:
protected:
PLATFORM_SOCKET sock;
long lastDebugEvent;
time_t lastDebugEvent;
static int broadcast_portno;
public:

View File

@@ -1,189 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>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>
#include <vector>
#include "thread.h"
using std::string;
const char* WSAGetLastErrorMessage(const char* pcMessagePrefix,int nErrorID = 0);
namespace Shared{ namespace Platform{
//
// This interface describes the methods a callback object must implement
// when signalled with detected servers
//
class DiscoveredServersInterface {
public:
virtual void DiscoveredServers(std::vector<string> serverList) = 0;
};
// =====================================================
// 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;
static int broadcast_portno;
public:
Socket(SOCKET sock);
Socket();
virtual ~Socket();
static int getBroadCastPort() { return broadcast_portno; }
static void setBroadCastPort(int value) { broadcast_portno = value; }
static std::vector<std::string> getLocalIPAddressList();
// 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);
static void setBlock(bool block, SOCKET socket);
bool isReadable();
bool isWritable(bool waitOnDelayedResponse);
bool isConnected();
static string getHostName();
static string getIp();
protected:
static void throwException(const string &str);
};
class BroadCastClientSocketThread : public Thread
{
private:
Mutex mutexRunning;
Mutex mutexQuit;
bool quit;
bool running;
DiscoveredServersInterface *discoveredServersCB;
void setRunningStatus(bool value);
void setQuitStatus(bool value);
public:
BroadCastClientSocketThread(DiscoveredServersInterface *cb);
virtual void execute();
void signalQuit();
bool getQuitStatus();
bool getRunningStatus();
};
// =====================================================
// class ClientSocket
// =====================================================
class ClientSocket: public Socket{
public:
ClientSocket();
virtual ~ClientSocket();
void connect(const Ip &ip, int port);
static void discoverServers(DiscoveredServersInterface *cb);
static void stopBroadCastClientThread();
protected:
static BroadCastClientSocketThread *broadCastClientThread;
static void startBroadCastClientThread(DiscoveredServersInterface *cb);
};
class BroadCastSocketThread : public Thread
{
private:
Mutex mutexRunning;
Mutex mutexQuit;
bool quit;
bool running;
void setRunningStatus(bool value);
void setQuitStatus(bool value);
public:
BroadCastSocketThread();
virtual void execute();
void signalQuit();
bool getQuitStatus();
bool getRunningStatus();
};
// =====================================================
// class ServerSocket
// =====================================================
class ServerSocket: public Socket{
public:
ServerSocket();
virtual ~ServerSocket();
void bind(int port);
void listen(int connectionQueueSize= SOMAXCONN);
Socket *accept();
void stopBroadCastThread();
protected:
BroadCastSocketThread *broadCastThread;
void startBroadCastThread();
bool isBroadCastThreadRunning();
};
}}//end namespace
#endif

View File

@@ -147,7 +147,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
memcpy(pixels+location,row_pointer[0],cinfo.output_width*cinfo.num_components);
} else {
int r,g,b,a,l;
for (int xPic = 0, xFile = 0; xPic < cinfo.output_width*picComponents; xPic+= picComponents, xFile+= cinfo.num_components) {
for (unsigned int xPic = 0, xFile = 0; xPic < cinfo.output_width*picComponents; xPic+= picComponents, xFile+= cinfo.num_components) {
switch(cinfo.num_components) {
case 3:
r = row_pointer[0][xFile];

View File

@@ -0,0 +1,75 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2007 Marti<74>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
// ==============================================================
#include "font.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{
// =====================================================
// class FontMetrics
// =====================================================
FontMetrics::FontMetrics(){
widths= new float[Font::charCount];
height= 0;
for(int i=0; i<Font::charCount; ++i){
widths[i]= 0;
}
}
FontMetrics::~FontMetrics(){
delete [] widths;
}
float FontMetrics::getTextWidth(const string &str) const{
float width= 0.f;
for(unsigned int i=0; i<str.size(); ++i){
width+= widths[str[i]];
}
return width;
}
float FontMetrics::getHeight() const{
return height;
}
// ===============================================
// class Font
// ===============================================
const int Font::charCount= 256;
Font::Font(){
inited= false;
type= "Times New Roman";
width= 400;
}
// ===============================================
// class Font2D
// ===============================================
Font2D::Font2D(){
size= 10;
}
// ===============================================
// class Font3D
// ===============================================
Font3D::Font3D(){
depth= 10.f;
}
}}//end namespace

View File

@@ -177,7 +177,7 @@ void Mesh::loadV3(const string &dir, FILE *f, TextureManager *textureManager){
readBytes = fread(vertices, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
readBytes = fread(normals, sizeof(Vec3f)*frameCount*vertexCount, 1, f);
if(textures[mtDiffuse]!=NULL){
for(int i=0; i<meshHeader.texCoordFrameCount; ++i){
for(unsigned int i=0; i<meshHeader.texCoordFrameCount; ++i){
readBytes = fread(texCoords, sizeof(Vec2f)*vertexCount, 1, f);
}
}
@@ -278,11 +278,11 @@ void Mesh::save(const string &dir, FILE *f){
void Mesh::computeTangents(){
delete [] tangents;
tangents= new Vec3f[vertexCount];
for(int i=0; i<vertexCount; ++i){
for(unsigned int i=0; i<vertexCount; ++i){
tangents[i]= Vec3f(0.f);
}
for(int i=0; i<indexCount; i+=3){
for(unsigned int i=0; i<indexCount; i+=3){
for(int j=0; j<3; ++j){
uint32 i0= indices[i+j];
uint32 i1= indices[i+(j+1)%3];
@@ -306,7 +306,7 @@ void Mesh::computeTangents(){
}
}
for(int i=0; i<vertexCount; ++i){
for(unsigned int i=0; i<vertexCount; ++i){
/*Vec3f binormal= normals[i].cross(tangents[i]);
tangents[i]+= binormal.cross(normals[i]);*/
tangents[i].normalize();
@@ -332,19 +332,19 @@ Model::~Model(){
// ==================== data ====================
void Model::buildInterpolationData() const{
for(int i=0; i<meshCount; ++i){
for(unsigned int i=0; i<meshCount; ++i){
meshes[i].buildInterpolationData();
}
}
void Model::updateInterpolationData(float t, bool cycle) const{
for(int i=0; i<meshCount; ++i){
for(unsigned int i=0; i<meshCount; ++i){
meshes[i].updateInterpolationData(t, cycle);
}
}
void Model::updateInterpolationVertices(float t, bool cycle) const{
for(int i=0; i<meshCount; ++i){
for(unsigned int i=0; i<meshCount; ++i){
meshes[i].updateInterpolationVertices(t, cycle);
}
}

View File

@@ -22,7 +22,6 @@
#include <sys/filio.h>
#endif
#include <net/if.h>
#include "conversion.h"
#include "util.h"
@@ -34,7 +33,7 @@
#include <windows.h>
#include <winsock.h>
#include <iphlpapi.h>
//#include <strstream>
#include <strstream>
#else
@@ -43,7 +42,7 @@
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
//#include <net/if.h>
#include <net/if.h>
//#include <sys/ioctl.h>
#endif
@@ -164,7 +163,7 @@ namespace Shared{ namespace Platform{
// must copy the data from this function before you call it again. It
// follows that this function is also not thread-safe.
const char* WSAGetLastErrorMessage(const char* pcMessagePrefix,
int nErrorID /* = 0 */)
int nErrorID = 0 )
{
// Build basic error string
static char acErrorBuffer[256];
@@ -232,12 +231,12 @@ int getLastSocketError() {
#endif
}
char * getLastSocketErrorText(int *errNumber=NULL) {
const char * getLastSocketErrorText(int *errNumber=NULL) {
int errId = (errNumber != NULL ? *errNumber : getLastSocketError());
#ifndef WIN32
return strerror(errId);
#else
return WSAGetLastErrorMessage(errId);
return WSAGetLastErrorMessage("",errId);
#endif
}
@@ -1680,8 +1679,8 @@ void BroadCastSocketThread::execute() {
char myhostname[100]; // hostname of local machine
char subnetmask[MAX_NIC_COUNT][100]; // Subnet mask to broadcast to
struct hostent* myhostent;
char * ptr; // some transient vars
int len,i;
//char * ptr; // some transient vars
//int len,i;
/* get my host name */
gethostname(myhostname,100);

File diff suppressed because it is too large Load Diff