aboutsummaryrefslogtreecommitdiff
path: root/src/examples/benchmark_https.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/benchmark_https.c')
-rw-r--r--src/examples/benchmark_https.c168
1 files changed, 85 insertions, 83 deletions
diff --git a/src/examples/benchmark_https.c b/src/examples/benchmark_https.c
index 64eb11b7..9506e562 100644
--- a/src/examples/benchmark_https.c
+++ b/src/examples/benchmark_https.c
@@ -25,14 +25,15 @@
25#include "platform.h" 25#include "platform.h"
26#include <microhttpd.h> 26#include <microhttpd.h>
27 27
28#if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 28#if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2
29#undef CPU_COUNT 29#undef CPU_COUNT
30#endif 30#endif
31#if !defined(CPU_COUNT) 31#if ! defined(CPU_COUNT)
32#define CPU_COUNT 2 32#define CPU_COUNT 2
33#endif 33#endif
34 34
35#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 35#define PAGE \
36 "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>"
36 37
37 38
38#define SMALL (1024 * 128) 39#define SMALL (1024 * 128)
@@ -62,16 +63,16 @@ static struct MHD_Response *response;
62 */ 63 */
63static void 64static void
64completed_callback (void *cls, 65completed_callback (void *cls,
65 struct MHD_Connection *connection, 66 struct MHD_Connection *connection,
66 void **con_cls, 67 void **con_cls,
67 enum MHD_RequestTerminationCode toe) 68 enum MHD_RequestTerminationCode toe)
68{ 69{
69 struct timeval *tv = *con_cls; 70 struct timeval *tv = *con_cls;
70 struct timeval tve; 71 struct timeval tve;
71 uint64_t delta; 72 uint64_t delta;
72 (void)cls; /* Unused. Silent compiler warning. */ 73 (void) cls; /* Unused. Silent compiler warning. */
73 (void)connection; /* Unused. Silent compiler warning. */ 74 (void) connection; /* Unused. Silent compiler warning. */
74 (void)toe; /* Unused. Silent compiler warning. */ 75 (void) toe; /* Unused. Silent compiler warning. */
75 76
76 if (NULL == tv) 77 if (NULL == tv)
77 return; 78 return;
@@ -80,10 +81,10 @@ completed_callback (void *cls,
80 delta = 0; 81 delta = 0;
81 if (tve.tv_usec >= tv->tv_usec) 82 if (tve.tv_usec >= tv->tv_usec)
82 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL 83 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL
83 + (tve.tv_usec - tv->tv_usec); 84 + (tve.tv_usec - tv->tv_usec);
84 else 85 else
85 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL 86 delta += (tve.tv_sec - tv->tv_sec) * 1000000LL
86 - tv->tv_usec + tve.tv_usec; 87 - tv->tv_usec + tve.tv_usec;
87 if (delta < SMALL) 88 if (delta < SMALL)
88 small_deltas[delta]++; 89 small_deltas[delta]++;
89 else 90 else
@@ -94,11 +95,11 @@ completed_callback (void *cls,
94 95
95static void * 96static void *
96uri_logger_cb (void *cls, 97uri_logger_cb (void *cls,
97 const char *uri) 98 const char *uri)
98{ 99{
99 struct timeval *tv = malloc (sizeof (struct timeval)); 100 struct timeval *tv = malloc (sizeof (struct timeval));
100 (void)cls; /* Unused. Silent compiler warning. */ 101 (void) cls; /* Unused. Silent compiler warning. */
101 (void)uri; /* Unused. Silent compiler warning. */ 102 (void) uri; /* Unused. Silent compiler warning. */
102 103
103 if (NULL != tv) 104 if (NULL != tv)
104 gettimeofday (tv, NULL); 105 gettimeofday (tv, NULL);
@@ -114,12 +115,12 @@ ahc_echo (void *cls,
114 const char *version, 115 const char *version,
115 const char *upload_data, size_t *upload_data_size, void **ptr) 116 const char *upload_data, size_t *upload_data_size, void **ptr)
116{ 117{
117 (void)cls; /* Unused. Silent compiler warning. */ 118 (void) cls; /* Unused. Silent compiler warning. */
118 (void)url; /* Unused. Silent compiler warning. */ 119 (void) url; /* Unused. Silent compiler warning. */
119 (void)version; /* Unused. Silent compiler warning. */ 120 (void) version; /* Unused. Silent compiler warning. */
120 (void)upload_data; /* Unused. Silent compiler warning. */ 121 (void) upload_data; /* Unused. Silent compiler warning. */
121 (void)upload_data_size; /* Unused. Silent compiler warning. */ 122 (void) upload_data_size; /* Unused. Silent compiler warning. */
122 (void)ptr; /* Unused. Silent compiler warning. */ 123 (void) ptr; /* Unused. Silent compiler warning. */
123 124
124 if (0 != strcmp (method, "GET")) 125 if (0 != strcmp (method, "GET"))
125 return MHD_NO; /* unexpected method */ 126 return MHD_NO; /* unexpected method */
@@ -129,53 +130,53 @@ ahc_echo (void *cls,
129 130
130/* test server key */ 131/* test server key */
131const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n" 132const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
132 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n" 133 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n"
133 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n" 134 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n"
134 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n" 135 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n"
135 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n" 136 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n"
136 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n" 137 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n"
137 "yoOl204xuekZOaG9RUP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6DXYXfZV4SSG2vB7\n" 153 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n"
153 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n" 154 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n"
154 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n" 155 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n"
155 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n" 156 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n"
156 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n" 157 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n"
157 "-----END RSA PRIVATE KEY-----\n"; 158 "-----END RSA PRIVATE KEY-----\n";
158 159
159/* test server CA signed certificates */ 160/* test server CA signed certificates */
160const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n" 161const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
161 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n" 162 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
162 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXDTQ1MDMxMjAwMDcyNVowFzEVMBMG\n" 163 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwM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==\n"
178 "-----END CERTIFICATE-----\n"; 179 "-----END CERTIFICATE-----\n";
179 180
180 181
181int 182int
@@ -185,36 +186,37 @@ main (int argc, char *const *argv)
185 unsigned int i; 186 unsigned int i;
186 187
187 if (argc != 2) 188 if (argc != 2)
188 { 189 {
189 printf ("%s PORT\n", argv[0]); 190 printf ("%s PORT\n", argv[0]);
190 return 1; 191 return 1;
191 } 192 }
192 response = MHD_create_response_from_buffer (strlen (PAGE), 193 response = MHD_create_response_from_buffer (strlen (PAGE),
193 (void *) PAGE, 194 (void *) PAGE,
194 MHD_RESPMEM_PERSISTENT); 195 MHD_RESPMEM_PERSISTENT);
195 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS 196 d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS
196#ifdef EPOLL_SUPPORT 197#ifdef EPOLL_SUPPORT
197 | MHD_USE_EPOLL | MHD_USE_TURBO 198 | MHD_USE_EPOLL | MHD_USE_TURBO
198#endif 199#endif
199 , 200 ,
200 atoi (argv[1]), 201 atoi (argv[1]),
201 NULL, NULL, &ahc_echo, NULL, 202 NULL, NULL, &ahc_echo, NULL,
202 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 203 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
203 MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, 204 MHD_OPTION_THREAD_POOL_SIZE, (unsigned
204 MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL, 205 int) NUMBER_OF_THREADS,
205 MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL, 206 MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL,
206 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000, 207 MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL,
207 /* Optionally, the gnutls_load_file() can be used to 208 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000,
208 load the key and the certificate from file. */ 209 /* Optionally, the gnutls_load_file() can be used to
209 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, 210 load the key and the certificate from file. */
210 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, 211 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
211 MHD_OPTION_END); 212 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
213 MHD_OPTION_END);
212 if (d == NULL) 214 if (d == NULL)
213 return 1; 215 return 1;
214 (void) getc (stdin); 216 (void) getc (stdin);
215 MHD_stop_daemon (d); 217 MHD_stop_daemon (d);
216 MHD_destroy_response (response); 218 MHD_destroy_response (response);
217 for (i=0;i<SMALL;i++) 219 for (i = 0; i<SMALL; i++)
218 if (0 != small_deltas[i]) 220 if (0 != small_deltas[i])
219 fprintf (stdout, "D: %d %u\n", i, small_deltas[i]); 221 fprintf (stdout, "D: %d %u\n", i, small_deltas[i]);
220 return 0; 222 return 0;