From 728d1723b4e9a8f4e8386237c558a30730470eed Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 23 Jan 2015 23:28:32 +0100 Subject: [PATCH] Remove callback from net_http.c code --- general.h | 9 +++++++++ net_http.c | 20 -------------------- net_http.h | 5 ----- runloop.c | 29 +++++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/general.h b/general.h index 1bf4618c5f..03298bb1a3 100644 --- a/general.h +++ b/general.h @@ -388,6 +388,10 @@ typedef struct rarch_resolution #define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024) #define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024) +#ifdef HAVE_NETPLAY +typedef int (*http_cb_t )(void *data, size_t len); +#endif + /* All run-time- / command line flag-related globals go here. */ struct global @@ -575,6 +579,7 @@ struct global #ifdef HAVE_NETPLAY msg_queue_t *http_msg_queue; http_t *http_handle; + http_cb_t http_cb; #endif bool exec; @@ -776,6 +781,10 @@ static inline void rarch_fail(int error_code, const char *error) longjmp(g_extern.error_sjlj_context, error_code); } +#ifdef HAVE_NETPLAY +void net_http_set_pending_cb(http_cb_t cb); +#endif + #endif diff --git a/net_http.c b/net_http.c index 00c273aafb..53cb9eb647 100644 --- a/net_http.c +++ b/net_http.c @@ -184,23 +184,6 @@ static ssize_t net_http_recv(int fd, bool *error, return -1; } -static http_cb_t pending_cb; - -void net_http_set_pending_cb(http_cb_t cb) -{ - pending_cb = cb; -} - -static http_cb_t net_http_get_pending_cb(void) -{ - return pending_cb; -} - -static void net_http_clear_pending_cb(void) -{ - pending_cb = NULL; -} - http_t *net_http_new(const char * url) { bool error; @@ -256,9 +239,6 @@ http_t *net_http_new(const char * url) state->len = 0; state->buflen = 512; state->data = (char*)malloc(state->buflen); - state->cb = net_http_get_pending_cb(); - - net_http_clear_pending_cb(); return state; diff --git a/net_http.h b/net_http.h index 52bbb07fd0..2d0396b7c5 100644 --- a/net_http.h +++ b/net_http.h @@ -25,8 +25,6 @@ extern "C" { #endif -typedef int (*http_cb_t )(void *data, size_t len); - typedef struct { int fd; @@ -40,13 +38,10 @@ typedef struct size_t len; size_t buflen; char * data; - http_cb_t cb; } http_t; http_t *net_http_new(const char * url); -void net_http_set_pending_cb(http_cb_t cb); - /* You can use this to call net_http_update * only when something will happen; select() it for reading. */ int net_http_fd(http_t *state); diff --git a/runloop.c b/runloop.c index ce8bdc4c43..e0b809fcb8 100644 --- a/runloop.c +++ b/runloop.c @@ -867,6 +867,24 @@ static int rarch_main_iterate_quit(void) } #ifdef HAVE_NETPLAY + +static http_cb_t pending_cb; + +void net_http_set_pending_cb(http_cb_t cb) +{ + pending_cb = cb; +} + +static http_cb_t net_http_get_pending_cb(void) +{ + return pending_cb; +} + +static void net_http_clear_pending_cb(void) +{ + pending_cb = NULL; +} + /** * rarch_main_iterate_http_transfer: * @@ -893,8 +911,8 @@ static int rarch_main_iterate_http_parse(void) size_t len; char *data = (char*)net_http_data(g_extern.http_handle, &len, false); - if (data && g_extern.http_handle->cb) - g_extern.http_handle->cb(data, len); + if (data && g_extern.http_cb) + g_extern.http_cb(data, len); net_http_delete(g_extern.http_handle); @@ -929,6 +947,13 @@ static int rarch_main_iterate_http_poll(void) g_extern.http_handle = net_http_new(url); + if (!g_extern.http_handle) + return -1; + + g_extern.http_cb = net_http_get_pending_cb(); + + net_http_clear_pending_cb(); + return 0; } #endif