OCT 1. 更正HTTP Server服务回调函数定义

This commit is contained in:
huangxin 2022-12-07 16:00:28 +08:00
parent f9fa369457
commit 900d86eb6c
4 changed files with 22 additions and 18 deletions

View File

@ -7,6 +7,7 @@
#include "http_response_cache.h"
static bool tcp_nodelay;
extern uv_read_cb http_stream_on_read;
void ipc_read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
int rc;

View File

@ -7,6 +7,8 @@
#include "http_response_cache.h"
#include "hw_string.h"
extern http_server_write_response_cb http_server_write_response;
#define CRLF "\r\n"
KHASH_MAP_INIT_STR(string_hashmap, char *)
@ -78,8 +80,8 @@ hw_string *create_response_buffer(hw_http_response *response) {
int header_buffer_incr = 512;
int body_size = resp->body.length;
int header_size_remaining = header_buffer_incr;
int response_size = header_size_remaining + sizeof(length_header) + num_chars(resp->body.length) + 2 * line_sep_size
+ body_size + line_sep_size;
int response_size = header_size_remaining + sizeof(length_header) + num_chars(resp->body.length) +
2 * line_sep_size + body_size + line_sep_size;
response_string->value = malloc(response_size);

View File

@ -1,6 +1,6 @@
#ifdef PLATFORM_POSIX
#include <signal.h>
#endif// PLATFORM_POSIX
#endif // PLATFORM_POSIX
#include <stdio.h>
#include <stdlib.h>
@ -48,6 +48,8 @@ int listener_count;
uv_async_t *listener_async_handles;
uv_loop_t *listener_event_loops;
uv_barrier_t *listeners_created_barrier;
uv_read_cb http_stream_on_read;
http_server_write_response_cb http_server_write_response;
int hw_init_with_config(configuration *c) {
#ifdef DEBUG
@ -132,7 +134,7 @@ void hw_http_add_route(char *route, http_request_callback callback, void *user_d
routes = kh_init(string_hashmap);
}
set_route(routes, route, route_entry);
dzlog_debug("Added route path: [%s]\n", route);// TODO: Replace with logging instead.
dzlog_debug("Added route path: [%s]\n", route); // TODO: Replace with logging instead.
}
void free_http_server() {
@ -145,7 +147,7 @@ void free_http_server() {
free((char *)v);
});
kh_destroy(string_hashmap, routes);
uv_close((uv_handle_t*)&server, NULL);
uv_close((uv_handle_t *)&server, NULL);
uninit_http_request_cache();
dzlog_debug("HTTP Server Close http://%s:%d\n", config->http_listen_address, config->http_listen_port);
}
@ -168,7 +170,7 @@ int hw_http_open() {
#ifdef UNIX
signal(SIGPIPE, SIG_IGN);
#endif// UNIX
#endif // UNIX
listener_count = threads;

View File

@ -25,8 +25,7 @@ extern uv_async_t *listener_async_handles;
extern uv_loop_t *listener_event_loops;
extern uv_barrier_t *listeners_created_barrier;
void (*http_stream_on_read)(uv_stream_t *, ssize_t, const uv_buf_t *);
int (*http_server_write_response)(hw_write_context *, hw_string *);
typedef int (*http_server_write_response_cb)(hw_write_context *, hw_string *);
http_connection *create_http_connection();
void http_stream_on_connect(uv_stream_t *stream, int status);