Skip to content

Commit 07b9920

Browse files
author
Maijin
committed
Update http_example.c with loop and timeout comment
1 parent 154279b commit 07b9920

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

examples/api/socket/http_example.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ static void *http_server_thread(void *user) {
3030

3131
printf("Server: Listening on %s:%s\n", ADDR, PORT);
3232

33-
RzSocketHTTPOptions so = { .accept_timeout = true, .timeout = 1 };
33+
RzSocketHTTPOptions so = { .accept_timeout = true, .timeout = 1 }; // timeout in seconds
3434
RzSocketHTTPRequest *hr = NULL;
3535

36-
// Accept one request
37-
while (!(hr = rz_socket_http_accept(s, &so))) {
38-
// Wait for connection
39-
}
36+
while(1) {
37+
hr = rz_socket_http_accept(s, &so);
38+
39+
// fail ?
40+
if (!hr) continue;
4041

41-
if (hr) {
42+
// handle the request.
4243
printf("Server: Received %s request for %s\n", hr->method, hr->path);
4344
const char *response_body = "<html><body><h1>Hello from Rizin!</h1></body></html>";
4445
rz_socket_http_response(hr, 200, response_body, strlen(response_body), NULL);

0 commit comments

Comments
 (0)