[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 255/335: clean up example
From: |
gnunet |
Subject: |
[libmicrohttpd] 255/335: clean up example |
Date: |
Sat, 27 Jul 2024 22:02:31 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to tag stf-m2
in repository libmicrohttpd.
commit 8a8fd51909bd8acd4f4f7d56d78bff780cc854c8
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jul 21 17:11:54 2024 +0200
clean up example
---
src/examples/minimal_example2.c | 72 ++++++++++++++++++++---------------
src/tests/basic/libtest_convenience.c | 32 +++++++++++-----
2 files changed, 64 insertions(+), 40 deletions(-)
diff --git a/src/examples/minimal_example2.c b/src/examples/minimal_example2.c
index 6973fcf3..b743c535 100644
--- a/src/examples/minimal_example2.c
+++ b/src/examples/minimal_example2.c
@@ -36,13 +36,17 @@ req_cb (void *cls,
{
static const char res_msg[] = "Hello there!";
- (void) cls; (void) path; (void) method; (void) upload_size; /* Unused */
+ (void) cls;
+ (void) path;
+ (void) method;
+ (void) upload_size; /* Unused */
return MHD_action_from_response (
request,
- MHD_response_from_buffer_static (MHD_HTTP_STATUS_OK,
- sizeof(res_msg) / sizeof(char) - 1,
- res_msg));
+ MHD_response_from_buffer_static (
+ MHD_HTTP_STATUS_OK,
+ sizeof(res_msg) / sizeof(char) - 1,
+ res_msg));
}
@@ -55,7 +59,9 @@ main (int argc,
if (argc != 2)
{
- fprintf (stderr,"Usage:\n%s PORT\n", argv[0]);
+ fprintf (stderr,
+ "Usage:\n%s PORT\n",
+ argv[0]);
return 1;
}
port = atoi (argv[1]);
@@ -65,33 +71,39 @@ main (int argc,
"The port must be a number between 1 and 65535.\n");
return 2;
}
- d = MHD_daemon_create (&req_cb, NULL);
- if (NULL != d)
+ d = MHD_daemon_create (&req_cb,
+ NULL);
+ if (NULL == d)
+ {
+ fprintf (stderr,
+ "Failed to create MHD daemon.\n");
+ return 3;
+ }
+ if (MHD_SC_OK !=
+ MHD_DAEMON_SET_OPTIONS (
+ d,
+ MHD_D_OPTION_WM_WORKER_THREADS (1),
+ MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO,
+ (uint_least16_t) port)))
{
- if (MHD_SC_OK ==
- MHD_DAEMON_SET_OPTIONS (d,
- MHD_D_OPTION_WM_WORKER_THREADS (1),
- MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO,
- (uint_least16_t)
port)))
- {
- if (MHD_SC_OK == MHD_daemon_start (d))
- {
- printf ("The MHD daemon is listening on port %d\n"
- "Press ENTER to stop.\n", port);
- (void) fgetc (stdin);
- }
- else
- fprintf (stderr, "Failed to start MHD daemon.\n");
- }
- else
- fprintf (stderr, "Failed to set MHD daemon run parameters.\n");
- printf ("Stopping... ");
+ fprintf (stderr,
+ "Failed to set MHD daemon run parameters.\n");
MHD_daemon_destroy (d);
- printf ("OK\n");
-
+ return 4;
}
- else
- fprintf (stderr, "Failed to create MHD daemon.\n");
-
+ if (MHD_SC_OK !=
+ MHD_daemon_start (d))
+ {
+ fprintf (stderr,
+ "Failed to start MHD daemon.\n");
+ MHD_daemon_destroy (d);
+ return 5;
+ }
+ printf ("The MHD daemon is listening on port %d\n"
+ "Press ENTER to stop.\n", port);
+ (void) fgetc (stdin);
+ printf ("Stopping... ");
+ MHD_daemon_destroy (d);
+ printf ("OK\n");
return 0;
}
diff --git a/src/tests/basic/libtest_convenience.c
b/src/tests/basic/libtest_convenience.c
index d7701b3c..65b37e83 100644
--- a/src/tests/basic/libtest_convenience.c
+++ b/src/tests/basic/libtest_convenience.c
@@ -38,9 +38,11 @@ MHDT_server_setup_minimal (void *cls,
struct MHD_Daemon *d)
{
if (MHD_SC_OK !=
- MHD_DAEMON_SET_OPTIONS (d,
- MHD_D_OPTION_BIND_PORT (MHD_AF_DUAL,
- 0)))
+ MHD_DAEMON_SET_OPTIONS (
+ d,
+ MHD_D_OPTION_WM_WORKER_THREADS (1),
+ MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO,
+ 0)))
return "Failed to bind to port 0!";
return NULL;
}
@@ -83,20 +85,30 @@ MHDT_server_run_blocking (void *cls,
int finsig,
struct MHD_Daemon *d)
{
- char e;
+ fd_set r;
- while (-1 ==
- read (finsig,
- &e,
- 1))
+ FD_ZERO (&r);
+ FD_SET (finsig, &r);
+ while (1)
{
- if (EAGAIN != errno)
+ struct timeval timeout = {
+ .tv_usec = 1000 /* 1000 microseconds */
+ };
+
+ if ( (-1 ==
+ select (finsig + 1,
+ &r,
+ NULL,
+ NULL,
+ &timeout)) &&
+ (EAGAIN != errno) )
{
fprintf (stderr,
- "Failure reading termination signal: %s\n",
+ "Failure waiting on termination signal: %s\n",
strerror (errno));
break;
}
+
if (MHD_SC_OK !=
MHD_daemon_process_blocking (d,
1000))
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] 252/335: expand test suite, (continued)
- [libmicrohttpd] 252/335: expand test suite, gnunet, 2024/07/27
- [libmicrohttpd] 260/335: Copy-paste & merge errors clean-up, gnunet, 2024/07/27
- [libmicrohttpd] 247/335: WIP-5 fixes, gnunet, 2024/07/27
- [libmicrohttpd] 261/335: split up convenience API, gnunet, 2024/07/27
- [libmicrohttpd] 250/335: fix shadowing, gnunet, 2024/07/27
- [libmicrohttpd] 264/335: expand test suite to cover upload and sendfile(), gnunet, 2024/07/27
- [libmicrohttpd] 233/335: -wrong variable, gnunet, 2024/07/27
- [libmicrohttpd] 263/335: -remove redundant comments, gnunet, 2024/07/27
- [libmicrohttpd] 262/335: expand test suite to cover more threading modes, gnunet, 2024/07/27
- [libmicrohttpd] 266/335: ignore, gnunet, 2024/07/27
- [libmicrohttpd] 255/335: clean up example,
gnunet <=
- [libmicrohttpd] 256/335: minimal_example2: saved two extra calls of MHD_daemon_destroy(), gnunet, 2024/07/27
- [libmicrohttpd] 274/335: daemon_start.c: make sure that sys symbols defined, gnunet, 2024/07/27
- [libmicrohttpd] 276/335: Workaround for Linux kernel bug, gnunet, 2024/07/27
- [libmicrohttpd] 267/335: epoll and other fixes, gnunet, 2024/07/27
- [libmicrohttpd] 249/335: fix FTBFS issues, gnunet, 2024/07/27
- [libmicrohttpd] 270/335: -fix test setup logic, gnunet, 2024/07/27
- [libmicrohttpd] 258/335: fix copy and paste bug, gnunet, 2024/07/27
- [libmicrohttpd] 271/335: Make sure that connection is closed if disconnected remotely, gnunet, 2024/07/27
- [libmicrohttpd] 265/335: add test with chunked upload, gnunet, 2024/07/27
- [libmicrohttpd] 272/335: Fixes, gnunet, 2024/07/27