libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

perf_get.c (19676B)


      1 /*
      2      This file is part of libmicrohttpd
      3      Copyright (C) 2007, 2009, 2011 Christian Grothoff
      4      Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
      5 
      6      libmicrohttpd is free software; you can redistribute it and/or modify
      7      it under the terms of the GNU General Public License as published
      8      by the Free Software Foundation; either version 2, or (at your
      9      option) any later version.
     10 
     11      libmicrohttpd is distributed in the hope that it will be useful, but
     12      WITHOUT ANY WARRANTY; without even the implied warranty of
     13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14      General Public License for more details.
     15 
     16      You should have received a copy of the GNU General Public License
     17      along with libmicrohttpd; see the file COPYING.  If not, write to the
     18      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19      Boston, MA 02110-1301, USA.
     20 */
     21 
     22 /**
     23  * @file perf_get.c
     24  * @brief benchmark simple GET operations (sequential access).
     25  *        Note that we run libcurl in the same process at the
     26  *        same time, so the execution time given is the combined
     27  *        time for both MHD and libcurl; it is quite possible
     28  *        that more time is spend with libcurl than with MHD,
     29  *        so the performance scores calculated with this code
     30  *        should NOT be used to compare with other HTTP servers
     31  *        (since MHD is actually better); only the relative
     32  *        scores between MHD versions are meaningful.
     33  *        Furthermore, this code ONLY tests MHD processing
     34  *        a single request at a time.  This is again
     35  *        not universally meaningful (i.e. when comparing
     36  *        multithreaded vs. single-threaded or select/poll).
     37  * @author Christian Grothoff
     38  * @author Karlson2k (Evgeny Grin)
     39  */
     40 
     41 #include "MHD_config.h"
     42 #include "platform.h"
     43 #include <curl/curl.h>
     44 #include <microhttpd.h>
     45 #include <stdlib.h>
     46 #include <string.h>
     47 #include <time.h>
     48 #include <errno.h>
     49 #include "mhd_has_in_name.h"
     50 
     51 /* Turn any MHD_PANIC() or failing mhd_assert() reached from this
     52    test into a marked, classifiable test error (TESTING.md, P5). */
     53 #include "mhd_panic_tripwire.h"
     54 
     55 #ifndef WINDOWS
     56 #include <unistd.h>
     57 #include <sys/socket.h>
     58 #endif
     59 
     60 #if defined(MHD_CPU_COUNT) && (MHD_CPU_COUNT + 0) < 2
     61 #undef MHD_CPU_COUNT
     62 #endif
     63 #if ! defined(MHD_CPU_COUNT)
     64 #define MHD_CPU_COUNT 2
     65 #endif
     66 
     67 /**
     68  * How many rounds of operations do we do for each
     69  * test?
     70  */
     71 #if MHD_CPU_COUNT > 8
     72 #ifndef _WIN32
     73 #define ROUNDS (1 + (30000 / 12) / MHD_CPU_COUNT)
     74 #else /* _WIN32 */
     75 #define ROUNDS (1 + (3000 / 12) / MHD_CPU_COUNT)
     76 #endif /* _WIN32 */
     77 #else
     78 #define ROUNDS 500
     79 #endif
     80 
     81 /**
     82  * Do we use HTTP 1.1?
     83  */
     84 static int oneone;
     85 
     86 /**
     87  * Response to return (re-used).
     88  */
     89 static struct MHD_Response *response;
     90 
     91 /**
     92  * Time this round was started.
     93  */
     94 static unsigned long long start_time;
     95 
     96 
     97 /**
     98  * Get the current timestamp
     99  *
    100  * @return current time in ms
    101  */
    102 static unsigned long long
    103 now (void)
    104 {
    105   struct timeval tv;
    106 
    107   gettimeofday (&tv, NULL);
    108   return (((unsigned long long) tv.tv_sec * 1000LL)
    109           + ((unsigned long long) tv.tv_usec / 1000LL));
    110 }
    111 
    112 
    113 /**
    114  * Start the timer.
    115  */
    116 static void
    117 start_timer (void)
    118 {
    119   start_time = now ();
    120 }
    121 
    122 
    123 /**
    124  * Stop the timer and report performance
    125  *
    126  * @param desc description of the threading mode we used
    127  */
    128 static void
    129 stop (const char *desc)
    130 {
    131   double rps = ((double) (ROUNDS * 1000)) / ((double) (now () - start_time));
    132 
    133   fprintf (stderr,
    134            "Sequential GETs using %s: %f %s\n",
    135            desc,
    136            rps,
    137            "requests/s");
    138 }
    139 
    140 
    141 struct CBC
    142 {
    143   char *buf;
    144   size_t pos;
    145   size_t size;
    146 };
    147 
    148 
    149 static size_t
    150 copyBuffer (void *ptr,
    151             size_t size, size_t nmemb,
    152             void *ctx)
    153 {
    154   struct CBC *cbc = ctx;
    155 
    156   if (cbc->pos + size * nmemb > cbc->size)
    157     return 0;                   /* overflow */
    158   memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
    159   cbc->pos += size * nmemb;
    160   return size * nmemb;
    161 }
    162 
    163 
    164 static enum MHD_Result
    165 ahc_echo (void *cls,
    166           struct MHD_Connection *connection,
    167           const char *url,
    168           const char *method,
    169           const char *version,
    170           const char *upload_data, size_t *upload_data_size,
    171           void **req_cls)
    172 {
    173   static int ptr;
    174   enum MHD_Result ret;
    175   (void) cls;
    176   (void) url; (void) version;                      /* Unused. Silent compiler warning. */
    177   (void) upload_data; (void) upload_data_size;     /* Unused. Silent compiler warning. */
    178 
    179   if (0 != strcmp (MHD_HTTP_METHOD_GET, method))
    180     return MHD_NO;              /* unexpected method */
    181   if (&ptr != *req_cls)
    182   {
    183     *req_cls = &ptr;
    184     return MHD_YES;
    185   }
    186   *req_cls = NULL;
    187   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
    188   if (ret == MHD_NO)
    189     abort ();
    190   return ret;
    191 }
    192 
    193 
    194 static unsigned int
    195 testInternalGet (uint16_t port, uint32_t poll_flag)
    196 {
    197   struct MHD_Daemon *d;
    198   CURL *c;
    199   char buf[2048];
    200   struct CBC cbc;
    201   CURLcode errornum;
    202   unsigned int i;
    203   char url[64];
    204 
    205   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    206     port = 0;
    207 
    208   cbc.buf = buf;
    209   cbc.size = 2048;
    210   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
    211                         | (enum MHD_FLAG) poll_flag,
    212                         port, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
    213   if (d == NULL)
    214     return 1;
    215   if (0 == port)
    216   {
    217     const union MHD_DaemonInfo *dinfo;
    218     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    219     if ((NULL == dinfo) || (0 == dinfo->port) )
    220     {
    221       MHD_stop_daemon (d); return 32;
    222     }
    223     port = dinfo->port;
    224   }
    225   snprintf (url,
    226             sizeof (url),
    227             "http://127.0.0.1:%u/hello_world",
    228             (unsigned int) port);
    229   start_timer ();
    230   for (i = 0; i < ROUNDS; i++)
    231   {
    232     cbc.pos = 0;
    233     c = curl_easy_init ();
    234     curl_easy_setopt (c, CURLOPT_URL, url);
    235     curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    236     curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    237     curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    238     curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    239     curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    240     if (oneone)
    241       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    242     else
    243       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    244     /* NOTE: use of CONNECTTIMEOUT without also
    245  setting NOSIGNAL results in really weird
    246  crashes on my system!*/
    247     curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    248     curl_easy_setopt (c, CURLOPT_PROXY, "");
    249     if (CURLE_OK != (errornum = curl_easy_perform (c)))
    250     {
    251       fprintf (stderr,
    252                "curl_easy_perform failed: `%s'\n",
    253                curl_easy_strerror (errornum));
    254       curl_easy_cleanup (c);
    255       MHD_stop_daemon (d);
    256       return 2;
    257     }
    258     curl_easy_cleanup (c);
    259   }
    260   stop (poll_flag == MHD_USE_AUTO ? "internal thread with 'auto'" :
    261         poll_flag == MHD_USE_POLL ? "internal thread with poll()" :
    262         poll_flag == MHD_USE_EPOLL ? "internal thread with epoll" :
    263         "internal thread with select()");
    264   MHD_stop_daemon (d);
    265   if (cbc.pos != strlen ("/hello_world"))
    266     return 4;
    267   if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
    268     return 8;
    269   return 0;
    270 }
    271 
    272 
    273 static unsigned int
    274 testMultithreadedGet (uint16_t port, uint32_t poll_flag)
    275 {
    276   struct MHD_Daemon *d;
    277   CURL *c;
    278   char buf[2048];
    279   struct CBC cbc;
    280   CURLcode errornum;
    281   unsigned int i;
    282   char url[64];
    283 
    284   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    285     port = 0;
    286 
    287   cbc.buf = buf;
    288   cbc.size = 2048;
    289   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
    290                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
    291                         | (enum MHD_FLAG) poll_flag,
    292                         port, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
    293   if (d == NULL)
    294     return 16;
    295   if (0 == port)
    296   {
    297     const union MHD_DaemonInfo *dinfo;
    298     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    299     if ((NULL == dinfo) || (0 == dinfo->port) )
    300     {
    301       MHD_stop_daemon (d); return 32;
    302     }
    303     port = dinfo->port;
    304   }
    305   snprintf (url,
    306             sizeof (url),
    307             "http://127.0.0.1:%u/hello_world",
    308             (unsigned int) port);
    309   start_timer ();
    310   for (i = 0; i < ROUNDS; i++)
    311   {
    312     cbc.pos = 0;
    313     c = curl_easy_init ();
    314     curl_easy_setopt (c, CURLOPT_URL, url);
    315     curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    316     curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    317     curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    318     curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    319     if (oneone)
    320       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    321     else
    322       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    323     curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    324     /* NOTE: use of CONNECTTIMEOUT without also
    325  setting NOSIGNAL results in really weird
    326  crashes on my system! */
    327     curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    328     curl_easy_setopt (c, CURLOPT_PROXY, "");
    329     if (CURLE_OK != (errornum = curl_easy_perform (c)))
    330     {
    331       fprintf (stderr,
    332                "curl_easy_perform failed: `%s'\n",
    333                curl_easy_strerror (errornum));
    334       curl_easy_cleanup (c);
    335       MHD_stop_daemon (d);
    336       return 32;
    337     }
    338     curl_easy_cleanup (c);
    339   }
    340   stop ((poll_flag & MHD_USE_AUTO) ?
    341         "internal thread with 'auto' and thread per connection" :
    342         (poll_flag & MHD_USE_POLL) ?
    343         "internal thread with poll() and thread per connection" :
    344         (poll_flag & MHD_USE_EPOLL) ?
    345         "internal thread with epoll and thread per connection" :
    346         "internal thread with select() and thread per connection");
    347   MHD_stop_daemon (d);
    348   if (cbc.pos != strlen ("/hello_world"))
    349     return 64;
    350   if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
    351     return 128;
    352   return 0;
    353 }
    354 
    355 
    356 static unsigned int
    357 testMultithreadedPoolGet (uint16_t port, uint32_t poll_flag)
    358 {
    359   struct MHD_Daemon *d;
    360   CURL *c;
    361   char buf[2048];
    362   struct CBC cbc;
    363   CURLcode errornum;
    364   unsigned int i;
    365   char url[64];
    366 
    367   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    368     port = 0;
    369 
    370   cbc.buf = buf;
    371   cbc.size = 2048;
    372   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
    373                         | (enum MHD_FLAG) poll_flag,
    374                         port, NULL, NULL, &ahc_echo, NULL,
    375                         MHD_OPTION_THREAD_POOL_SIZE, MHD_CPU_COUNT,
    376                         MHD_OPTION_END);
    377   if (d == NULL)
    378     return 16;
    379   if (0 == port)
    380   {
    381     const union MHD_DaemonInfo *dinfo;
    382     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    383     if ((NULL == dinfo) || (0 == dinfo->port) )
    384     {
    385       MHD_stop_daemon (d); return 32;
    386     }
    387     port = dinfo->port;
    388   }
    389   snprintf (url,
    390             sizeof (url),
    391             "http://127.0.0.1:%u/hello_world",
    392             (unsigned int) port);
    393   start_timer ();
    394   for (i = 0; i < ROUNDS; i++)
    395   {
    396     cbc.pos = 0;
    397     c = curl_easy_init ();
    398     curl_easy_setopt (c, CURLOPT_URL, url);
    399     curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    400     curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    401     curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    402     curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    403     if (oneone)
    404       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    405     else
    406       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    407     curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    408     /* NOTE: use of CONNECTTIMEOUT without also
    409  setting NOSIGNAL results in really weird
    410  crashes on my system!*/
    411     curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    412     curl_easy_setopt (c, CURLOPT_PROXY, "");
    413     if (CURLE_OK != (errornum = curl_easy_perform (c)))
    414     {
    415       fprintf (stderr,
    416                "curl_easy_perform failed: `%s'\n",
    417                curl_easy_strerror (errornum));
    418       curl_easy_cleanup (c);
    419       MHD_stop_daemon (d);
    420       return 32;
    421     }
    422     curl_easy_cleanup (c);
    423   }
    424   stop (0 != (poll_flag & MHD_USE_AUTO) ? "internal thread pool with 'auto'" :
    425         0 != (poll_flag & MHD_USE_POLL) ? "internal thread pool with poll()" :
    426         0 != (poll_flag & MHD_USE_EPOLL) ? "internal thread pool with epoll" :
    427         "internal thread pool with select()");
    428   MHD_stop_daemon (d);
    429   if (cbc.pos != strlen ("/hello_world"))
    430     return 64;
    431   if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
    432     return 128;
    433   return 0;
    434 }
    435 
    436 
    437 static unsigned int
    438 testExternalGet (uint16_t port)
    439 {
    440   struct MHD_Daemon *d;
    441   CURL *c;
    442   char buf[2048];
    443   struct CBC cbc;
    444   CURLM *multi;
    445   CURLMcode mret;
    446   fd_set rs;
    447   fd_set ws;
    448   fd_set es;
    449   MHD_socket maxsock;
    450 #ifdef MHD_WINSOCK_SOCKETS
    451   int maxposixs; /* Max socket number unused on W32 */
    452 #else  /* MHD_POSIX_SOCKETS */
    453 #define maxposixs maxsock
    454 #endif /* MHD_POSIX_SOCKETS */
    455   int running;
    456   struct CURLMsg *msg;
    457   time_t start;
    458   struct timeval tv;
    459   unsigned int i;
    460   char url[64];
    461 
    462   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    463     port = 0;
    464 
    465   multi = NULL;
    466   cbc.buf = buf;
    467   cbc.size = 2048;
    468   d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_NO_THREAD_SAFETY,
    469                         port, NULL, NULL,
    470                         &ahc_echo, NULL,
    471                         MHD_OPTION_APP_FD_SETSIZE, (int) FD_SETSIZE,
    472                         MHD_OPTION_END);
    473   if (NULL == d)
    474     return 256;
    475   if (0 == port)
    476   {
    477     const union MHD_DaemonInfo *dinfo;
    478     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    479     if ((NULL == dinfo) || (0 == dinfo->port) )
    480     {
    481       MHD_stop_daemon (d); return 32;
    482     }
    483     port = dinfo->port;
    484   }
    485   snprintf (url,
    486             sizeof (url),
    487             "http://127.0.0.1:%u/hello_world",
    488             (unsigned int) port);
    489   start_timer ();
    490   multi = curl_multi_init ();
    491   if (multi == NULL)
    492   {
    493     MHD_stop_daemon (d);
    494     return 512;
    495   }
    496   for (i = 0; i < ROUNDS; i++)
    497   {
    498     cbc.pos = 0;
    499     c = curl_easy_init ();
    500     curl_easy_setopt (c, CURLOPT_URL, url);
    501     curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    502     curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    503     curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    504     if (oneone)
    505       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    506     else
    507       curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    508     curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    509     curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    510     /* NOTE: use of CONNECTTIMEOUT without also
    511  setting NOSIGNAL results in really weird
    512  crashes on my system! */
    513     curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    514     curl_easy_setopt (c, CURLOPT_PROXY, "");
    515     mret = curl_multi_add_handle (multi, c);
    516     if (mret != CURLM_OK)
    517     {
    518       curl_multi_cleanup (multi);
    519       curl_easy_cleanup (c);
    520       MHD_stop_daemon (d);
    521       return 1024;
    522     }
    523     start = time (NULL);
    524     while ((time (NULL) - start < 5) && (c != NULL))
    525     {
    526       maxsock = MHD_INVALID_SOCKET;
    527       maxposixs = -1;
    528       FD_ZERO (&rs);
    529       FD_ZERO (&ws);
    530       FD_ZERO (&es);
    531       curl_multi_perform (multi, &running);
    532       mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
    533       if (mret != CURLM_OK)
    534       {
    535         curl_multi_remove_handle (multi, c);
    536         curl_multi_cleanup (multi);
    537         curl_easy_cleanup (c);
    538         MHD_stop_daemon (d);
    539         return 2048;
    540       }
    541       if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
    542       {
    543         curl_multi_remove_handle (multi, c);
    544         curl_multi_cleanup (multi);
    545         curl_easy_cleanup (c);
    546         MHD_stop_daemon (d);
    547         return 4096;
    548       }
    549       tv.tv_sec = 0;
    550       tv.tv_usec = 1000;
    551       if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
    552       {
    553   #ifdef MHD_POSIX_SOCKETS
    554         if (EINTR != errno)
    555         {
    556           fprintf (stderr, "Unexpected select() error: %d. Line: %d\n",
    557                    (int) errno, __LINE__);
    558           fflush (stderr);
    559           exit (99);
    560         }
    561   #else
    562         if ((WSAEINVAL != WSAGetLastError ()) ||
    563             (0 != rs.fd_count) || (0 != ws.fd_count) || (0 != es.fd_count) )
    564         {
    565           fprintf (stderr, "Unexpected select() error: %d. Line: %d\n",
    566                    (int) WSAGetLastError (), __LINE__);
    567           fflush (stderr);
    568           exit (99);
    569         }
    570         Sleep (1);
    571   #endif
    572       }
    573       curl_multi_perform (multi, &running);
    574       if (0 == running)
    575       {
    576         int pending;
    577         int curl_fine = 0;
    578         while (NULL != (msg = curl_multi_info_read (multi, &pending)))
    579         {
    580           if (msg->msg == CURLMSG_DONE)
    581           {
    582             if (msg->data.result == CURLE_OK)
    583               curl_fine = 1;
    584             else
    585             {
    586               fprintf (stderr,
    587                        "%s failed at %s:%d: `%s'\n",
    588                        "curl_multi_perform",
    589                        __FILE__,
    590                        __LINE__, curl_easy_strerror (msg->data.result));
    591               abort ();
    592             }
    593           }
    594         }
    595         if (! curl_fine)
    596         {
    597           fprintf (stderr, "libcurl haven't returned OK code\n");
    598           abort ();
    599         }
    600         curl_multi_remove_handle (multi, c);
    601         curl_easy_cleanup (c);
    602         c = NULL;
    603         break;
    604       }
    605       /* two possibilities here; as select sets are
    606          tiny, this makes virtually no difference
    607          in actual runtime right now, even though the
    608          number of select calls is virtually cut in half
    609          (and 'select' is the most expensive of our system
    610          calls according to 'strace') */
    611       if (0)
    612         MHD_run (d);
    613       else
    614         MHD_run_from_select (d, &rs, &ws, &es);
    615     }
    616     if (NULL != c)
    617     {
    618       curl_multi_remove_handle (multi, c);
    619       curl_easy_cleanup (c);
    620       fprintf (stderr, "Timeout!?\n");
    621     }
    622   }
    623   stop ("external select");
    624   if (multi != NULL)
    625   {
    626     curl_multi_cleanup (multi);
    627   }
    628   MHD_stop_daemon (d);
    629   if (cbc.pos != strlen ("/hello_world"))
    630     return 8192;
    631   if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
    632     return 16384;
    633   return 0;
    634 }
    635 
    636 
    637 int
    638 main (int argc, char *const *argv)
    639 {
    640   unsigned int errorCount = 0;
    641   uint16_t port = 1130;
    642   (void) argc;   /* Unused. Silent compiler warning. */
    643 
    644   if ((NULL == argv) || (0 == argv[0]))
    645     return 99;
    646   oneone = has_in_name (argv[0], "11");
    647   if (oneone)
    648     port += 15;
    649   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    650     return 2;
    651   response = MHD_create_response_from_buffer_copy (strlen ("/hello_world"),
    652                                                    "/hello_world");
    653   errorCount += testExternalGet (port++);
    654   if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
    655   {
    656     errorCount += testInternalGet (port++, MHD_USE_AUTO);
    657     errorCount += testMultithreadedGet (port++, MHD_USE_AUTO);
    658     errorCount += testMultithreadedPoolGet (port++, MHD_USE_AUTO);
    659     errorCount += testInternalGet (port++, 0);
    660     errorCount += testMultithreadedGet (port++, 0);
    661     errorCount += testMultithreadedPoolGet (port++, 0);
    662     if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_POLL))
    663     {
    664       errorCount += testInternalGet (port++, MHD_USE_POLL);
    665       errorCount += testMultithreadedGet (port++, MHD_USE_POLL);
    666       errorCount += testMultithreadedPoolGet (port++, MHD_USE_POLL);
    667     }
    668     if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_EPOLL))
    669     {
    670       errorCount += testInternalGet (port++, MHD_USE_EPOLL);
    671       errorCount += testMultithreadedPoolGet (port++, MHD_USE_EPOLL);
    672     }
    673   }
    674   MHD_destroy_response (response);
    675   if (errorCount != 0)
    676     fprintf (stderr, "Error (code: %u)\n", errorCount);
    677   curl_global_cleanup ();
    678   return errorCount != 0;       /* 0 == pass */
    679 }