src/examples: muted compiler warnings

This commit is contained in:
Evgeny Grin (Karlson2k)
2022-06-01 22:12:37 +03:00
parent 74c2eba238
commit 93dcf8ea91
21 changed files with 209 additions and 54 deletions
+2 -2
View File
@@ -778,8 +778,8 @@ main (int argc, char *const *argv)
break; /* fatal internal error */
if (MHD_get_timeout64 (d, &mhd_timeout) == MHD_YES)
{
tv.tv_sec = mhd_timeout / 1000;
tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
tv.tv_sec = (time_t) mhd_timeout / 1000;
tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
tvp = &tv;
}
else
+2 -2
View File
@@ -109,7 +109,7 @@ main (int argc, char *const *argv)
if ( (argc != 2) ||
(1 != sscanf (argv[1], "%u", &port)) ||
(UINT16_MAX < port) )
(65535 < port) )
{
fprintf (stderr,
"%s PORT\n", argv[0]);
@@ -118,7 +118,7 @@ main (int argc, char *const *argv)
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
+9 -1
View File
@@ -141,12 +141,20 @@ main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
unsigned int i;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
response = MHD_create_response_from_buffer_static (strlen (PAGE),
(const void *) PAGE);
#if 0
@@ -160,7 +168,7 @@ main (int argc, char *const *argv)
| MHD_USE_EPOLL | MHD_USE_TURBO
#endif
,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_THREAD_POOL_SIZE, (unsigned
+9 -1
View File
@@ -207,12 +207,20 @@ main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
unsigned int i;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
response = MHD_create_response_from_buffer_static (strlen (PAGE),
(const void *) PAGE);
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
@@ -220,7 +228,7 @@ main (int argc, char *const *argv)
| MHD_USE_EPOLL | MHD_USE_TURBO
#endif
,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_THREAD_POOL_SIZE, (unsigned
+5 -1
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2015 Christian Grothoff (and other contributing authors)
Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -73,7 +74,10 @@ callback (void *cls,
}
* End of pseudo code. */
/* Return amount of data copied to buffer. */
return size_to_copy;
/* The 'buf_size' is always smaller than SSIZE_MAX therefore it's safe
* to cast 'size_to_copy' to 'ssize_t'. */
/* assert (size_to_copy <= buf_size); */
return (ssize_t) size_to_copy;
}
+12 -6
View File
@@ -29,10 +29,12 @@
#include <stdlib.h>
#define PAGE \
"<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
"<html><head><title>libmicrohttpd demo</title></head>" \
"<body>Access granted</body></html>"
#define DENIED \
"<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
"<html><head><title>libmicrohttpd demo</title></head>" \
"<body>Access denied</body></html>"
#define MY_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4"
@@ -116,12 +118,16 @@ main (int argc, char *const *argv)
ssize_t len;
size_t off;
struct MHD_Daemon *d;
unsigned int port;
if (argc != 2)
if ( (argc != 2) ||
(1 != sscanf (argv[1], "%u", &port)) ||
(65535 < port) )
{
printf ("%s PORT\n", argv[0]);
return 1;
}
fd = open ("/dev/urandom", O_RDONLY);
if (-1 == fd)
{
@@ -134,7 +140,7 @@ main (int argc, char *const *argv)
while (off < 8)
{
len = read (fd, rnd, 8);
if (len == -1)
if (0 > len)
{
fprintf (stderr, "Failed to read `%s': %s\n",
"/dev/urandom",
@@ -142,12 +148,12 @@ main (int argc, char *const *argv)
(void) close (fd);
return 1;
}
off += len;
off += (size_t) len;
}
(void) close (fd);
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof(rnd), rnd,
MHD_OPTION_NONCE_NC_SIZE, 300,
+9 -1
View File
@@ -75,16 +75,24 @@ main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
struct handler_param data_for_handler;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
data_for_handler.response_page = PAGE;
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
| MHD_USE_DUAL_STACK,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, &data_for_handler,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_END);
+11 -2
View File
@@ -100,7 +100,7 @@ ahc_echo (void *cls,
}
else
{
response = MHD_create_response_from_fd64 (buf.st_size, fd);
response = MHD_create_response_from_fd64 ((uint64_t) buf.st_size, fd);
if (NULL == response)
{
if (0 != close (fd))
@@ -118,15 +118,24 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
+11 -2
View File
@@ -169,7 +169,8 @@ ahc_echo (void *cls,
}
else
{
response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k page size */
response = MHD_create_response_from_callback ((size_t) buf.st_size,
32 * 1024, /* 32k page size */
&file_reader,
file,
&file_free_callback);
@@ -189,15 +190,23 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (NULL == d)
return 1;
@@ -107,7 +107,8 @@ ahc_echo (void *cls,
}
else
{
response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k page size */
response = MHD_create_response_from_callback ((size_t) buf.st_size,
32 * 1024, /* 32k page size */
&file_reader,
file,
&free_callback);
@@ -135,21 +136,34 @@ main (int argc, char *const *argv)
fd_set es;
MHD_socket max;
uint64_t mhd_timeout;
int port;
if (argc != 3)
{
printf ("%s PORT SECONDS-TO-RUN\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
end = time (NULL) + atoi (argv[2]);
while ((t = time (NULL)) < end)
{
#if ! defined(_WIN32) || defined(__CYGWIN__)
tv.tv_sec = end - t;
#else /* Native W32 */
tv.tv_sec = (long) (end - t);
#endif /* Native W32 */
tv.tv_usec = 0;
max = 0;
FD_ZERO (&rs);
@@ -161,11 +175,15 @@ main (int argc, char *const *argv)
{
if (((uint64_t) tv.tv_sec) < mhd_timeout / 1000LL)
{
tv.tv_sec = mhd_timeout / 1000LL;
tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000LL)) * 1000LL;
#if ! defined(_WIN32) || defined(__CYGWIN__)
tv.tv_sec = (time_t) (mhd_timeout / 1000LL);
#else /* Native W32 */
tv.tv_sec = (long) (mhd_timeout / 1000LL);
#endif /* Native W32 */
tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
}
}
if (-1 == select (max + 1, &rs, &ws, &es, &tv))
if (-1 == select ((int) max + 1, &rs, &ws, &es, &tv))
{
if (EINTR != errno)
abort ();
+9 -4
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2019 Christian Grothoff (and other contributing authors)
Copyright (C) 2019-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file http_compression.c
* @brief minimal example for how to compress HTTP response
* @author Silvio Clecio (silvioprog)
* @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -68,14 +70,14 @@ body_compress (void **buf,
uLongf cbuf_size;
int ret;
cbuf_size = compressBound (*buf_size);
cbuf_size = compressBound ((uLong) * buf_size);
cbuf = malloc (cbuf_size);
if (NULL == cbuf)
return MHD_NO;
ret = compress (cbuf,
&cbuf_size,
(const Bytef *) *buf,
*buf_size);
(uLong) * buf_size);
if ((Z_OK != ret) ||
(cbuf_size >= *buf_size))
{
@@ -165,15 +167,18 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
unsigned int port;
if (argc != 2)
if ( (argc != 2) ||
(1 != sscanf (argv[1], "%u", &port)) ||
(65535 < port) )
{
printf ("%s PORT\n", argv[0]);
return 1;
}
d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
| MHD_USE_ERROR_LOG,
atoi (argv[1]), NULL, NULL,
(uint16_t) port, NULL, NULL,
&ahc_echo, NULL,
MHD_OPTION_END);
if (NULL == d)
+2 -1
View File
@@ -186,7 +186,8 @@ http_ahc (void *cls,
}
else
{
response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k PAGE_NOT_FOUND size */
response = MHD_create_response_from_callback ((size_t) buf.st_size,
32 * 1024, /* 32k page size */
&file_reader, file,
&file_free_callback);
if (NULL == response)
+9 -1
View File
@@ -82,19 +82,27 @@ main (int argc,
{
struct MHD_Daemon *d;
struct handler_param data_for_handler;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
data_for_handler.response_page = PAGE;
d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
/* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
/* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, &data_for_handler,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
+11 -1
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007, 2008 Christian Grothoff (and other contributing authors)
Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file minimal_example.c
* @brief minimal example for how to generate an infinite stream with libmicrohttpd
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -77,15 +79,23 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 1;
+11 -1
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007 Christian Grothoff (and other contributing authors)
Copyright (C) 2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file minimal_example.c
* @brief minimal example for how to use libmicrohttpd
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -69,18 +71,26 @@ main (int argc,
char *const *argv)
{
struct MHD_Daemon *d;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
/* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
/* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
+12 -2
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007 Christian Grothoff (and other contributing authors)
Copyright (C) 2021-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,9 +18,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file minimal_example_empty_ssl.c
* @file minimal_example_empty_tls.c
* @brief minimal example for how to use libmicrohttpd
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -135,19 +137,27 @@ main (int argc,
char *const *argv)
{
struct MHD_Daemon *d;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
| MHD_USE_TLS,
/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
/* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
/* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
+16 -4
View File
@@ -736,16 +736,24 @@ main (int argc, char *const *argv)
fd_set es;
MHD_socket max;
uint64_t mhd_timeout;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
/* initialize PRNG */
srand ((unsigned int) time (NULL));
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL,
&create_response, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
@@ -765,13 +773,17 @@ main (int argc, char *const *argv)
break; /* fatal internal error */
if (MHD_get_timeout64 (d, &mhd_timeout) == MHD_YES)
{
tv.tv_sec = mhd_timeout / 1000;
tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
#if ! defined(_WIN32) || defined(__CYGWIN__)
tv.tv_sec = (time_t) (mhd_timeout / 1000LL);
#else /* Native W32 */
tv.tv_sec = (long) (mhd_timeout / 1000LL);
#endif /* Native W32 */
tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
tvp = &tv;
}
else
tvp = NULL;
if (-1 == select (max + 1, &rs, &ws, &es, tvp))
if (-1 == select ((int) max + 1, &rs, &ws, &es, tvp))
{
if (EINTR != errno)
abort ();
+8 -4
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2007, 2008 Christian Grothoff (and other contributing authors)
Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -21,6 +22,7 @@
* @brief example for how to get the query string from libmicrohttpd
* Call with an URI ending with something like "?q=QUERY"
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
@@ -43,6 +45,7 @@ ahc_echo (void *cls,
struct MHD_Response *response;
enum MHD_Result ret;
int resp_len;
size_t buf_size;
(void) cls; /* Unused. Silent compiler warning. */
(void) url; /* Unused. Silent compiler warning. */
(void) version; /* Unused. Silent compiler warning. */
@@ -62,18 +65,19 @@ ahc_echo (void *cls,
if (NULL == val)
return MHD_NO; /* No "q" argument was found */
resp_len = snprintf (NULL, 0, PAGE, "q", val);
if (0 > resp_len)
if (0 >= resp_len)
return MHD_NO; /* Error calculating response size */
me = malloc (resp_len + 1);
buf_size = (size_t) resp_len + 1; /* Add one byte for zero-termination */
me = malloc (buf_size);
if (me == NULL)
return MHD_NO; /* Error allocating memory */
if (resp_len != snprintf (me, resp_len + 1, PAGE, "q", val))
if (resp_len != snprintf (me, buf_size, PAGE, "q", val))
{
free (me);
return MHD_NO; /* Error forming the response body */
}
response =
MHD_create_response_from_buffer_with_free_callback (resp_len,
MHD_create_response_from_buffer_with_free_callback (buf_size - 1,
(void *) me,
&free);
if (response == NULL)
+16 -8
View File
@@ -33,14 +33,15 @@ struct handler_param
const char *askpage =
"<html><body>\n\
Upload a file, please!<br>\n\
<form action=\"/filepost\" method=\"post\" enctype=\"multipart/form-data\">\n\
<input name=\"file\" type=\"file\">\n\
<input type=\"submit\" value=\" Send \"></form>\n\
</body></html>";
Upload a file, please!<br>\n\
<form action=\"/filepost\" method=\"post\" enctype=\"multipart/form-data\">\n\
<input name=\"file\" type=\"file\">\n\
<input type=\"submit\" value=\" Send \"></form>\n\
</body></html>";
#define BUSYPAGE \
"<html><head><title>Webserver busy</title></head><body>We are too busy to process POSTs right now.</body></html>"
"<html><head><title>Webserver busy</title></head>" \
"<body>We are too busy to process POSTs right now.</body></html>"
static enum MHD_Result
ahc_echo (void *cls,
@@ -96,18 +97,25 @@ int
main (int argc, char *const *argv)
{
struct MHD_Daemon *d;
struct handler_param data_for_handler;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
data_for_handler.response_page = askpage;
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, &data_for_handler,
MHD_OPTION_END);
if (d == NULL)
+9 -1
View File
@@ -145,14 +145,22 @@ main (int argc,
struct epoll_event events_list[1];
struct Request *req;
uint64_t timer_expirations;
int port;
if (argc != 2)
{
printf ("%s PORT\n", argv[0]);
return 1;
}
port = atoi (argv[1]);
if ( (1 > port) || (port > 65535) )
{
fprintf (stderr,
"Port must be a number between 1 and 65535.\n");
return 1;
}
d = MHD_start_daemon (MHD_USE_EPOLL | MHD_ALLOW_SUSPEND_RESUME,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_NOTIFY_COMPLETED, &connection_done, NULL,
MHD_OPTION_END);
+13 -4
View File
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2016 Christian Grothoff (and other contributing authors)
Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
* @file upgrade_example.c
* @brief example for how to use libmicrohttpd upgrade
* @author Christian Grothoff
* @author Karlson2k (Evgeny Grin)
*
* Telnet to the HTTP server, use this in the request:
* GET / http/1.1
@@ -71,11 +73,15 @@ send_all (MHD_socket sock,
size_t off;
make_blocking (sock);
for (off = 0; off < len; off += ret)
for (off = 0; off < len; off += (size_t) ret)
{
ret = send (sock,
&buf[off],
#if ! defined(_WIN32) || defined(__CYGWIN__)
len - off,
#else /* Native W32 */
(int) (len - off),
#endif /* Native W32 */
0);
if (0 > ret)
{
@@ -135,7 +141,7 @@ run_usock (void *cls)
break;
send_all (md->sock,
buf,
got);
(size_t) got);
}
free (md);
MHD_upgrade_action (urh,
@@ -286,15 +292,18 @@ main (int argc,
char *const *argv)
{
struct MHD_Daemon *d;
unsigned int port;
if (argc != 2)
if ( (argc != 2) ||
(1 != sscanf (argv[1], "%u", &port)) ||
(65535 < port) )
{
printf ("%s PORT\n", argv[0]);
return 1;
}
d = MHD_start_daemon (MHD_ALLOW_UPGRADE | MHD_USE_AUTO
| MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
atoi (argv[1]),
(uint16_t) port,
NULL, NULL,
&ahc_echo, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,