Ported auto-discover LAN connect to win32

This commit is contained in:
Mark Vejvoda
2010-04-01 07:46:14 +00:00
parent 215fbdb33f
commit 6c92f188b6
13 changed files with 642 additions and 28 deletions

View File

@@ -17,6 +17,7 @@
#include <string>
#include <vector>
#include <stdexcept>
#include <list>
#include "types.h"
#include "checksum.h"
@@ -25,6 +26,7 @@
using std::string;
using std::vector;
using std::exception;
using std::list;
using Shared::Platform::int64;
using Shared::Util::Checksum;
@@ -78,6 +80,20 @@ private:
int64 queryCounter(int multiplier) const;
};
// =====================================================
// class ModeInfo
// =====================================================
class ModeInfo {
public:
int width;
int height;
int depth;
ModeInfo(int width, int height, int depth);
string getString() const;
};
// =====================================================
// class PlatformExceptionHandler
// =====================================================
@@ -113,6 +129,7 @@ string extractDirectoryPathFromFile(string filename);
string extractExtension(const string& filename);
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
void getFullscreenVideoModes(list<ModeInfo> *modeinfos);
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
void restoreVideoMode(bool exitingApp=false);

View File

@@ -15,6 +15,8 @@
#include <string>
#include <winsock.h>
#include <map>
#include <vector>
#include "thread.h"
using std::string;
@@ -54,14 +56,16 @@ private:
protected:
static SocketManager socketManager;
SOCKET sock;
static int broadcast_portno;
public:
Socket(SOCKET sock);
Socket();
~Socket();
virtual ~Socket();
static bool enableDebugText;
static bool enableNetworkDebugInfo;
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);
@@ -96,6 +100,27 @@ protected:
class ClientSocket: public Socket{
public:
void connect(const Ip &ip, int port);
static std::vector<string> discoverServers();
};
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();
};
// =====================================================
@@ -105,13 +130,19 @@ public:
class ServerSocket: public Socket{
public:
ServerSocket();
virtual ~ServerSocket();
void bind(int port);
void listen(int connectionQueueSize= SOMAXCONN);
Socket *accept();
void stopBroadCastThread();
protected:
void broadcast_thread();
BroadCastSocketThread *broadCastThread;
void startBroadCastThread();
};
}}//end namespace