/** * rarch_main_data_http_iterate_transfer: * * Resumes HTTP transfer update. * * Returns: 0 when finished, -1 when we should continue * with the transfer on the next frame. **/ static int rarch_main_data_http_iterate_transfer(void *data) { http_handle_t *http = (http_handle_t*)data; size_t pos = 0, tot = 0; int percent = 0; if (!net_http_update(http->handle, &pos, &tot)) { if(tot != 0) percent = (unsigned long long)pos * 100 / (unsigned long long)tot; if (percent > 0) { char tmp[PATH_MAX_LENGTH]; snprintf(tmp, sizeof(tmp), "%s: %d%%", msg_hash_to_str(MSG_DOWNLOAD_PROGRESS), percent); data_runloop_osd_msg(tmp, sizeof(tmp)); } return -1; } return 0; }
/** * rarch_main_data_http_iterate_transfer: * * Resumes HTTP transfer update. * * Returns: 0 when finished, -1 when we should continue * with the transfer on the next frame. **/ static int rarch_main_data_http_iterate_transfer(rarch_task_t *task) { http_handle_t *http = (http_handle_t*)task->state; size_t pos = 0, tot = 0; if (!net_http_update(http->handle, &pos, &tot)) { task->progress = (tot == 0) ? -1 : (signed)(pos * 100 / tot); return -1; } return 0; }
/** * rarch_main_data_http_iterate_transfer: * * Resumes HTTP transfer update. * * Returns: 0 when finished, -1 when we should continue * with the transfer on the next frame. **/ static int rarch_main_data_http_iterate_transfer(http_handle_t *http) { size_t pos = 0, tot = 0; if (!net_http_update(http->handle, &pos, &tot)) { #ifdef _WIN32 RARCH_LOG("%.9I64u / %.9I64u \r", (unsigned long long)pos, (unsigned long long)tot); #else RARCH_LOG("%.9llu / %.9llu \r", (unsigned long long)pos, (unsigned long long)tot); #endif return -1; } return 0; }
/** * task_http_iterate_transfer: * * Resumes HTTP transfer update. * * Returns: 0 when finished, -1 when we should continue * with the transfer on the next frame. **/ static int task_http_iterate_transfer(retro_task_t *task) { http_handle_t *http = (http_handle_t*)task->state; size_t pos = 0, tot = 0; /* FIXME: This wouldn't be needed if we could wait for a timeout */ if (task_queue_is_threaded()) retro_sleep(1); if (!net_http_update(http->handle, &pos, &tot)) { task_set_progress(task, (tot == 0) ? -1 : (signed)(pos * 100 / tot)); return -1; } return 0; }
/** * rarch_main_data_http_iterate_transfer: * * Resumes HTTP transfer update. * * Returns: 0 when finished, -1 when we should continue * with the transfer on the next frame. **/ static int rarch_main_data_http_iterate_transfer(void *data) { http_handle_t *http = (http_handle_t*)data; size_t pos = 0, tot = 0; int percent = 0; if (!net_http_update(http->handle, &pos, &tot)) { if(tot != 0) percent=(unsigned long long)pos*100/(unsigned long long)tot; else percent=0; if (percent > 0) { char tmp[PATH_MAX_LENGTH] = {0}; snprintf(tmp, sizeof(tmp), "Download progress: %d%%", percent); data_runloop_osd_msg(tmp, sizeof(tmp)); } return -1; } return 0; }
int net_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout) { size_t length; uint8_t* data = NULL; char* res = NULL; int ret = NET_HTTP_GET_OK; struct http_t* http = NULL; retro_time_t t0 = cpu_features_get_time_usec(); struct http_connection_t *conn = net_http_connection_new(url); *result = NULL; /* Error creating the connection descriptor. */ if (!conn) goto error; /* Don't bother with timeouts here, it's just a string scan. */ while (!net_http_connection_iterate(conn)) {} /* Error finishing the connection descriptor. */ if (!net_http_connection_done(conn)) { ret = NET_HTTP_GET_MALFORMED_URL; goto error; } http = net_http_new(conn); /* Error connecting to the endpoint. */ if (!http) { ret = NET_HTTP_GET_CONNECT_ERROR; goto error; } while (!net_http_update(http, NULL, NULL)) { /* Timeout error. */ if (timeout && (cpu_features_get_time_usec() - t0) > *timeout) { ret = NET_HTTP_GET_TIMEOUT; goto error; } } data = net_http_data(http, &length, false); if (data) { res = (char*)malloc(length + 1); /* Allocation error. */ if ( !res ) goto error; memcpy((void*)res, (void*)data, length); free(data); res[length] = 0; *result = res; } else { length = 0; *result = NULL; } if (size) *size = length; error: if ( http ) net_http_delete( http ); if ( conn ) net_http_connection_free( conn ); if (timeout) { t0 = cpu_features_get_time_usec() - t0; if (t0 < *timeout) *timeout -= t0; else *timeout = 0; } return ret; }