-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C++ library libnghttp2_asio on top of libnghttp2
The libnghttp2_asio library is C++ library built on top of libnghttp2. Currently, it has server API and easily create HTTP/2 server using node.js like API calls. See the example server source code in examples/asio-sv.cc. The library depends on Boost::ASIO library.
- Loading branch information
1 parent
446f8f1
commit 5d0bf4c
Showing
20 changed files
with
3,032 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* nghttp2 - HTTP/2 C Library | ||
* | ||
* Copyright (c) 2014 Tatsuhiro Tsujikawa | ||
* | ||
* 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. | ||
*/ | ||
// We wrote this code based on the original code which has the | ||
// following license: | ||
// | ||
// main.cpp | ||
// ~~~~~~~~ | ||
// | ||
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
#include <nghttp2/asio_http2.h> | ||
|
||
using namespace nghttp2::asio_http2; | ||
using namespace nghttp2::asio_http2::server; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
try { | ||
// Check command line arguments. | ||
if (argc < 3) { | ||
std::cerr << "Usage: asio-sv <port> <threads> <private-key-file> " | ||
<< "<cert-file>\n"; | ||
return 1; | ||
} | ||
|
||
uint16_t port = std::stoi(argv[1]); | ||
std::size_t num_threads = std::stoi(argv[2]); | ||
|
||
http2 server; | ||
|
||
server.num_threads(num_threads); | ||
|
||
if(argc >= 5) { | ||
server.tls(argv[3], argv[4]); | ||
} | ||
|
||
server.listen | ||
("*", port, | ||
[](std::shared_ptr<request> req, std::shared_ptr<response> res) | ||
{ | ||
res->write_head(200, { header{ "foo", "bar" } }); | ||
res->end("hello, world"); | ||
}); | ||
} catch (std::exception& e) { | ||
std::cerr << "exception: " << e.what() << "\n"; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# =========================================================================== | ||
# http://www.gnu.org/software/autoconf-archive/ax_boost_asio.html | ||
# =========================================================================== | ||
# | ||
# SYNOPSIS | ||
# | ||
# AX_BOOST_ASIO | ||
# | ||
# DESCRIPTION | ||
# | ||
# Test for Asio library from the Boost C++ libraries. The macro requires a | ||
# preceding call to AX_BOOST_BASE. Further documentation is available at | ||
# <http://randspringer.de/boost/index.html>. | ||
# | ||
# This macro calls: | ||
# | ||
# AC_SUBST(BOOST_ASIO_LIB) | ||
# | ||
# And sets: | ||
# | ||
# HAVE_BOOST_ASIO | ||
# | ||
# LICENSE | ||
# | ||
# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de> | ||
# Copyright (c) 2008 Pete Greenwell <pete@mu.org> | ||
# | ||
# Copying and distribution of this file, with or without modification, are | ||
# permitted in any medium without royalty provided the copyright notice | ||
# and this notice are preserved. This file is offered as-is, without any | ||
# warranty. | ||
|
||
#serial 16 | ||
|
||
AC_DEFUN([AX_BOOST_ASIO], | ||
[ | ||
AC_ARG_WITH([boost-asio], | ||
AS_HELP_STRING([--with-boost-asio@<:@=special-lib@:>@], | ||
[use the ASIO library from boost - it is possible to specify a certain library for the linker | ||
e.g. --with-boost-asio=boost_system-gcc41-mt-1_34 ]), | ||
[ | ||
if test "$withval" = "no"; then | ||
want_boost="no" | ||
elif test "$withval" = "yes"; then | ||
want_boost="yes" | ||
ax_boost_user_asio_lib="" | ||
else | ||
want_boost="yes" | ||
ax_boost_user_asio_lib="$withval" | ||
fi | ||
], | ||
[want_boost="yes"] | ||
) | ||
if test "x$want_boost" = "xyes"; then | ||
AC_REQUIRE([AC_PROG_CC]) | ||
CPPFLAGS_SAVED="$CPPFLAGS" | ||
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" | ||
export CPPFLAGS | ||
LDFLAGS_SAVED="$LDFLAGS" | ||
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" | ||
export LDFLAGS | ||
AC_CACHE_CHECK(whether the Boost::ASIO library is available, | ||
ax_cv_boost_asio, | ||
[AC_LANG_PUSH([C++]) | ||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ @%:@include <boost/asio.hpp> | ||
]], | ||
[[ | ||
boost::asio::io_service io; | ||
boost::system::error_code timer_result; | ||
boost::asio::deadline_timer t(io); | ||
t.cancel(); | ||
io.run_one(); | ||
return 0; | ||
]])], | ||
ax_cv_boost_asio=yes, ax_cv_boost_asio=no) | ||
AC_LANG_POP([C++]) | ||
]) | ||
if test "x$ax_cv_boost_asio" = "xyes"; then | ||
AC_DEFINE(HAVE_BOOST_ASIO,,[define if the Boost::ASIO library is available]) | ||
BN=boost_system | ||
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` | ||
if test "x$ax_boost_user_asio_lib" = "x"; then | ||
for ax_lib in `ls $BOOSTLIBDIR/libboost_system*.so* $BOOSTLIBDIR/libboost_system*.dylib* $BOOSTLIBDIR/libboost_system*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_system.*\)\.so.*$;\1;' -e 's;^lib\(boost_system.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_system.*\)\.a.*$;\1;' ` ; do | ||
AC_CHECK_LIB($ax_lib, main, [BOOST_ASIO_LIB="-l$ax_lib" AC_SUBST(BOOST_ASIO_LIB) link_thread="yes" break], | ||
[link_thread="no"]) | ||
done | ||
else | ||
for ax_lib in $ax_boost_user_asio_lib $BN-$ax_boost_user_asio_lib; do | ||
AC_CHECK_LIB($ax_lib, main, | ||
[BOOST_ASIO_LIB="-l$ax_lib" AC_SUBST(BOOST_ASIO_LIB) link_asio="yes" break], | ||
[link_asio="no"]) | ||
done | ||
fi | ||
if test "x$ax_lib" = "x"; then | ||
AC_MSG_ERROR(Could not find a version of the library!) | ||
fi | ||
if test "x$link_asio" = "xno"; then | ||
AC_MSG_ERROR(Could not link against $ax_lib !) | ||
fi | ||
fi | ||
CPPFLAGS="$CPPFLAGS_SAVED" | ||
LDFLAGS="$LDFLAGS_SAVED" | ||
fi | ||
]) |
Oops, something went wrong.