OpenTTD Source
12.0-beta2
|
Base socket handler for HTTP traffic. More...
#include <tcp_http.h>
Public Member Functions | |
bool | IsConnected () const |
Whether this socket is currently bound to a socket. More... | |
void | CloseSocket () |
Close the actual socket of the connection. | |
NetworkHTTPSocketHandler (SOCKET sock, HTTPCallback *callback, const std::string &host, const char *url, const char *data, int depth) | |
Start the querying. More... | |
~NetworkHTTPSocketHandler () | |
Free whatever needs to be freed. | |
![]() | |
NetworkSocketHandler () | |
Create a new unbound socket. | |
virtual | ~NetworkSocketHandler () |
Close the socket when destructing the socket handler. | |
void | MarkClosed () |
Mark the connection as closed. More... | |
bool | HasClientQuit () const |
Whether the current client connected to the socket has quit. More... | |
void | Reopen () |
Reopen the socket so we can send/receive stuff again. | |
Static Public Member Functions | |
static int | Connect (char *uri, HTTPCallback *callback, const char *data=nullptr, int depth=0) |
Connect to the given URI. More... | |
static void | HTTPReceive () |
Do the receiving for all HTTP connections. | |
Data Fields | |
SOCKET | sock |
The socket currently connected to. | |
Private Member Functions | |
int | HandleHeader () |
Handle the header of a HTTP reply. More... | |
int | Receive () |
Handle receiving of HTTP data. More... | |
Private Attributes | |
char | recv_buffer [4096] |
Partially received message. | |
int | recv_pos |
Current position in buffer. | |
int | recv_length |
Length of the data still retrieving. | |
HTTPCallback * | callback |
The callback to call for the incoming data. | |
const char * | data |
The (POST) data we might want to forward (to a redirect). | |
int | redirect_depth |
The depth of the redirection. | |
Base socket handler for HTTP traffic.
Definition at line 38 of file tcp_http.h.
NetworkHTTPSocketHandler::NetworkHTTPSocketHandler | ( | SOCKET | s, |
HTTPCallback * | callback, | ||
const std::string & | host, | ||
const char * | url, | ||
const char * | data, | ||
int | depth | ||
) |
Start the querying.
s | the socket of this connection |
callback | the callback for HTTP retrieval |
host | the hostname of the server to connect to |
url | the url at the server |
data | the data to send |
depth | the depth (redirect recursion) of the queries |
Definition at line 34 of file tcp_http.cpp.
References _http_connections, data, Debug, GetNetworkRevisionString(), HTTPCallback::OnFailure(), and sock.
|
static |
Connect to the given URI.
uri | the URI to connect to. |
callback | the callback to send data back on. |
data | the data we want to send (as POST). |
depth | the recursion/redirect depth. |
Definition at line 192 of file tcp_http.cpp.
References callback, data, and return_error.
Referenced by HandleHeader().
|
private |
Handle the header of a HTTP reply.
Definition at line 105 of file tcp_http.cpp.
References callback, Connect(), CONTENT_LENGTH, data, Debug, END_OF_HEADER, HTTP_1_0, HTTP_1_1, LOCATION, NEWLINE, recv_buffer, redirect_depth, and return_error.
Referenced by Receive().
|
inline |
Whether this socket is currently bound to a socket.
Definition at line 56 of file tcp_http.h.
|
private |
Handle receiving of HTTP data.
Definition at line 221 of file tcp_http.cpp.
References NetworkError::AsString(), callback, Debug, END_OF_HEADER, NetworkError::GetLast(), HandleHeader(), NetworkError::IsConnectionReset(), lengthof, HTTPCallback::OnReceiveData(), recv_buffer, recv_length, recv_pos, sock, and NetworkError::WouldBlock().
Referenced by HTTPReceive().