OpenTTD Source 20260311-master-g511d3794ce
http_curl.cpp File Reference

CURL-based implementation for HTTP requests. More...

#include "../../stdafx.h"
#include "../../debug.h"
#include "../../fileio_func.h"
#include "../../rev.h"
#include "../../thread.h"
#include "../network_internal.h"
#include "http.h"
#include "http_shared.h"
#include <atomic>
#include <condition_variable>
#include <curl/curl.h>
#include <mutex>
#include <queue>
#include "../../safeguards.h"

Go to the source code of this file.

Data Structures

class  NetworkHTTPRequest
 Single HTTP request. More...

Functions

void CurlSetOption (CURL *curl, auto option, auto value)
 Set some specific option and emit debug information upon failure.
void HttpThread ()
 Thread entry point for the HTTP request thread.
void NetworkHTTPInitialize ()
 Initialize the HTTP socket handler.
void NetworkHTTPUninitialize ()
 Uninitialize the HTTP socket handler.

Variables

static std::vector< HTTPThreadSafeCallback * > _http_callbacks
 Callback for the current requests.
static std::vector< HTTPThreadSafeCallback * > _new_http_callbacks
 Callbacks for the request that should be started.
static std::mutex _http_callback_mutex
 Mutex to prevent concurrent access to _http_callbacks.
static std::mutex _new_http_callback_mutex
 Mutex to prevent concurrent access to _new_http_callbacks.
static std::thread _http_thread
 The thread running the HTTP requests.
static std::atomic< bool > _http_thread_exit = false
 Whether to ask the HTTP request thread to stop.
static std::queue< std::unique_ptr< NetworkHTTPRequest > > _http_requests
 HTTP requests that are currently running.
static std::mutex _http_mutex
 Mutex to prevent concurrent access _http_requests.
static std::condition_variable _http_cv
 Conditional variable to wake up the HTTP request thread.

Detailed Description

CURL-based implementation for HTTP requests.

Definition in file http_curl.cpp.

Function Documentation

◆ CurlSetOption()

void CurlSetOption ( CURL * curl,
auto option,
auto value )

Set some specific option and emit debug information upon failure.

Parameters
curlThe curl instance we're using.
optionThe option to set.
valueThe value for the option.

Definition at line 131 of file http_curl.cpp.

References Debug.

Referenced by HttpThread().

◆ HttpThread()

◆ NetworkHTTPInitialize()

void NetworkHTTPInitialize ( )

Initialize the HTTP socket handler.

Definition at line 257 of file http_curl.cpp.

◆ NetworkHTTPUninitialize()

void NetworkHTTPUninitialize ( )

Uninitialize the HTTP socket handler.

Definition at line 292 of file http_curl.cpp.

Variable Documentation

◆ _http_callback_mutex

std::mutex _http_callback_mutex
static

Mutex to prevent concurrent access to _http_callbacks.

Definition at line 48 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::HTTPReceive().

◆ _http_callbacks

std::vector<HTTPThreadSafeCallback *> _http_callbacks
static

Callback for the current requests.

Definition at line 46 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::HTTPReceive().

◆ _http_cv

std::condition_variable _http_cv
static

Conditional variable to wake up the HTTP request thread.

Definition at line 86 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::Connect(), HttpThread(), and NetworkHTTPUninitialize().

◆ _http_mutex

std::mutex _http_mutex
static

Mutex to prevent concurrent access _http_requests.

Definition at line 85 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::Connect(), HttpThread(), and NetworkHTTPUninitialize().

◆ _http_requests

std::queue<std::unique_ptr<NetworkHTTPRequest> > _http_requests
static

HTTP requests that are currently running.

Definition at line 84 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::Connect(), and HttpThread().

◆ _http_thread

std::thread _http_thread
static

The thread running the HTTP requests.

Definition at line 82 of file http_curl.cpp.

Referenced by NetworkHTTPInitialize(), and NetworkHTTPUninitialize().

◆ _http_thread_exit

std::atomic<bool> _http_thread_exit = false
static

Whether to ask the HTTP request thread to stop.

Definition at line 83 of file http_curl.cpp.

Referenced by HttpThread(), NetworkHTTPInitialize(), and NetworkHTTPUninitialize().

◆ _new_http_callback_mutex

std::mutex _new_http_callback_mutex
static

Mutex to prevent concurrent access to _new_http_callbacks.

Definition at line 49 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::HTTPReceive().

◆ _new_http_callbacks

std::vector<HTTPThreadSafeCallback *> _new_http_callbacks
static

Callbacks for the request that should be started.

Definition at line 47 of file http_curl.cpp.

Referenced by NetworkHTTPSocketHandler::HTTPReceive().