Add restd library.
This commit is contained in:
@@ -7,7 +7,7 @@ set (CMAKE_MODULE_PATH "${MODULE_PATH}")
|
||||
|
||||
link_directories(${CMAKE_SOURCE_DIR}/build/lib)
|
||||
|
||||
include_directories (${CMAKE_SOURCE_DIR}/libasyncd/include)
|
||||
include_directories (${CMAKE_SOURCE_DIR}/domo-iot/lib/include)
|
||||
include_directories (${CMAKE_SOURCE_DIR}/libevent/include)
|
||||
include_directories (${CMAKE_SOURCE_DIR}/build/libevent/include)
|
||||
include_directories (${CMAKE_SOURCE_DIR}/qlibc/include)
|
||||
@@ -26,7 +26,7 @@ add_executable (domo-iot ${source_files})
|
||||
target_link_libraries (domo-iot
|
||||
LINK_PUBLIC
|
||||
nats_static
|
||||
asyncd-static
|
||||
restd-static
|
||||
qlibc-static
|
||||
qlibcext-static
|
||||
event
|
||||
|
||||
44
src/main.c
44
src/main.c
@@ -28,45 +28,41 @@
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <asyncd/asyncd.h>
|
||||
#include <restd.h>
|
||||
|
||||
int my_http_get_handler(short event, ad_conn_t *conn, void *userdata)
|
||||
int my_http_get_handler(short event, restd_conn_t *conn, void *userdata)
|
||||
{
|
||||
if (event & AD_EVENT_READ)
|
||||
if (event & RESTD_EVENT_READ)
|
||||
{
|
||||
if (ad_http_get_status(conn) == AD_HTTP_REQ_DONE)
|
||||
if (restd_http_get_status(conn) == RESTD_HTTP_REQ_DONE)
|
||||
{
|
||||
ad_http_response(conn, 200, "text/html", "Hello World", 11);
|
||||
return ad_http_is_keepalive_request(conn) ? AD_DONE : AD_CLOSE;
|
||||
restd_http_response(conn, 200, "text/html", "Hello World", 11);
|
||||
return restd_http_is_keepalive_request(conn) ? RESTD_DONE : RESTD_CLOSE;
|
||||
}
|
||||
}
|
||||
return AD_OK;
|
||||
return RESTD_OK;
|
||||
}
|
||||
|
||||
int my_http_default_handler(short event, ad_conn_t *conn, void *userdata)
|
||||
int my_http_default_handler(short event, restd_conn_t *conn, void *userdata)
|
||||
{
|
||||
if (event & AD_EVENT_READ)
|
||||
if (event & RESTD_EVENT_READ)
|
||||
{
|
||||
if (ad_http_get_status(conn) == AD_HTTP_REQ_DONE)
|
||||
if (restd_http_get_status(conn) == RESTD_HTTP_REQ_DONE)
|
||||
{
|
||||
ad_http_response(conn, 501, "text/html", "Not implemented", 15);
|
||||
return AD_CLOSE; // Close connection.
|
||||
restd_http_response(conn, 501, "text/html", "Not implemented", 15);
|
||||
return RESTD_CLOSE; // Close connection.
|
||||
}
|
||||
}
|
||||
return AD_OK;
|
||||
return RESTD_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//SSL_load_error_strings();
|
||||
//SSL_library_init();
|
||||
ad_log_level(AD_LOG_DEBUG);
|
||||
ad_server_t *server = ad_server_new();
|
||||
ad_server_set_option(server, "server.port", "8888");
|
||||
//ad_server_set_ssl_ctx(server,
|
||||
// ad_server_ssl_ctx_create_simple("ssl.cert", "ssl.pkey"));
|
||||
ad_server_register_hook(server, ad_http_handler, NULL); // HTTP Parser is also a hook.
|
||||
ad_server_register_hook_on_method(server, "GET", my_http_get_handler, NULL);
|
||||
ad_server_register_hook(server, my_http_default_handler, NULL);
|
||||
return ad_server_start(server);
|
||||
restd_log_level(RESTD_LOG_DEBUG);
|
||||
restd_server_t *server = restd_server_new();
|
||||
restd_server_set_option(server, "server.port", "8888");
|
||||
restd_server_register_hook(server, restd_http_handler, NULL); // HTTP Parser is also a hook.
|
||||
restd_server_register_hook_on_method(server, "GET", my_http_get_handler, NULL);
|
||||
restd_server_register_hook(server, my_http_default_handler, NULL);
|
||||
return restd_server_start(server);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user