OCT 1. 更正HTTP Server服务回调函数定义
This commit is contained in:
parent
f9fa369457
commit
900d86eb6c
|
@ -7,6 +7,7 @@
|
||||||
#include "http_response_cache.h"
|
#include "http_response_cache.h"
|
||||||
|
|
||||||
static bool tcp_nodelay;
|
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) {
|
void ipc_read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "http_response_cache.h"
|
#include "http_response_cache.h"
|
||||||
#include "hw_string.h"
|
#include "hw_string.h"
|
||||||
|
|
||||||
|
extern http_server_write_response_cb http_server_write_response;
|
||||||
|
|
||||||
#define CRLF "\r\n"
|
#define CRLF "\r\n"
|
||||||
KHASH_MAP_INIT_STR(string_hashmap, char *)
|
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 header_buffer_incr = 512;
|
||||||
int body_size = resp->body.length;
|
int body_size = resp->body.length;
|
||||||
int header_size_remaining = header_buffer_incr;
|
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
|
int response_size = header_size_remaining + sizeof(length_header) + num_chars(resp->body.length) +
|
||||||
+ body_size + line_sep_size;
|
2 * line_sep_size + body_size + line_sep_size;
|
||||||
|
|
||||||
response_string->value = malloc(response_size);
|
response_string->value = malloc(response_size);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifdef PLATFORM_POSIX
|
#ifdef PLATFORM_POSIX
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#endif// PLATFORM_POSIX
|
#endif // PLATFORM_POSIX
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -39,15 +39,17 @@ static uv_tcp_t server;
|
||||||
static http_parser_settings parser_settings;
|
static http_parser_settings parser_settings;
|
||||||
static struct sockaddr_in listen_address;
|
static struct sockaddr_in listen_address;
|
||||||
|
|
||||||
uv_loop_t *uv_loop;
|
uv_loop_t *uv_loop;
|
||||||
void *routes;
|
void *routes;
|
||||||
hw_string *http_v1_0;
|
hw_string *http_v1_0;
|
||||||
hw_string *http_v1_1;
|
hw_string *http_v1_1;
|
||||||
hw_string *server_name;
|
hw_string *server_name;
|
||||||
int listener_count;
|
int listener_count;
|
||||||
uv_async_t *listener_async_handles;
|
uv_async_t *listener_async_handles;
|
||||||
uv_loop_t *listener_event_loops;
|
uv_loop_t *listener_event_loops;
|
||||||
uv_barrier_t *listeners_created_barrier;
|
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) {
|
int hw_init_with_config(configuration *c) {
|
||||||
#ifdef DEBUG
|
#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);
|
routes = kh_init(string_hashmap);
|
||||||
}
|
}
|
||||||
set_route(routes, route, route_entry);
|
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() {
|
void free_http_server() {
|
||||||
|
@ -145,13 +147,13 @@ void free_http_server() {
|
||||||
free((char *)v);
|
free((char *)v);
|
||||||
});
|
});
|
||||||
kh_destroy(string_hashmap, routes);
|
kh_destroy(string_hashmap, routes);
|
||||||
uv_close((uv_handle_t*)&server, NULL);
|
uv_close((uv_handle_t *)&server, NULL);
|
||||||
uninit_http_request_cache();
|
uninit_http_request_cache();
|
||||||
dzlog_debug("HTTP Server Close http://%s:%d\n", config->http_listen_address, config->http_listen_port);
|
dzlog_debug("HTTP Server Close http://%s:%d\n", config->http_listen_address, config->http_listen_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
int hw_http_open() {
|
int hw_http_open() {
|
||||||
int threads = (int)config->thread_count;
|
int threads = (int)config->thread_count;
|
||||||
static uv_async_t service_handle;
|
static uv_async_t service_handle;
|
||||||
|
|
||||||
if (routes == NULL) {
|
if (routes == NULL) {
|
||||||
|
@ -168,7 +170,7 @@ int hw_http_open() {
|
||||||
|
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
#endif// UNIX
|
#endif // UNIX
|
||||||
|
|
||||||
listener_count = threads;
|
listener_count = threads;
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,7 @@ extern uv_async_t *listener_async_handles;
|
||||||
extern uv_loop_t *listener_event_loops;
|
extern uv_loop_t *listener_event_loops;
|
||||||
extern uv_barrier_t *listeners_created_barrier;
|
extern uv_barrier_t *listeners_created_barrier;
|
||||||
|
|
||||||
void (*http_stream_on_read)(uv_stream_t *, ssize_t, const uv_buf_t *);
|
typedef int (*http_server_write_response_cb)(hw_write_context *, hw_string *);
|
||||||
int (*http_server_write_response)(hw_write_context *, hw_string *);
|
|
||||||
|
|
||||||
http_connection *create_http_connection();
|
http_connection *create_http_connection();
|
||||||
void http_stream_on_connect(uv_stream_t *stream, int status);
|
void http_stream_on_connect(uv_stream_t *stream, int status);
|
||||||
|
|
Loading…
Reference in New Issue