Remove callback from net_http.c code

This commit is contained in:
twinaphex 2015-01-23 23:28:32 +01:00
parent e0807bc440
commit 728d1723b4
4 changed files with 36 additions and 27 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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