mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
Use a new curl easy instance per request
This commit is contained in:
parent
68aecaeed5
commit
1278277d46
2
http.cpp
2
http.cpp
@ -86,8 +86,6 @@ void MoonlightInstance::NvHTTPInit(int32_t callbackId, pp::VarArray args)
|
|||||||
LoadCert(_cert.c_str(), _key.c_str());
|
LoadCert(_cert.c_str(), _key.c_str());
|
||||||
g_UniqueId = strdup(_uniqueId.c_str());
|
g_UniqueId = strdup(_uniqueId.c_str());
|
||||||
|
|
||||||
http_init();
|
|
||||||
|
|
||||||
pp::VarDictionary ret;
|
pp::VarDictionary ret;
|
||||||
ret.Set("callbackId", pp::Var(callbackId));
|
ret.Set("callbackId", pp::Var(callbackId));
|
||||||
ret.Set("type", pp::Var("resolve"));
|
ret.Set("type", pp::Var("resolve"));
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
#include <openssl/x509v3.h>
|
#include <openssl/x509v3.h>
|
||||||
#include <openssl/pem.h>
|
#include <openssl/pem.h>
|
||||||
|
|
||||||
static CURL *curl;
|
|
||||||
|
|
||||||
extern X509 *g_Cert;
|
extern X509 *g_Cert;
|
||||||
extern EVP_PKEY *g_PrivateKey;
|
extern EVP_PKEY *g_PrivateKey;
|
||||||
|
|
||||||
@ -61,7 +59,10 @@ static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int http_init() {
|
int http_request(char* url, PHTTP_DATA data) {
|
||||||
|
int ret;
|
||||||
|
CURL *curl;
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if (!curl)
|
if (!curl)
|
||||||
return GS_FAILED;
|
return GS_FAILED;
|
||||||
@ -75,19 +76,16 @@ int http_init() {
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _write_curl);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _write_curl);
|
||||||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
|
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
|
curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
|
||||||
|
|
||||||
return GS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int http_request(char* url, PHTTP_DATA data) {
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, data);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, data);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
|
||||||
if (data->size > 0) {
|
if (data->size > 0) {
|
||||||
free(data->memory);
|
free(data->memory);
|
||||||
data->memory = malloc(1);
|
data->memory = malloc(1);
|
||||||
if(data->memory == NULL)
|
if(data->memory == NULL) {
|
||||||
return GS_OUT_OF_MEMORY;
|
ret = GS_OUT_OF_MEMORY;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
data->size = 0;
|
data->size = 0;
|
||||||
}
|
}
|
||||||
@ -95,16 +93,16 @@ int http_request(char* url, PHTTP_DATA data) {
|
|||||||
CURLcode res = curl_easy_perform(curl);
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
|
||||||
if(res != CURLE_OK) {
|
if(res != CURLE_OK) {
|
||||||
return GS_FAILED;
|
ret = GS_FAILED;
|
||||||
} else if (data->memory == NULL) {
|
} else if (data->memory == NULL) {
|
||||||
return GS_OUT_OF_MEMORY;
|
ret = GS_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
ret = GS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GS_OK;
|
cleanup:
|
||||||
}
|
|
||||||
|
|
||||||
void http_cleanup() {
|
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
PHTTP_DATA http_create_data() {
|
PHTTP_DATA http_create_data() {
|
||||||
|
@ -30,7 +30,6 @@ typedef struct _HTTP_DATA {
|
|||||||
size_t size;
|
size_t size;
|
||||||
} HTTP_DATA, *PHTTP_DATA;
|
} HTTP_DATA, *PHTTP_DATA;
|
||||||
|
|
||||||
int http_init();
|
|
||||||
PHTTP_DATA http_create_data();
|
PHTTP_DATA http_create_data();
|
||||||
int http_request(char* url, PHTTP_DATA data);
|
int http_request(char* url, PHTTP_DATA data);
|
||||||
void http_free_data(PHTTP_DATA data);
|
void http_free_data(PHTTP_DATA data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user