mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-17 08:14:01 +00:00
(task_http) Abort task on error
This commit is contained in:
parent
f04f4c89c8
commit
afce03a20e
@ -49,6 +49,8 @@ bool net_http_update(struct http_t *state, size_t* progress, size_t* total);
|
|||||||
/* 200, 404, or whatever. */
|
/* 200, 404, or whatever. */
|
||||||
int net_http_status(struct http_t *state);
|
int net_http_status(struct http_t *state);
|
||||||
|
|
||||||
|
bool net_http_error(struct http_t *state);
|
||||||
|
|
||||||
/* Returns the downloaded data. The returned buffer is owned by the
|
/* Returns the downloaded data. The returned buffer is owned by the
|
||||||
* HTTP handler; it's freed by net_http_delete.
|
* HTTP handler; it's freed by net_http_delete.
|
||||||
*
|
*
|
||||||
|
@ -523,7 +523,7 @@ fail:
|
|||||||
state->status = -1;
|
state->status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_http_status(struct http_t *state)
|
int net_http_status(struct http_t *state)
|
||||||
@ -538,8 +538,7 @@ uint8_t* net_http_data(struct http_t *state, size_t* len, bool accept_error)
|
|||||||
if (!state)
|
if (!state)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!accept_error &&
|
if (!accept_error && net_http_error(state))
|
||||||
(state->error || state->status<200 || state->status>299))
|
|
||||||
{
|
{
|
||||||
if (len)
|
if (len)
|
||||||
*len=0;
|
*len=0;
|
||||||
@ -563,3 +562,8 @@ void net_http_delete(struct http_t *state)
|
|||||||
// free(state->data);
|
// free(state->data);
|
||||||
free(state);
|
free(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool net_http_error(struct http_t *state)
|
||||||
|
{
|
||||||
|
return (state->error || state->status<200 || state->status>299);
|
||||||
|
}
|
||||||
|
@ -317,6 +317,9 @@ void cb_net_generic(void *task_data, void *user_data, const char *err)
|
|||||||
menu_entries_unset_refresh(true);
|
menu_entries_unset_refresh(true);
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
|
if (err)
|
||||||
|
RARCH_ERR("Download failed: %s\n", err);
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
if (data->data)
|
if (data->data)
|
||||||
@ -456,6 +459,12 @@ void cb_generic_download(void *task_data, void *user_data, const char *err)
|
|||||||
event_command(EVENT_CMD_CORE_INFO_INIT);
|
event_command(EVENT_CMD_CORE_INFO_INIT);
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Download of '%s' failed: %s\n",
|
||||||
|
(transf ? transf->path: "unknown"), err);
|
||||||
|
}
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
if (data->data)
|
if (data->data)
|
||||||
@ -463,7 +472,8 @@ finish:
|
|||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(transf);
|
if (transf)
|
||||||
|
free(transf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int deferred_push_core_updater_list(menu_displaylist_info_t *info)
|
static int deferred_push_core_updater_list(menu_displaylist_info_t *info)
|
||||||
|
@ -151,12 +151,11 @@ static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
|||||||
if (!rarch_main_data_http_con_iterate_transfer(http))
|
if (!rarch_main_data_http_con_iterate_transfer(http))
|
||||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
||||||
break;
|
break;
|
||||||
case HTTP_STATUS_TRANSFER_PARSE:
|
|
||||||
goto task_finished;
|
|
||||||
case HTTP_STATUS_TRANSFER:
|
case HTTP_STATUS_TRANSFER:
|
||||||
if (!rarch_main_data_http_iterate_transfer(http))
|
if (!rarch_main_data_http_iterate_transfer(http))
|
||||||
http->status = HTTP_STATUS_TRANSFER_PARSE;
|
goto task_finished;
|
||||||
break;
|
break;
|
||||||
|
case HTTP_STATUS_TRANSFER_PARSE:
|
||||||
case HTTP_STATUS_POLL:
|
case HTTP_STATUS_POLL:
|
||||||
goto task_finished;
|
goto task_finished;
|
||||||
default:
|
default:
|
||||||
@ -167,17 +166,32 @@ static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
|||||||
task_finished:
|
task_finished:
|
||||||
task->finished = true;
|
task->finished = true;
|
||||||
|
|
||||||
data = (http_transfer_data_t*)calloc(1, sizeof(*data));
|
|
||||||
task->task_data = data;
|
|
||||||
|
|
||||||
if (http->handle)
|
if (http->handle)
|
||||||
{
|
{
|
||||||
data->data = (char*)net_http_data(http->handle, &data->len, false);
|
size_t len = 0;
|
||||||
|
char *tmp = (char*)net_http_data(http->handle, &len, false);
|
||||||
|
|
||||||
if (data->data && http->cb)
|
if (tmp && http->cb)
|
||||||
http->cb(data->data, data->len);
|
http->cb(tmp, len);
|
||||||
|
|
||||||
|
if (net_http_error(http->handle))
|
||||||
|
{
|
||||||
|
tmp = (char*)net_http_data(http->handle, &len, true);
|
||||||
|
|
||||||
|
if (tmp)
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
|
task->error = strdup("Download failed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data = (http_transfer_data_t*)calloc(1, sizeof(*data));
|
||||||
|
data->data = tmp;
|
||||||
|
data->len = len;
|
||||||
|
|
||||||
|
task->task_data = data;
|
||||||
|
}
|
||||||
|
|
||||||
/* we can't let net_http_delete free our data */
|
|
||||||
net_http_delete(http->handle);
|
net_http_delete(http->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user