Skip to content

Commit

Permalink
Add some api
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Jan 5, 2021
1 parent 8c2e9c3 commit b0bed67
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,24 @@ static void keepalive_cb(struct ev_loop *loop, struct ev_timer *w, int revents)
conn_error(&conn->com, HTTP_STATUS_REQUEST_TIMEOUT, NULL);
}

static struct uh_server *conn_get_server(struct uh_connection *conn)
{
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;

return &conni->srv->com;
}

static struct ev_loop *conn_get_loop(struct uh_connection *conn)
{
struct uh_connection_internal *conni = (struct uh_connection_internal *)conn;

return conni->srv->loop;
}

static void conn_init_cb(struct uh_connection *conn)
{
conn->get_server = conn_get_server;
conn->get_loop = conn_get_loop;
conn->done = conn_done;
conn->send = conn_send;
conn->send_file = conn_send_file;
Expand Down
8 changes: 8 additions & 0 deletions src/uhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ static int uh_set_index_page(struct uh_server *srv, const char *name)
return 0;
}

static struct ev_loop *uh_get_loop(struct uh_server *srv)
{
struct uh_server_internal *srvi = (struct uh_server_internal *)srv;

return srvi->loop;
}

int uh_server_init(struct uh_server *srv, struct ev_loop *loop, const char *host, int port)
{
struct uh_server_internal *srvi = (struct uh_server_internal *)srv;
Expand Down Expand Up @@ -446,6 +453,7 @@ int uh_server_init(struct uh_server *srv, struct ev_loop *loop, const char *host
uh_log_debug("Listen on: %s %d\n", addr_str, port);
}

srv->get_loop = uh_get_loop;
srv->free = uh_server_free;
srv->start_worker = uh_start_worker;

Expand Down
5 changes: 5 additions & 0 deletions src/uhttpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ enum {
UH_EV_COMPLETE
};

struct uh_server;

struct uh_connection {
struct uh_server *(*get_server)(struct uh_connection *conn);
struct ev_loop *(*get_loop)(struct uh_connection *conn);
/*
** Indicates the end of request processing
** Must be called at last, if not call 'error', 'redirect' and 'serve_file'
Expand Down Expand Up @@ -78,6 +82,7 @@ struct uh_connection {
typedef void (*uh_path_handler_prototype)(struct uh_connection *conn, int event);

struct uh_server {
struct ev_loop *(*get_loop)(struct uh_server *srv);
void (*free)(struct uh_server *srv);
/*
** Start n worker processes to process the requests
Expand Down

0 comments on commit b0bed67

Please sign in to comment.