[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
#
# Copyright (c) 2003-2017 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)
#
import os ;
if [ os.name ] = SOLARIS
{
lib socket ;
lib nsl ;
}
else if [ os.name ] = NT
{
lib ws2_32 ;
lib mswsock ;
}
else if [ os.name ] = HPUX
{
lib ipv6 ;
}
else if [ os.name ] = HAIKU
{
lib network ;
}
exe server
: echo_server.cpp
/boost/context//boost_context
/boost/coroutine//boost_coroutine
/boost/system//boost_system
: <define>BOOST_ALL_NO_LIB=1
<threading>multi
<os>SOLARIS:<library>socket
<os>SOLARIS:<library>nsl
<os>NT:<define>_WIN32_WINNT=0x0501
<os>NT,<toolset>gcc:<library>ws2_32
<os>NT,<toolset>gcc:<library>mswsock
<os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
<os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
<os>HPUX:<library>ipv6
<os>HAIKU:<library>network
;
exe parallel_grep
: parallel_grep.cpp
/boost/context//boost_context
/boost/coroutine//boost_coroutine
/boost/system//boost_system
: <define>BOOST_ALL_NO_LIB=1
<threading>multi
<os>SOLARIS:<library>socket
<os>SOLARIS:<library>nsl
<os>NT:<define>_WIN32_WINNT=0x0501
<os>NT,<toolset>gcc:<library>ws2_32
<os>NT,<toolset>gcc:<library>mswsock
<os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
<os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
<os>HPUX:<library>ipv6
<os>HAIKU:<library>network
;

View File

@@ -0,0 +1,122 @@
//
// echo_server.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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 <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/write.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <iostream>
using boost::asio::ip::tcp;
class session : public boost::enable_shared_from_this<session>
{
public:
explicit session(boost::asio::io_context& io_context)
: strand_(io_context),
socket_(io_context),
timer_(io_context)
{
}
tcp::socket& socket()
{
return socket_;
}
void go()
{
boost::asio::spawn(strand_,
boost::bind(&session::echo,
shared_from_this(), _1));
boost::asio::spawn(strand_,
boost::bind(&session::timeout,
shared_from_this(), _1));
}
private:
void echo(boost::asio::yield_context yield)
{
try
{
char data[128];
for (;;)
{
timer_.expires_from_now(boost::posix_time::seconds(10));
std::size_t n = socket_.async_read_some(boost::asio::buffer(data), yield);
boost::asio::async_write(socket_, boost::asio::buffer(data, n), yield);
}
}
catch (std::exception& e)
{
socket_.close();
timer_.cancel();
}
}
void timeout(boost::asio::yield_context yield)
{
while (socket_.is_open())
{
boost::system::error_code ignored_ec;
timer_.async_wait(yield[ignored_ec]);
if (timer_.expires_from_now() <= boost::posix_time::seconds(0))
socket_.close();
}
}
boost::asio::io_context::strand strand_;
tcp::socket socket_;
boost::asio::deadline_timer timer_;
};
void do_accept(boost::asio::io_context& io_context,
unsigned short port, boost::asio::yield_context yield)
{
tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), port));
for (;;)
{
boost::system::error_code ec;
boost::shared_ptr<session> new_session(new session(io_context));
acceptor.async_accept(new_session->socket(), yield[ec]);
if (!ec) new_session->go();
}
}
int main(int argc, char* argv[])
{
try
{
if (argc != 2)
{
std::cerr << "Usage: echo_server <port>\n";
return 1;
}
boost::asio::io_context io_context;
boost::asio::spawn(io_context,
boost::bind(do_accept,
boost::ref(io_context), atoi(argv[1]), _1));
io_context.run();
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}

View File

@@ -0,0 +1,90 @@
//
// parallel_grep.cpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 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 <boost/asio/dispatch.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/thread_pool.hpp>
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <fstream>
#include <iostream>
#include <string>
using boost::asio::dispatch;
using boost::asio::spawn;
using boost::asio::strand;
using boost::asio::thread_pool;
using boost::asio::yield_context;
void print_match(std::string input_file, std::string line)
{
std::cout << input_file << ':' << line << std::endl;
}
void search_file(std::string search_string, std::string input_file,
strand<thread_pool::executor_type> output_strand, yield_context yield)
{
std::ifstream is(input_file.c_str());
std::string line;
std::size_t line_num = 0;
while (std::getline(is, line))
{
// If we find a match, send a message to the output.
if (line.find(search_string) != std::string::npos)
{
dispatch(output_strand, boost::bind(&print_match, input_file, line));
}
// Every so often we yield control to another coroutine.
if (++line_num % 10 == 0)
post(yield);
}
}
int main(int argc, char* argv[])
{
try
{
if (argc < 2)
{
std::cerr << "Usage: parallel_grep <string> <files...>\n";
return 1;
}
// We use a fixed size pool of threads for reading the input files. The
// number of threads is automatically determined based on the number of
// CPUs available in the system.
thread_pool pool;
// To prevent the output from being garbled, we use a strand to synchronise
// printing.
strand<thread_pool::executor_type> output_strand(pool.get_executor());
// Spawn a new coroutine for each file specified on the command line.
std::string search_string = argv[1];
for (int argn = 2; argn < argc; ++argn)
{
std::string input_file = argv[argn];
spawn(pool, boost::bind(&search_file,
search_string, input_file, output_strand, _1));
}
// Join the thread pool to wait for all the spawned tasks to complete.
pool.join();
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}