From 53f828674a93fe540b11488ae128a17720269c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Betts?= Date: Sun, 9 Jan 2022 20:47:52 +0100 Subject: [PATCH] Set up the dumbest HTTP server --- bsnes/target-bsnes/program/program.cpp | 1 + bsnes/target-bsnes/program/program.hpp | 2 +- bsnes/target-bsnes/program/rpc.cpp | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bsnes/target-bsnes/program/program.cpp b/bsnes/target-bsnes/program/program.cpp index 086f5d3d..535b3106 100644 --- a/bsnes/target-bsnes/program/program.cpp +++ b/bsnes/target-bsnes/program/program.cpp @@ -1,4 +1,5 @@ #include "../bsnes.hpp" + #include "platform.cpp" #include "game.cpp" #include "game-pak.cpp" diff --git a/bsnes/target-bsnes/program/program.hpp b/bsnes/target-bsnes/program/program.hpp index abecf693..1b0483ce 100644 --- a/bsnes/target-bsnes/program/program.hpp +++ b/bsnes/target-bsnes/program/program.hpp @@ -222,7 +222,7 @@ public: }; ProducerConsumerQueue pendingRpcCommands; - nall::thread rpcHandlerThread; + nall::HTTP::Server rpcServer; bool fastForwarding = false; bool rewinding = false; diff --git a/bsnes/target-bsnes/program/rpc.cpp b/bsnes/target-bsnes/program/rpc.cpp index 2b392f53..8a050c9d 100644 --- a/bsnes/target-bsnes/program/rpc.cpp +++ b/bsnes/target-bsnes/program/rpc.cpp @@ -1,19 +1,24 @@ #include auto Program::startRpcListener() -> void { - // NB: There is no cross-platform way to read from a pipe in a non-blocking - // way. So instead, we're going to spin up a blocking thread that reads stdin - // and processes it. What's even worse, is that we can't even properly - // terminate this thread since there's no timeout on blocking stdin reads, - // all we can do is force-terminate this thread on exit. - rpcHandlerThread = nall::thread::create([&](auto param) { - OutputDebugStringA("HELLO IT WORKED LOOK AT THIS\n"); + rpcServer.main([&](nall::HTTP::Request& rq) -> nall::HTTP::Response { + OutputDebugStringA("GOT REQUEST\n"); + nall::HTTP::Response resp; + + resp.setResponseType(200); + resp.setText("hooray!"); + resp.header.append("Content-Type", "text/plain"); + return resp; }); + + OutputDebugStringA("SETTING UP SERVER\n"); + rpcServer.open(); } auto Program::stopRpcListener() -> void { - rpcHandlerThread.cancel(); + rpcServer.close(); } auto Program::processRpcCommands() -> void { + rpcServer.scan(); } \ No newline at end of file