Skip to content

Commit

Permalink
feat: add a method to replace the existing loop
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Sep 5, 2021
1 parent 596347f commit b8ddb7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/uhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ static struct ev_loop *uh_get_loop(struct uh_server *srv)
return srvi->loop;
}

static void uh_set_loop(struct uh_server *srv, struct ev_loop *loop)
{
struct uh_server_internal *srvi = (struct uh_server_internal *)srv;

srvi->loop = loop;
}

static int parse_address(const char *addr, char **host, char **port)
{
static char buf[256];
Expand Down Expand Up @@ -475,6 +482,7 @@ void uh_server_init(struct uh_server *srv, struct ev_loop *loop)
srvi->loop = loop ? loop : EV_DEFAULT;

srv->get_loop = uh_get_loop;
srv->set_loop = uh_set_loop;
srv->free = uh_server_free;

srv->listen = uh_server_listen;
Expand Down
2 changes: 2 additions & 0 deletions src/uhttpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ typedef void (*uh_path_handler_prototype)(struct uh_connection *conn, int event)

struct uh_server {
struct ev_loop *(*get_loop)(struct uh_server *srv);
/* Replace the existing loop. Can only be called before calling the listen */
void (*set_loop)(struct uh_server *srv, struct ev_loop *loop);
void (*free)(struct uh_server *srv);
/*
** listen an address, multiple call allowed
Expand Down

0 comments on commit b8ddb7f

Please sign in to comment.