libmicrohttpd

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

test_get_sendfile.c (18572B)


      1 /*
      2      This file is part of libmicrohttpd
      3      Copyright (C) 2007, 2009 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  * @file test_get_sendfile.c
     23  * @brief  Testcase for libmicrohttpd response from FD
     24  * @author Christian Grothoff
     25  * @author Karlson2k (Evgeny Grin)
     26  */
     27 
     28 #include "MHD_config.h"
     29 #include "platform.h"
     30 #include <curl/curl.h>
     31 #include <microhttpd.h>
     32 #include <stdlib.h>
     33 #include <string.h>
     34 #include <time.h>
     35 #include <sys/types.h>
     36 #include <fcntl.h>
     37 #include <errno.h>
     38 #include "mhd_sockets.h"
     39 #include "mhd_has_in_name.h"
     40 
     41 /* Turn any MHD_PANIC() or failing mhd_assert() reached from this
     42    test into a marked, classifiable test error (TESTING.md, P5). */
     43 #include "mhd_panic_tripwire.h"
     44 
     45 #ifndef WINDOWS
     46 #include <sys/socket.h>
     47 #include <unistd.h>
     48 #endif
     49 
     50 #if defined(MHD_CPU_COUNT) && (MHD_CPU_COUNT + 0) < 2
     51 #undef MHD_CPU_COUNT
     52 #endif
     53 #if ! defined(MHD_CPU_COUNT)
     54 #define MHD_CPU_COUNT 2
     55 #endif
     56 
     57 #define TESTSTR \
     58   "This is the content of the test file we are sending using sendfile (if available)"
     59 
     60 static char *sourcefile;
     61 
     62 static int oneone;
     63 
     64 struct CBC
     65 {
     66   char *buf;
     67   size_t pos;
     68   size_t size;
     69 };
     70 
     71 
     72 static size_t
     73 copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
     74 {
     75   struct CBC *cbc = ctx;
     76 
     77   if (cbc->pos + size * nmemb > cbc->size)
     78     return 0;                   /* overflow */
     79   memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
     80   cbc->pos += size * nmemb;
     81   return size * nmemb;
     82 }
     83 
     84 
     85 static enum MHD_Result
     86 ahc_echo (void *cls,
     87           struct MHD_Connection *connection,
     88           const char *url,
     89           const char *method,
     90           const char *version,
     91           const char *upload_data, size_t *upload_data_size,
     92           void **req_cls)
     93 {
     94   static int ptr;
     95   struct MHD_Response *response;
     96   enum MHD_Result ret;
     97   int fd;
     98   (void) cls;
     99   (void) url; (void) version;                      /* Unused. Silent compiler warning. */
    100   (void) upload_data; (void) upload_data_size;     /* Unused. Silent compiler warning. */
    101 
    102   if (0 != strcmp (MHD_HTTP_METHOD_GET, method))
    103     return MHD_NO;              /* unexpected method */
    104   if (&ptr != *req_cls)
    105   {
    106     *req_cls = &ptr;
    107     return MHD_YES;
    108   }
    109   *req_cls = NULL;
    110   fd = open (sourcefile, O_RDONLY);
    111   if (fd == -1)
    112   {
    113     fprintf (stderr, "Failed to open `%s': %s\n",
    114              sourcefile,
    115              strerror (errno));
    116     exit (1);
    117   }
    118   response = MHD_create_response_from_fd (strlen (TESTSTR), fd);
    119   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
    120   MHD_destroy_response (response);
    121   if (ret == MHD_NO)
    122     abort ();
    123   return ret;
    124 }
    125 
    126 
    127 static unsigned int
    128 testInternalGet (void)
    129 {
    130   struct MHD_Daemon *d;
    131   CURL *c;
    132   char buf[2048];
    133   struct CBC cbc;
    134   CURLcode errornum;
    135   uint16_t port;
    136 
    137   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    138     port = 0;
    139   else
    140   {
    141     port = 1200;
    142     if (oneone)
    143       port += 10;
    144   }
    145 
    146   cbc.buf = buf;
    147   cbc.size = 2048;
    148   cbc.pos = 0;
    149   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
    150                         port, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
    151   if (d == NULL)
    152     return 1;
    153   if (0 == port)
    154   {
    155     const union MHD_DaemonInfo *dinfo;
    156     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    157     if ((NULL == dinfo) || (0 == dinfo->port) )
    158     {
    159       MHD_stop_daemon (d); return 32;
    160     }
    161     port = dinfo->port;
    162   }
    163   c = curl_easy_init ();
    164   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
    165   curl_easy_setopt (c, CURLOPT_PORT, (long) port);
    166   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    167   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    168   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    169   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    170   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    171   if (oneone)
    172     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    173   else
    174     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    175   /* NOTE: use of CONNECTTIMEOUT without also
    176      setting NOSIGNAL results in really weird
    177      crashes on my system!*/
    178   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    179   curl_easy_setopt (c, CURLOPT_PROXY, "");
    180   if (CURLE_OK != (errornum = curl_easy_perform (c)))
    181   {
    182     fprintf (stderr,
    183              "curl_easy_perform failed: `%s'\n",
    184              curl_easy_strerror (errornum));
    185     curl_easy_cleanup (c);
    186     MHD_stop_daemon (d);
    187     return 2;
    188   }
    189   curl_easy_cleanup (c);
    190   MHD_stop_daemon (d);
    191   if (cbc.pos != strlen (TESTSTR))
    192     return 4;
    193   if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
    194     return 8;
    195   return 0;
    196 }
    197 
    198 
    199 static unsigned int
    200 testMultithreadedGet (void)
    201 {
    202   struct MHD_Daemon *d;
    203   CURL *c;
    204   char buf[2048];
    205   struct CBC cbc;
    206   CURLcode errornum;
    207   uint16_t port;
    208 
    209   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    210     port = 0;
    211   else
    212   {
    213     port = 1201;
    214     if (oneone)
    215       port += 10;
    216   }
    217 
    218   cbc.buf = buf;
    219   cbc.size = 2048;
    220   cbc.pos = 0;
    221   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
    222                         | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
    223                         port, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
    224   if (d == NULL)
    225     return 16;
    226   if (0 == port)
    227   {
    228     const union MHD_DaemonInfo *dinfo;
    229     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    230     if ((NULL == dinfo) || (0 == dinfo->port) )
    231     {
    232       MHD_stop_daemon (d); return 32;
    233     }
    234     port = dinfo->port;
    235   }
    236   c = curl_easy_init ();
    237   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
    238   curl_easy_setopt (c, CURLOPT_PORT, (long) port);
    239   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    240   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    241   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    242   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    243   if (oneone)
    244     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    245   else
    246     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    247   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    248   /* NOTE: use of CONNECTTIMEOUT without also
    249      setting NOSIGNAL results in really weird
    250      crashes on my system! */
    251   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    252   curl_easy_setopt (c, CURLOPT_PROXY, "");
    253   if (CURLE_OK != (errornum = curl_easy_perform (c)))
    254   {
    255     fprintf (stderr,
    256              "curl_easy_perform failed: `%s'\n",
    257              curl_easy_strerror (errornum));
    258     curl_easy_cleanup (c);
    259     MHD_stop_daemon (d);
    260     return 32;
    261   }
    262   curl_easy_cleanup (c);
    263   MHD_stop_daemon (d);
    264   if (cbc.pos != strlen (TESTSTR))
    265     return 64;
    266   if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
    267     return 128;
    268   return 0;
    269 }
    270 
    271 
    272 static unsigned int
    273 testMultithreadedPoolGet (void)
    274 {
    275   struct MHD_Daemon *d;
    276   CURL *c;
    277   char buf[2048];
    278   struct CBC cbc;
    279   CURLcode errornum;
    280   uint16_t port;
    281 
    282   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    283     port = 0;
    284   else
    285   {
    286     port = 1202;
    287     if (oneone)
    288       port += 10;
    289   }
    290 
    291   cbc.buf = buf;
    292   cbc.size = 2048;
    293   cbc.pos = 0;
    294   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
    295                         port, NULL, NULL, &ahc_echo, NULL,
    296                         MHD_OPTION_THREAD_POOL_SIZE, MHD_CPU_COUNT,
    297                         MHD_OPTION_END);
    298   if (d == NULL)
    299     return 16;
    300   if (0 == port)
    301   {
    302     const union MHD_DaemonInfo *dinfo;
    303     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    304     if ((NULL == dinfo) || (0 == dinfo->port) )
    305     {
    306       MHD_stop_daemon (d); return 32;
    307     }
    308     port = dinfo->port;
    309   }
    310   c = curl_easy_init ();
    311   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
    312   curl_easy_setopt (c, CURLOPT_PORT, (long) port);
    313   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    314   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    315   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    316   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    317   if (oneone)
    318     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    319   else
    320     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    321   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    322   /* NOTE: use of CONNECTTIMEOUT without also
    323      setting NOSIGNAL results in really weird
    324      crashes on my system!*/
    325   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    326   curl_easy_setopt (c, CURLOPT_PROXY, "");
    327   if (CURLE_OK != (errornum = curl_easy_perform (c)))
    328   {
    329     fprintf (stderr,
    330              "curl_easy_perform failed: `%s'\n",
    331              curl_easy_strerror (errornum));
    332     curl_easy_cleanup (c);
    333     MHD_stop_daemon (d);
    334     return 32;
    335   }
    336   curl_easy_cleanup (c);
    337   MHD_stop_daemon (d);
    338   if (cbc.pos != strlen (TESTSTR))
    339     return 64;
    340   if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
    341     return 128;
    342   return 0;
    343 }
    344 
    345 
    346 static unsigned int
    347 testExternalGet (int thread_unsafe)
    348 {
    349   struct MHD_Daemon *d;
    350   CURL *c;
    351   char buf[2048];
    352   struct CBC cbc;
    353   CURLM *multi;
    354   CURLMcode mret;
    355   fd_set rs;
    356   fd_set ws;
    357   fd_set es;
    358   MHD_socket maxsock;
    359 #ifdef MHD_WINSOCK_SOCKETS
    360   int maxposixs; /* Max socket number unused on W32 */
    361 #else  /* MHD_POSIX_SOCKETS */
    362 #define maxposixs maxsock
    363 #endif /* MHD_POSIX_SOCKETS */
    364   int running;
    365   struct CURLMsg *msg;
    366   time_t start;
    367   struct timeval tv;
    368   uint16_t port;
    369 
    370   if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    371     port = 0;
    372   else
    373   {
    374     port = 1203;
    375     if (oneone)
    376       port += 10;
    377   }
    378 
    379   multi = NULL;
    380   cbc.buf = buf;
    381   cbc.size = 2048;
    382   cbc.pos = 0;
    383   d = MHD_start_daemon (MHD_USE_ERROR_LOG
    384                         | (thread_unsafe ? MHD_USE_NO_THREAD_SAFETY : 0),
    385                         port, NULL, NULL, &ahc_echo, NULL,
    386                         MHD_OPTION_APP_FD_SETSIZE, (int) FD_SETSIZE,
    387                         MHD_OPTION_END);
    388   if (d == NULL)
    389     return 256;
    390   if (0 == port)
    391   {
    392     const union MHD_DaemonInfo *dinfo;
    393     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    394     if ((NULL == dinfo) || (0 == dinfo->port) )
    395     {
    396       MHD_stop_daemon (d); return 32;
    397     }
    398     port = dinfo->port;
    399   }
    400   c = curl_easy_init ();
    401   curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/");
    402   curl_easy_setopt (c, CURLOPT_PORT, (long) port);
    403   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    404   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    405   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    406   if (oneone)
    407     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    408   else
    409     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    410   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    411   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    412   /* NOTE: use of CONNECTTIMEOUT without also
    413      setting NOSIGNAL results in really weird
    414      crashes on my system! */
    415   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    416   curl_easy_setopt (c, CURLOPT_PROXY, "");
    417 
    418 
    419   multi = curl_multi_init ();
    420   if (multi == NULL)
    421   {
    422     curl_easy_cleanup (c);
    423     MHD_stop_daemon (d);
    424     return 512;
    425   }
    426   mret = curl_multi_add_handle (multi, c);
    427   if (mret != CURLM_OK)
    428   {
    429     curl_multi_cleanup (multi);
    430     curl_easy_cleanup (c);
    431     MHD_stop_daemon (d);
    432     return 1024;
    433   }
    434   start = time (NULL);
    435   while ((time (NULL) - start < 5) && (multi != NULL))
    436   {
    437     maxsock = MHD_INVALID_SOCKET;
    438     maxposixs = -1;
    439     FD_ZERO (&rs);
    440     FD_ZERO (&ws);
    441     FD_ZERO (&es);
    442     curl_multi_perform (multi, &running);
    443     mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
    444     if (mret != CURLM_OK)
    445     {
    446       curl_multi_remove_handle (multi, c);
    447       curl_multi_cleanup (multi);
    448       curl_easy_cleanup (c);
    449       MHD_stop_daemon (d);
    450       return 2048;
    451     }
    452     if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
    453     {
    454       curl_multi_remove_handle (multi, c);
    455       curl_multi_cleanup (multi);
    456       curl_easy_cleanup (c);
    457       MHD_stop_daemon (d);
    458       return 4096;
    459     }
    460     tv.tv_sec = 0;
    461     tv.tv_usec = 1000;
    462     if (-1 == select (maxposixs + 1, &rs, &ws, &es, &tv))
    463     {
    464 #ifdef MHD_POSIX_SOCKETS
    465       if (EINTR != errno)
    466       {
    467         fprintf (stderr, "Unexpected select() error: %d. Line: %d\n",
    468                  (int) errno, __LINE__);
    469         fflush (stderr);
    470         exit (99);
    471       }
    472 #else
    473       if ((WSAEINVAL != WSAGetLastError ()) ||
    474           (0 != rs.fd_count) || (0 != ws.fd_count) || (0 != es.fd_count) )
    475       {
    476         fprintf (stderr, "Unexpected select() error: %d. Line: %d\n",
    477                  (int) WSAGetLastError (), __LINE__);
    478         fflush (stderr);
    479         exit (99);
    480       }
    481       Sleep (1);
    482 #endif
    483     }
    484     curl_multi_perform (multi, &running);
    485     if (0 == running)
    486     {
    487       int pending;
    488       int curl_fine = 0;
    489       while (NULL != (msg = curl_multi_info_read (multi, &pending)))
    490       {
    491         if (msg->msg == CURLMSG_DONE)
    492         {
    493           if (msg->data.result == CURLE_OK)
    494             curl_fine = 1;
    495           else
    496           {
    497             fprintf (stderr,
    498                      "%s failed at %s:%d: `%s'\n",
    499                      "curl_multi_perform",
    500                      __FILE__,
    501                      __LINE__, curl_easy_strerror (msg->data.result));
    502             abort ();
    503           }
    504         }
    505       }
    506       if (! curl_fine)
    507       {
    508         fprintf (stderr, "libcurl haven't returned OK code\n");
    509         abort ();
    510       }
    511       curl_multi_remove_handle (multi, c);
    512       curl_multi_cleanup (multi);
    513       curl_easy_cleanup (c);
    514       c = NULL;
    515       multi = NULL;
    516     }
    517     MHD_run (d);
    518   }
    519   if (multi != NULL)
    520   {
    521     curl_multi_remove_handle (multi, c);
    522     curl_easy_cleanup (c);
    523     curl_multi_cleanup (multi);
    524   }
    525   MHD_stop_daemon (d);
    526   if (cbc.pos != strlen (TESTSTR))
    527   {
    528     fprintf (stderr,
    529              "Got %.*s instead of %s!\n",
    530              (int) cbc.pos,
    531              cbc.buf,
    532              TESTSTR);
    533     return 8192;
    534   }
    535   if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
    536     return 16384;
    537   return 0;
    538 }
    539 
    540 
    541 static unsigned int
    542 testUnknownPortGet (void)
    543 {
    544   struct MHD_Daemon *d;
    545   const union MHD_DaemonInfo *di;
    546   CURL *c;
    547   char buf[2048];
    548   struct CBC cbc;
    549   CURLcode errornum;
    550   uint16_t port;
    551 
    552   struct sockaddr_in addr;
    553   socklen_t addr_len = sizeof(addr);
    554   memset (&addr, 0, sizeof(addr));
    555   addr.sin_family = AF_INET;
    556   addr.sin_port = 0;
    557   addr.sin_addr.s_addr = INADDR_ANY;
    558 
    559   cbc.buf = buf;
    560   cbc.size = 2048;
    561   cbc.pos = 0;
    562   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
    563                         0, NULL, NULL, &ahc_echo, NULL,
    564                         MHD_OPTION_SOCK_ADDR, &addr,
    565                         MHD_OPTION_END);
    566   if (d == NULL)
    567     return 32768;
    568 
    569   if (MHD_NO == MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
    570   {
    571     di = MHD_get_daemon_info (d, MHD_DAEMON_INFO_LISTEN_FD);
    572     if (di == NULL)
    573       return 65536;
    574 
    575     if (0 != getsockname (di->listen_fd, (struct sockaddr *) &addr, &addr_len))
    576       return 131072;
    577 
    578     if (addr.sin_family != AF_INET)
    579       return 26214;
    580     port = (uint16_t) ntohs (addr.sin_port);
    581   }
    582   else
    583   {
    584     const union MHD_DaemonInfo *dinfo;
    585     dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
    586     if ((NULL == dinfo) || (0 == dinfo->port) )
    587     {
    588       MHD_stop_daemon (d); return 32;
    589     }
    590     port = dinfo->port;
    591   }
    592 
    593   snprintf (buf, sizeof(buf), "http://127.0.0.1:%u/",
    594             (unsigned int) port);
    595 
    596   c = curl_easy_init ();
    597   curl_easy_setopt (c, CURLOPT_URL, buf);
    598   curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    599   curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    600   curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
    601   curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    602   curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
    603   if (oneone)
    604     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    605   else
    606     curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    607   /* NOTE: use of CONNECTTIMEOUT without also
    608      setting NOSIGNAL results in really weird
    609      crashes on my system! */
    610   curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
    611   curl_easy_setopt (c, CURLOPT_PROXY, "");
    612   if (CURLE_OK != (errornum = curl_easy_perform (c)))
    613   {
    614     fprintf (stderr,
    615              "curl_easy_perform failed: `%s'\n",
    616              curl_easy_strerror (errornum));
    617     curl_easy_cleanup (c);
    618     MHD_stop_daemon (d);
    619     return 524288;
    620   }
    621   curl_easy_cleanup (c);
    622   MHD_stop_daemon (d);
    623   if (cbc.pos != strlen (TESTSTR))
    624     return 1048576;
    625   if (0 != strncmp (TESTSTR, cbc.buf, strlen (TESTSTR)))
    626     return 2097152;
    627   return 0;
    628 }
    629 
    630 
    631 int
    632 main (int argc, char *const *argv)
    633 {
    634   unsigned int errorCount = 0;
    635   const char *tmp;
    636   FILE *f;
    637   (void) argc;   /* Unused. Silent compiler warning. */
    638 
    639   if ((NULL == argv) || (0 == argv[0]))
    640     return 99;
    641   oneone = has_in_name (argv[0], "11");
    642 
    643   if ( (NULL == (tmp = getenv ("TMPDIR"))) &&
    644        (NULL == (tmp = getenv ("TMP"))) &&
    645        (NULL == (tmp = getenv ("TEMP"))) )
    646     tmp = "/tmp";
    647   sourcefile = malloc (strlen (tmp) + 32);
    648   snprintf (sourcefile,
    649             strlen (tmp) + 32,
    650             "%s/%s%s",
    651             tmp,
    652             "test-mhd-sendfile",
    653             oneone ? "11" : "");
    654   f = fopen (sourcefile, "w");
    655   if (NULL == f)
    656   {
    657     fprintf (stderr, "failed to write test file\n");
    658     free (sourcefile);
    659     return 1;
    660   }
    661   if (1 !=
    662       fwrite (TESTSTR, strlen (TESTSTR), 1, f))
    663     abort ();
    664   fclose (f);
    665   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    666     return 2;
    667   if (MHD_YES == MHD_is_feature_supported (MHD_FEATURE_THREADS))
    668   {
    669     errorCount += testInternalGet ();
    670     errorCount += testMultithreadedGet ();
    671     errorCount += testMultithreadedPoolGet ();
    672     errorCount += testUnknownPortGet ();
    673     errorCount += testExternalGet (0);
    674   }
    675   errorCount += testExternalGet (! 0);
    676   if (errorCount != 0)
    677     fprintf (stderr, "Error (code: %u)\n", errorCount);
    678   curl_global_cleanup ();
    679   unlink (sourcefile);
    680   free (sourcefile);
    681   return (0 == errorCount) ? 0 : 1;       /* 0 == pass */
    682 }