mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 11:03:45 +01:00
start aemu_postoffice relay with built-in adhoc server
This commit is contained in:
1 parent
4791043e8d
commit
c8a9ed025a
1 file changed
+52
@@ -64,6 +64,8 @@
|
||||
|
||||
#include "ext/aemu_postoffice/client/postoffice_client.h"
|
||||
#include "ext/aemu_postoffice/adhocctl/client/adhocctl.h"
|
||||
#include "ext/aemu_postoffice/server_cpp/server.h"
|
||||
#include "ext/aemu_postoffice/server_cpp/log.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef errno
|
||||
@@ -102,6 +104,7 @@ bool trackingRelayFailure = false;
|
||||
bool relayDisabled = false;
|
||||
bool relayFirstConnect = true;
|
||||
bool g_serverListLoaded = false;
|
||||
std::thread relayThread;
|
||||
|
||||
int gameModeNotifyEvent = -1;
|
||||
|
||||
@@ -351,6 +354,10 @@ void __NetAdhocShutdown() {
|
||||
adhocServerThread.join();
|
||||
}
|
||||
|
||||
if (relayThread.joinable()) {
|
||||
relayThread.join();
|
||||
}
|
||||
|
||||
NetAdhocctl_Term();
|
||||
|
||||
if (netAdhocInited) {
|
||||
@@ -2061,6 +2068,18 @@ void __AdhocNotifInit() {
|
||||
sendTargetPeers.clear();
|
||||
}
|
||||
|
||||
static void aemu_postoffice_server_log(const char *format, ...){
|
||||
char log_buf[1024] = {0};
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int len = vsnprintf(log_buf, sizeof(log_buf), format, args);
|
||||
va_end(args);
|
||||
if (len < 1024 && log_buf[len - 1] == '\n'){
|
||||
log_buf[len - 1] = '\0';
|
||||
}
|
||||
INFO_LOG(Log::sceNet, "%s", log_buf);
|
||||
}
|
||||
|
||||
void __NetAdhocInit() {
|
||||
friendFinderRunning = false;
|
||||
netAdhocInited = false;
|
||||
@@ -2078,6 +2097,39 @@ void __NetAdhocInit() {
|
||||
if (g_Config.bEnableWlan && g_Config.bEnableAdhocServer) {
|
||||
adhocServerRunning = true;
|
||||
adhocServerThread = std::thread(proAdhocServerThread, SERVER_PORT);
|
||||
|
||||
// relay thread
|
||||
relayThread = std::thread([] () {
|
||||
SetCurrentThreadName("AEMUPostoffice");
|
||||
|
||||
aemu_postoffice_server::LOG = aemu_postoffice_server_log;
|
||||
|
||||
struct aemu_postoffice_server::config config;
|
||||
/*
|
||||
* strict mode requires adhocctl data to be fed into the relay, either from
|
||||
* aemu_postoffice's implementation of adhocctl, or by constructing the snapshot
|
||||
* from ppsspp's adhocctl server
|
||||
*/
|
||||
config.strict_mode = false;
|
||||
|
||||
aemu_postoffice_server::Server relay_server(config);
|
||||
|
||||
while (adhocServerRunning) {
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto pump_status = relay_server.pump();
|
||||
auto wait_time = std::chrono::milliseconds(8);
|
||||
if (pump_status == aemu_postoffice_server::ServerPumpStatus::LISTEN_SOCK_DEAD) {
|
||||
break;
|
||||
}
|
||||
if (pump_status == aemu_postoffice_server::ServerPumpStatus::IDLE){
|
||||
wait_time = std::chrono::milliseconds(100);
|
||||
}
|
||||
auto time_taken = now - std::chrono::high_resolution_clock::now();
|
||||
if (time_taken < wait_time){
|
||||
std::this_thread::sleep_for(wait_time - time_taken);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user