Refactoring for an improved event loop

This commit is contained in:
2025-07-21 20:29:35 +02:00
parent 5cb3977c3c
commit a2912b5191
17 changed files with 3001 additions and 2381 deletions
+36 -44
View File
@@ -386,7 +386,7 @@ typedef struct {
void *data0;
int data1;
int data2;
} HTTP_RequestHandle;
} HTTP_RequestBuilder;
// Initialize a client object. If something goes wrong,
// NULL is returned.
@@ -398,7 +398,38 @@ void http_client_free(HTTP_Client *client);
// Create a request object associated to the given client.
// On success, 0 is returned and the handle is initialized.
// On error, -1 is returned.
int http_client_request(HTTP_Client *client, HTTP_RequestHandle *handle);
int http_client_get_builder(HTTP_Client *client, HTTP_RequestBuilder *builder);
void http_request_builder_user_data(HTTP_RequestBuilder builder, void *user_data);
// Enable/disable I/O tracing for the specified request.
// This must be done when the request is in the initialization
// phase.
void http_request_builder_trace(HTTP_RequestBuilder builder, bool trace);
// Set the method and URL of the specified request object.
// This must be the first thing you do after http_client_request
// is called (you may http_request_trace before, but nothing
// else!)
void http_request_builder_line(HTTP_RequestBuilder builder, HTTP_Method method, HTTP_String url);
// Append a header to the specified request. You must call
// this after http_request_line and may do so multiple times.
void http_request_builder_header(HTTP_RequestBuilder builder, HTTP_String str);
// Append some data to the request's body. You must call
// this after either http_request_line or http_request_header.
void http_request_builder_body(HTTP_RequestBuilder builder, HTTP_String str);
// Mark the initialization of the request as completed and
// perform the request.
void http_request_builder_submit(HTTP_RequestBuilder builder);
// Free resources associated to a request. This must be called
// after the request has completed.
//
// TODO: allow aborting pending requests
void http_response_free(HTTP_Client *client, HTTP_Response *res);
// Wait for the completion of one request associated to
// the client. The handle of the resolved request is returned
@@ -411,55 +442,16 @@ int http_client_request(HTTP_Client *client, HTTP_RequestHandle *handle);
//
// Note that calling this function when no requests are
// pending is considered an error.
int http_client_wait(HTTP_Client *client, HTTP_RequestHandle *handle);
// Enable/disable I/O tracing for the specified request.
// This must be done when the request is in the initialization
// phase.
void http_request_trace(HTTP_RequestHandle handle, bool trace);
// Set the method and URL of the specified request object.
// This must be the first thing you do after http_client_request
// is called (you may http_request_trace before, but nothing
// else!)
void http_request_line(HTTP_RequestHandle handle, HTTP_Method method, HTTP_String url);
// Append a header to the specified request. You must call
// this after http_request_line and may do so multiple times.
void http_request_header(HTTP_RequestHandle handle, HTTP_String str);
// Append some data to the request's body. You must call
// this after either http_request_line or http_request_header.
void http_request_body(HTTP_RequestHandle handle, HTTP_String str);
// Mark the initialization of the request as completed and
// perform the request.
void http_request_submit(HTTP_RequestHandle handle);
// Retrieve the response to the specified request. If the
// request hasn't completed or it couldn't be performed
// due to an error, NULL is returned. If the request completed,
// the parsed response object is returned.
//
// Note that responses 4xx and 5xx code responses are still
// considered as successes from cHTTP's perspective.
HTTP_Response *http_request_result(HTTP_RequestHandle handle);
// Free resources associated to a request. This must be called
// after the request has completed.
//
// TODO: allow aborting pending requests
void http_request_free(HTTP_RequestHandle handle);
int http_client_wait(HTTP_Client *client, HTTP_Response **res, void **user_data);
// TODO: comment
HTTP_Response *http_get(HTTP_String url,
HTTP_String *headers, int num_headers,
HTTP_RequestHandle *phandle);
HTTP_String *headers, int num_headers);
// TODO: comment
HTTP_Response *http_post(HTTP_String url,
HTTP_String *headers, int num_headers,
HTTP_String body, HTTP_RequestHandle *phandle);
HTTP_String body);
#endif // CLIENT_INCLUDED