libuhttpd: New API
int uh_server_open(const char *host, int port); void uh_server_init(struct uh_server *srv, int sock); Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>main
parent
3920100e64
commit
dcb397a62c
|
@ -102,8 +102,10 @@ int main(int argc, char **argv)
|
||||||
done:
|
done:
|
||||||
uloop_done();
|
uloop_done();
|
||||||
|
|
||||||
if (srv)
|
if (srv) {
|
||||||
srv->free(srv);
|
srv->free(srv);
|
||||||
|
free(srv);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
37
src/uhttpd.c
37
src/uhttpd.c
|
@ -53,7 +53,6 @@ static void uh_server_free(struct uh_server *srv)
|
||||||
uh_ssl_free();
|
uh_ssl_free();
|
||||||
free(srv->docroot);
|
free(srv->docroot);
|
||||||
free(srv->index_file);
|
free(srv->index_file);
|
||||||
free(srv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,23 +63,19 @@ static void uh_accept_cb(struct uloop_fd *fd, unsigned int events)
|
||||||
uh_accept_client(srv, srv->ssl);
|
uh_accept_client(srv, srv->ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct uh_server *uh_server_new(const char *host, int port)
|
int uh_server_open(const char *host, int port)
|
||||||
{
|
{
|
||||||
struct uh_server *srv = NULL;
|
int sock = usock(USOCK_TCP | USOCK_SERVER | USOCK_IPV4ONLY, host, usock_port(port));
|
||||||
int sock = -1;
|
|
||||||
|
|
||||||
sock = usock(USOCK_TCP | USOCK_SERVER | USOCK_IPV4ONLY, host, usock_port(port));
|
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
uh_log_err("usock");
|
uh_log_err("usock");
|
||||||
return NULL;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
srv = calloc(1, sizeof(struct uh_server));
|
return sock;
|
||||||
if (!srv) {
|
}
|
||||||
uh_log_err("calloc");
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void uh_server_init(struct uh_server *srv, int sock)
|
||||||
|
{
|
||||||
srv->docroot = strdup(".");
|
srv->docroot = strdup(".");
|
||||||
srv->index_file = strdup("index.html");
|
srv->index_file = strdup("index.html");
|
||||||
|
|
||||||
|
@ -99,6 +94,24 @@ struct uh_server *uh_server_new(const char *host, int port)
|
||||||
#if (UHTTPD_SSL_SUPPORT)
|
#if (UHTTPD_SSL_SUPPORT)
|
||||||
srv->ssl_init = uh_ssl_init;
|
srv->ssl_init = uh_ssl_init;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
struct uh_server *uh_server_new(const char *host, int port)
|
||||||
|
{
|
||||||
|
struct uh_server *srv;
|
||||||
|
int sock;
|
||||||
|
|
||||||
|
sock = uh_server_open(host, port);
|
||||||
|
if (sock < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
srv = calloc(1, sizeof(struct uh_server));
|
||||||
|
if (!srv) {
|
||||||
|
uh_log_err("calloc");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
uh_server_init(srv, sock);
|
||||||
|
|
||||||
return srv;
|
return srv;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,9 @@ struct uh_server {
|
||||||
|
|
||||||
struct uh_server *uh_server_new(const char *host, int port);
|
struct uh_server *uh_server_new(const char *host, int port);
|
||||||
|
|
||||||
|
int uh_server_open(const char *host, int port);
|
||||||
|
void uh_server_init(struct uh_server *srv, int sock);
|
||||||
|
|
||||||
#if (UHTTPD_LUA_SUPPORT)
|
#if (UHTTPD_LUA_SUPPORT)
|
||||||
void uh_template(struct uh_client *cl);
|
void uh_template(struct uh_client *cl);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue