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

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

#include "../../stdafx.h"
#include "../../debug.h"
#include "../../rev.h"
#include "../network_internal.h"
#include "http.h"
#include "http_shared.h"
#include <mutex>
#include <winhttp.h>
#include "../../safeguards.h"

Go to the source code of this file.

Data Structures

class  NetworkHTTPRequest
 Single HTTP request. More...

Functions

static std::string GetLastErrorAsString ()
 Gets the last error from Windows as a string.
static void StaticWinHttpCallback (HINTERNET, DWORD_PTR context, DWORD code, void *info, DWORD length)
 Implementation of Microsoft's WINHTTP_STATUS_CALLBACK.
void NetworkHTTPInitialize ()
 Initialize the HTTP socket handler.
void NetworkHTTPUninitialize ()
 Uninitialize the HTTP socket handler.

Variables

static HINTERNET _winhttp_session = nullptr
 Currently running download session.
static std::vector< NetworkHTTPRequest * > _http_requests
 HTTP requests that are currently running.
static std::vector< NetworkHTTPRequest * > _new_http_requests
 HTTP requests that should be started.
static std::mutex _new_http_requests_mutex
 Mutex to prevent concurrent access _new_http_requests.
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.

Detailed Description

WinHTTP-based implementation for HTTP requests.

Definition in file http_winhttp.cpp.

Function Documentation

◆ GetLastErrorAsString()

std::string GetLastErrorAsString ( )
static

Gets the last error from Windows as a string.

Returns
The human readable form of the last error.

Definition at line 76 of file http_winhttp.cpp.

References FS2OTTD().

Referenced by NetworkHTTPRequest::Connect(), and NetworkHTTPRequest::WinHttpCallback().

◆ NetworkHTTPInitialize()

void NetworkHTTPInitialize ( )

Initialize the HTTP socket handler.

Definition at line 357 of file http_winhttp.cpp.

References _http_thread, _http_thread_exit, _winhttp_session, Debug, FileExists(), GetNetworkRevisionString(), HttpThread(), StartNewThread(), and StaticWinHttpCallback().

Referenced by NetworkStartUp().

◆ NetworkHTTPUninitialize()

void NetworkHTTPUninitialize ( )

Uninitialize the HTTP socket handler.

Definition at line 370 of file http_winhttp.cpp.

References _http_cv, _http_mutex, _http_thread, _http_thread_exit, _winhttp_session, NetworkHTTPSocketHandler::HTTPReceive(), and lock.

Referenced by NetworkShutDown().

◆ StaticWinHttpCallback()

void StaticWinHttpCallback ( HINTERNET ,
DWORD_PTR context,
DWORD code,
void * info,
DWORD length )
static

Implementation of Microsoft's WINHTTP_STATUS_CALLBACK.

Parameters
contextPointer to our context, i.e. our request.
codeThe code of the event.
infoThe information about the event.
lengthThe length of the information.

Definition at line 207 of file http_winhttp.cpp.

References NetworkHTTPRequest::WinHttpCallback().

Referenced by NetworkHTTPInitialize().

Variable Documentation

◆ _http_callback_mutex

std::mutex _http_callback_mutex
static

Mutex to prevent concurrent access to _http_callbacks.

Definition at line 53 of file http_winhttp.cpp.

Referenced by NetworkHTTPRequest::~NetworkHTTPRequest().

◆ _http_callbacks

std::vector<HTTPThreadSafeCallback *> _http_callbacks
static

Callback for the current requests.

Definition at line 51 of file http_winhttp.cpp.

Referenced by NetworkHTTPRequest::~NetworkHTTPRequest().

◆ _http_requests

std::vector<NetworkHTTPRequest *> _http_requests
static

HTTP requests that are currently running.

Definition at line 47 of file http_winhttp.cpp.

◆ _new_http_callback_mutex

std::mutex _new_http_callback_mutex
static

Mutex to prevent concurrent access to _new_http_callbacks.

Definition at line 54 of file http_winhttp.cpp.

Referenced by NetworkHTTPRequest::NetworkHTTPRequest(), and NetworkHTTPRequest::NetworkHTTPRequest().

◆ _new_http_callbacks

std::vector<HTTPThreadSafeCallback *> _new_http_callbacks
static

Callbacks for the request that should be started.

Definition at line 52 of file http_winhttp.cpp.

Referenced by NetworkHTTPRequest::NetworkHTTPRequest(), and NetworkHTTPRequest::NetworkHTTPRequest().

◆ _new_http_requests

std::vector<NetworkHTTPRequest *> _new_http_requests
static

HTTP requests that should be started.

Definition at line 48 of file http_winhttp.cpp.

◆ _new_http_requests_mutex

std::mutex _new_http_requests_mutex
static

Mutex to prevent concurrent access _new_http_requests.

Definition at line 49 of file http_winhttp.cpp.

◆ _winhttp_session

HINTERNET _winhttp_session = nullptr
static

Currently running download session.

Definition at line 23 of file http_winhttp.cpp.

Referenced by NetworkHTTPRequest::Connect(), NetworkHTTPInitialize(), and NetworkHTTPUninitialize().