diff --git a/CMakeLists.txt b/CMakeLists.txt index d1d8afa96f7ed338a7a7d339360eaafeb3e73e59..08bd6ff8995965f16d38aed99b5d11c91cab0f3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ cmake_minimum_required(VERSION 3.1) # XXX using 0.1.90 instead of 0.1.0-DEV -project(nghttp2 VERSION 0.1.90) +project(ngtcp2 VERSION 0.1.90) # See versioning rule: # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html @@ -86,6 +86,7 @@ set(HAVE_LIBEV ${LIBEV_FOUND}) # Checks for header files. include(CheckIncludeFile) check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) +check_include_file("netinet/in.h" HAVE_NETINET_IN_H) check_include_file("stddef.h" HAVE_STDDEF_H) check_include_file("stdint.h" HAVE_STDINT_H) check_include_file("stdlib.h" HAVE_STDLIB_H) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000000000000000000000000000000000..e7975bc2490e67ce1a8ef9779627f041cc7abeaa --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,53 @@ +# Notes: +# - Minimal appveyor.yml file is an empty file. All sections are optional. +# - Indent each level of configuration with 2 spaces. Do not use tabs! +# - All section names are case-sensitive. +# - Section names should be unique on each level. + +#---------------------------------# +# general configuration # +#---------------------------------# + +# version format +#version: 0.10.{build} + +# branches to build +branches: + # blacklist + except: + - gh-pages + +# Do not build on tags (GitHub only) +skip_tags: true + +#---------------------------------# +# environment configuration # +#---------------------------------# + +os: Windows Server 2012 + +# scripts that run after cloning repository +install: + # install Win-Flex-Bison + #- cmd: cinst winflexbison -y + +#---------------------------------# +# build configuration # +#---------------------------------# + +# scripts to run before build +before_build: + - cmd: cmake . + +# scripts to run *after* solution is built and *before* automatic packaging occurs (web apps, NuGet packages, Azure Cloud Services) +# before_package: + +# scripts to run after build +# after_build: + +# to run your custom scripts instead of automatic MSBuild +build_script: + - cmd: cmake --build . + +# to disable automatic builds +# build: off \ No newline at end of file diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 840a8243b48839e4524494fc3d81bdb6b3eabddd..4812069e63f31bebc068ecc6a1ea7560f40f1e4f 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -8,6 +8,9 @@ /* Define to 1 if you have the <arpa/inet.h> header file. */ #cmakedefine HAVE_ARPA_INET_H 1 +/* Define to 1 if you have the <netinet/in.h> header file. */ +#cmakedefine HAVE_NETINET_IN_H 1 + /* Define to 1 if you have the <stddef.h> header file. */ #cmakedefine HAVE_STDDEF_H 1 diff --git a/lib/ngtcp2_conv.c b/lib/ngtcp2_conv.c index 482304b01f9ae9836827a2a1e4d2c23ed5e9fec2..5c8fc84fdfcd30eea85a271d18db5a473733f104 100644 --- a/lib/ngtcp2_conv.c +++ b/lib/ngtcp2_conv.c @@ -28,6 +28,7 @@ #include <assert.h> #include "ngtcp2_str.h" +#include "ngtcp2_net.h" uint64_t ngtcp2_get_uint64(const uint8_t *p) { uint64_t n; diff --git a/lib/ngtcp2_crypto.c b/lib/ngtcp2_crypto.c index b2fd4e855c773e222789ab4a06b29ccf5b0b398d..01fa08da9d7ce442db3f7089ab2c05c7b59cb21c 100644 --- a/lib/ngtcp2_crypto.c +++ b/lib/ngtcp2_crypto.c @@ -29,6 +29,7 @@ #include "ngtcp2_str.h" #include "ngtcp2_conv.h" +#include "ngtcp2_net.h" int ngtcp2_crypto_km_new(ngtcp2_crypto_km **pckm, const uint8_t *key, size_t keylen, const uint8_t *iv, size_t ivlen, diff --git a/lib/ngtcp2_log.c b/lib/ngtcp2_log.c index 3553d27ab0b2cba37c31f5572f91d067d590d186..87c5033b7eab238de4d882e01e2bd7b88950d5e8 100644 --- a/lib/ngtcp2_log.c +++ b/lib/ngtcp2_log.c @@ -25,7 +25,9 @@ #include "ngtcp2_log.h" #include <stdio.h> -#include <unistd.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif #include <assert.h> #include <errno.h> diff --git a/lib/ngtcp2_map.c b/lib/ngtcp2_map.c index 82f4079f40934a34b1de141b55f3eefa827e9c27..e97348b782d9724aa4d3efe9ab18dcaccea9239f 100644 --- a/lib/ngtcp2_map.c +++ b/lib/ngtcp2_map.c @@ -28,6 +28,7 @@ #include <string.h> #include "ngtcp2_conv.h" +#include "ngtcp2_net.h" #define INITIAL_TABLE_LENGTH 256 diff --git a/lib/ngtcp2_net.h b/lib/ngtcp2_net.h new file mode 100644 index 0000000000000000000000000000000000000000..ff3cea9919223321d635ac41b2bc4bca771edcf6 --- /dev/null +++ b/lib/ngtcp2_net.h @@ -0,0 +1,91 @@ +/* + * ngtcp2 + * + * Copyright (c) 2019 ngtcp2 contributors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef NGTCP2_NET_H +#define NGTCP2_NET_H + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif /* HAVE_CONFIG_H */ + +#ifdef HAVE_ARPA_INET_H +# include <arpa/inet.h> +#endif /* HAVE_ARPA_INET_H */ + +#ifdef HAVE_NETINET_IN_H +# include <netinet/in.h> +#endif /* HAVE_NETINET_IN_H */ + +#include <ngtcp2/ngtcp2.h> + +#if defined(WIN32) +/* Windows requires ws2_32 library for ntonl family functions. We + define inline functions for those function so that we don't have + dependeny on that lib. */ + +# ifdef _MSC_VER +# define STIN static __inline +# else +# define STIN static inline +# endif + +STIN uint32_t htonl(uint32_t hostlong) { + uint32_t res; + unsigned char *p = (unsigned char *)&res; + *p++ = hostlong >> 24; + *p++ = (hostlong >> 16) & 0xffu; + *p++ = (hostlong >> 8) & 0xffu; + *p = hostlong & 0xffu; + return res; +} + +STIN uint16_t htons(uint16_t hostshort) { + uint16_t res; + unsigned char *p = (unsigned char *)&res; + *p++ = hostshort >> 8; + *p = hostshort & 0xffu; + return res; +} + +STIN uint32_t ntohl(uint32_t netlong) { + uint32_t res; + unsigned char *p = (unsigned char *)&netlong; + res = *p++ << 24; + res += *p++ << 16; + res += *p++ << 8; + res += *p; + return res; +} + +STIN uint16_t ntohs(uint16_t netshort) { + uint16_t res; + unsigned char *p = (unsigned char *)&netshort; + res = *p++ << 8; + res += *p; + return res; +} + +#endif /* WIN32 */ + +#endif /* NGTCP2_NET_H */ \ No newline at end of file diff --git a/lib/ngtcp2_ringbuf.c b/lib/ngtcp2_ringbuf.c index e669b24154c911f1dc39fdd936592e922cc0cda3..4761a217d9449907f73889b8d6880511fc1cc24b 100644 --- a/lib/ngtcp2_ringbuf.c +++ b/lib/ngtcp2_ringbuf.c @@ -25,12 +25,20 @@ #include "ngtcp2_ringbuf.h" #include <assert.h> +#ifdef WIN32 +# include <intrin.h> +#endif #include "ngtcp2_macro.h" +#include "ngtcp2_net.h" int ngtcp2_ringbuf_init(ngtcp2_ringbuf *rb, size_t nmemb, size_t size, ngtcp2_mem *mem) { +#ifdef WIN32 + assert(1 == __popcnt((unsigned int)nmemb)); +#else assert(1 == __builtin_popcount((unsigned int)nmemb)); +#endif rb->buf = ngtcp2_mem_malloc(mem, nmemb * size); if (rb->buf == NULL) {