Ported LAN auto-connect feature to win32

This commit is contained in:
Mark Vejvoda
2010-04-02 03:06:27 +00:00
parent bc725454fd
commit 8cf77f1b8a
2 changed files with 230 additions and 27 deletions

View File

@@ -23,6 +23,14 @@ 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
@@ -81,6 +89,7 @@ public:
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();
@@ -93,14 +102,48 @@ protected:
};
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 std::vector<string> discoverServers();
static void discoverServers(DiscoveredServersInterface *cb);
static void stopBroadCastClientThread();
protected:
static BroadCastClientSocketThread *broadCastClientThread;
static void startBroadCastClientThread(DiscoveredServersInterface *cb);
};
class BroadCastSocketThread : public Thread