mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-01 23:58:26 +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. */
|
||||
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
|
||||
* HTTP handler; it's freed by net_http_delete.
|
||||
*
|
||||
|
@ -523,7 +523,7 @@ fail:
|
||||
state->status = -1;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
return NULL;
|
||||
|
||||
if (!accept_error &&
|
||||
(state->error || state->status<200 || state->status>299))
|
||||
if (!accept_error && net_http_error(state))
|
||||
{
|
||||
if (len)
|
||||
*len=0;
|
||||
@ -563,3 +562,8 @@ void net_http_delete(struct http_t *state)
|
||||
// free(state->data);
|
||||
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);
|
||||
|
||||
finish:
|
||||
if (err)
|
||||
RARCH_ERR("Download failed: %s\n", err);
|
||||
|
||||
if (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);
|
||||
|
||||
finish:
|
||||
if (err)
|
||||
{
|
||||
RARCH_ERR("Download of '%s' failed: %s\n",
|
||||
(transf ? transf->path: "unknown"), err);
|
||||
}
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (data->data)
|
||||
@ -463,6 +472,7 @@ finish:
|
||||
free(data);
|
||||
}
|
||||
|
||||
if (transf)
|
||||
free(transf);
|
||||
}
|
||||
|
||||
|
@ -151,12 +151,11 @@ static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
||||
if (!rarch_main_data_http_con_iterate_transfer(http))
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER_PARSE:
|
||||
goto task_finished;
|
||||
case HTTP_STATUS_TRANSFER:
|
||||
if (!rarch_main_data_http_iterate_transfer(http))
|
||||
http->status = HTTP_STATUS_TRANSFER_PARSE;
|
||||
goto task_finished;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER_PARSE:
|
||||
case HTTP_STATUS_POLL:
|
||||
goto task_finished;
|
||||
default:
|
||||
@ -167,17 +166,32 @@ static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
||||
task_finished:
|
||||
task->finished = true;
|
||||
|
||||
data = (http_transfer_data_t*)calloc(1, sizeof(*data));
|
||||
task->task_data = data;
|
||||
|
||||
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)
|
||||
http->cb(data->data, data->len);
|
||||
if (tmp && http->cb)
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user