<commit_before>/*
     This file is part of libmicrohttpd
     Copyright (C) 2016 <NAME>

     libmicrohttpd is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     libmicrohttpd is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with libmicrohttpd; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     Boston, MA 02110-1301, USA.
*/

/**
 * @file test_upgrade.c
 * @brief  Testcase for libmicrohttpd upgrading a connection
 * @author <NAME>
 */

#include "platform.h"
#include "microhttpd.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>

#ifndef WINDOWS
#include <unistd.h>
#endif

#include "mhd_sockets.h"
#ifdef HAVE_NETINET_IP_H
#include <netinet/ip.h>
#endif /* HAVE_NETINET_IP_H */
#include "test_upgrade_common.c"


/**
 * Test upgrading a connection.
 *
 * @param flags which event loop style should be tested
 * @param pool size of the thread pool, 0 to disable
 */
static int
test_upgrade (int flags,
              unsigned int pool)
{
  struct MHD_Daemon *d;
  MHD_socket sock;
  struct sockaddr_in sa;

  done = 0;
  if (0 == (flags & MHD_USE_THREAD_PER_CONNECTION))
    flags |= MHD_USE_SUSPEND_RESUME;
  d = MHD_start_daemon (flags | MHD_USE_DEBUG,
                        1080,
                        NULL, NULL,
                        &ahc_upgrade, NULL,
                        MHD_OPTION_THREAD_POOL_SIZE, pool,
                        MHD_OPTION_END);
  if (NULL == d)
    return 2;
  sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (MHD_INVALID_SOCKET == sock)
    abort ();
  sa.sin_family = AF_INET;
  sa.sin_port = htons (1080);
  sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  if (0 != connect (sock,
                    (struct sockaddr *) &sa,
                    sizeof (sa)))
    abort ();
  if (0 !- pthread_create (&pt_client,
                           NULL,
                           &run_usock_client,
                           &sock))<commit_msg>-typo<commit_after>/*
     This file is part of libmicrohttpd
     Copyright (C) 2016 <NAME>

     libmicrohttpd is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     libmicrohttpd is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with libmicrohttpd; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     Boston, MA 02110-1301, USA.
*/

/**
 * @file test_upgrade.c
 * @brief  Testcase for libmicrohttpd upgrading a connection
 * @author <NAME>
 */

#include "platform.h"
#include "microhttpd.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>

#ifndef WINDOWS
#include <unistd.h>
#endif

#include "mhd_sockets.h"
#ifdef HAVE_NETINET_IP_H
#include <netinet/ip.h>
#endif /* HAVE_NETINET_IP_H */
#include "test_upgrade_common.c"


/**
 * Test upgrading a connection.
 *
 * @param flags which event loop style should be tested
 * @param pool size of the thread pool, 0 to disable
 */
static int
test_upgrade (int flags,
              unsigned int pool)
{
  struct MHD_Daemon *d;
  MHD_socket sock;
  struct sockaddr_in sa;

  done = 0;
  if (0 == (flags & MHD_USE_THREAD_PER_CONNECTION))
    flags |= MHD_USE_SUSPEND_RESUME;
  d = MHD_start_daemon (flags | MHD_USE_DEBUG,
                        1080,
                        NULL, NULL,
                        &ahc_upgrade, NULL,
                        MHD_OPTION_THREAD_POOL_SIZE, pool,
                        MHD_OPTION_END);
  if (NULL == d)
    return 2;
  sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (MHD_INVALID_SOCKET == sock)
    abort ();
  sa.sin_family = AF_INET;
  sa.sin_port = htons (1080);
  sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  if (0 != connect (sock,
                    (struct sockaddr *) &sa,
                    sizeof (sa)))
    abort ();
  if (0 != pthread_create (&pt_client,
                           NULL,
                           &run_usock_client,
                           &sock))
{'fraction_non_alphanumeric': 0.08439425051334702, 'fraction_numerical': 0.012320328542094456, 'mean_word_length': 2.408677396780966, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '98469', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1492, 'n_words': 515}