diff --git a/general.h b/general.h index e0609e2383..1bf4618c5f 100644 --- a/general.h +++ b/general.h @@ -59,6 +59,10 @@ #include "command.h" #endif +#ifdef HAVE_NETPLAY +#include "net_http.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -568,6 +572,10 @@ struct global #endif msg_queue_t *msg_queue; +#ifdef HAVE_NETPLAY + msg_queue_t *http_msg_queue; + http_t *http_handle; +#endif bool exec; diff --git a/retroarch.c b/retroarch.c index 8b6c22623b..7bab577109 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2910,6 +2910,10 @@ bool rarch_main_command(unsigned cmd) rarch_main_command(RARCH_CMD_MSG_QUEUE_DEINIT); if (!g_extern.msg_queue) rarch_assert(g_extern.msg_queue = msg_queue_new(8)); +#ifdef HAVE_NETPLAY + if (!g_extern.http_msg_queue) + rarch_assert(g_extern.http_msg_queue = msg_queue_new(8)); +#endif break; case RARCH_CMD_BSV_MOVIE_DEINIT: if (g_extern.bsv.movie) diff --git a/runloop.c b/runloop.c index 911e926e7a..f361e7f745 100644 --- a/runloop.c +++ b/runloop.c @@ -866,6 +866,36 @@ static int rarch_main_iterate_quit(void) return -1; } +#ifdef HAVE_NETPLAY +static int rarch_main_iterate_http_transfer(void) +{ + size_t pos = 0, tot = 0; + + if (!net_http_update(g_extern.http_handle, &pos, &tot)) + { + RARCH_LOG("%.9lu / %.9lu \r", pos, tot); + return -1; + } + + return 0; +} + +static int rarch_main_iterate_http_poll(void) +{ + const char *url = msg_queue_pull(g_extern.http_msg_queue); + + if (!url) + return -1; + /* Can only deal with one HTTP transfer at a time for now */ + if (g_extern.http_handle) + return -1; + + g_extern.http_handle = net_http_new(url); + + return 0; +} +#endif + /** * rarch_main_iterate: * @@ -897,6 +927,19 @@ int rarch_main_iterate(void) do_pre_state_checks(input, old_input, trigger_input); +#ifdef HAVE_NETPLAY + if (g_extern.http_handle) + { + if (!rarch_main_iterate_http_transfer()) + { + /* TODO - we should have some function pointer + * we can call here. */ + } + } + else + rarch_main_iterate_http_poll(); +#endif + #ifdef HAVE_MENU if (g_extern.is_menu) {