project64/Source/Project64/UserInterface/Debugger/ScriptAPI/JSServerWorker.h

67 lines
1.5 KiB
C
Raw Normal View History

#pragma once
2022-09-26 02:31:54 +00:00
#include "ScriptAPI.h"
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
class CJSServerWorker : public CScriptWorker
{
private:
2022-09-26 02:31:54 +00:00
enum
{
TIMEOUT_MS = 1
};
2022-09-26 02:31:54 +00:00
struct ServerQueue
{
CriticalSection cs;
std::string listenAddress;
unsigned short listenPort;
bool bClosePending;
2022-09-26 02:31:54 +00:00
ServerQueue() :
listenAddress(""), listenPort(0), bClosePending(false)
{
}
} m_Queue;
struct JSServerAddrInfo
{
char address[INET6_ADDRSTRLEN];
2022-09-26 02:31:54 +00:00
const char * family;
unsigned short port;
JSServerAddrInfo() :
address(""),
family(""),
port(0)
{
}
};
bool m_bWinsockOK;
SOCKET m_ServerSocket;
JSServerAddrInfo m_Address;
public:
2022-09-26 02:31:54 +00:00
CJSServerWorker(CScriptInstance * instance, void * dukObjectHeapPtr);
virtual ~CJSServerWorker();
2022-09-26 02:31:54 +00:00
void Init(const char * address, unsigned short port);
void WorkerProc();
std::string GetAddress();
unsigned short GetPort();
2022-09-26 02:31:54 +00:00
const char * GetFamily();
private:
void JSEmitConnection(SOCKET c);
void JSEmitClose();
void JSEmitListening();
2022-09-26 02:31:54 +00:00
void JSEmitError(const char * errMessage);
2022-09-26 02:31:54 +00:00
static duk_idx_t CbArgs_EmitConnection(duk_context * ctx, void * _env);
static duk_idx_t CbArgs_EmitClose(duk_context * ctx, void * _env);
static duk_idx_t CbArgs_EmitListening(duk_context * ctx, void * _env);
static duk_idx_t CbArgs_EmitError(duk_context * ctx, void * _env);
};