// transmit_file.cpp
// ~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// 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)
random_access_handle& file, Handler handler)
{
// Construct an OVERLAPPED-derived object to contain the handler.
- overlapped_ptr overlapped(socket.get_io_service(), handler);
+ overlapped_ptr overlapped(socket.get_executor().context(), handler);
// Initiate the TransmitFile operation.
BOOL ok = ::TransmitFile(socket.native_handle(),
{
// The operation completed immediately, so a completion notification needs
// to be posted. When complete() is called, ownership of the OVERLAPPED-
- // derived object passes to the io_service.
+ // derived object passes to the io_context.
boost::system::error_code ec(last_error,
boost::asio::error::get_system_category());
overlapped.complete(ec, 0);
else
{
// The operation was successfully initiated, so ownership of the
- // OVERLAPPED-derived object has passed to the io_service.
+ // OVERLAPPED-derived object has passed to the io_context.
overlapped.release();
}
}
public:
typedef boost::shared_ptr<connection> pointer;
- static pointer create(boost::asio::io_service& io_service,
+ static pointer create(boost::asio::io_context& io_context,
const std::string& filename)
{
- return pointer(new connection(io_service, filename));
+ return pointer(new connection(io_context, filename));
}
tcp::socket& socket()
}
private:
- connection(boost::asio::io_service& io_service, const std::string& filename)
- : socket_(io_service),
+ connection(boost::asio::io_context& io_context, const std::string& filename)
+ : socket_(io_context),
filename_(filename),
- file_(io_service)
+ file_(io_context)
{
}
class server
{
public:
- server(boost::asio::io_service& io_service,
+ server(boost::asio::io_context& io_context,
unsigned short port, const std::string& filename)
- : acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
+ : acceptor_(io_context, tcp::endpoint(tcp::v4(), port)),
filename_(filename)
{
start_accept();
void start_accept()
{
connection::pointer new_connection =
- connection::create(acceptor_.get_io_service(), filename_);
+ connection::create(acceptor_.get_executor().context(), filename_);
acceptor_.async_accept(new_connection->socket(),
boost::bind(&server::handle_accept, this, new_connection,
return 1;
}
- boost::asio::io_service io_service;
+ boost::asio::io_context io_context;
using namespace std; // For atoi.
- server s(io_service, atoi(argv[1]), argv[2]);
+ server s(io_context, atoi(argv[1]), argv[2]);
- io_service.run();
+ io_context.run();
}
catch (std::exception& e)
{