examples/hello: Update according to handler_loop
This commit is contained in:
parent
98f5f52461
commit
c9edbbc4b0
|
@ -1,9 +1,13 @@
|
|||
# "Hello world" example
|
||||
|
||||
This example shows a minimal setup for an application using `libweb`. When
|
||||
executed, it starts a HTTP/1.1 server on port `8080` and returns an example
|
||||
website reading "Hello from libweb!" when either `/` or `/index.html` are
|
||||
accessed by clients.
|
||||
executed, it starts a HTTP/1.1 server on a random port, which is then printed
|
||||
to the standard output, and returns an example website when either `/` or
|
||||
`/index.html` are accessed by clients, reading:
|
||||
|
||||
```
|
||||
Hello from libweb!
|
||||
```
|
||||
|
||||
## How to build
|
||||
|
||||
|
|
|
@ -81,7 +81,6 @@ static int on_length(const unsigned long long len,
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = EXIT_FAILURE;
|
||||
const short port = 8080;
|
||||
const struct handler_cfg cfg =
|
||||
{
|
||||
.length = on_length
|
||||
|
@ -103,12 +102,22 @@ int main(int argc, char *argv[])
|
|||
goto end;
|
||||
}
|
||||
|
||||
if (handler_listen(h, port))
|
||||
unsigned short outport;
|
||||
|
||||
if (handler_listen(h, 0, &outport))
|
||||
{
|
||||
fprintf(stderr, "%s: handler_listen failed\n", __func__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
printf("Listening on port %hu\n", outport);
|
||||
|
||||
if (handler_loop(h))
|
||||
{
|
||||
fprintf(stderr, "%s: handler_loop failed\n", __func__);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
|
||||
end:
|
||||
|
|
Loading…
Reference in New Issue