Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Jan 8, 2019
2 parents 03cba8f + b4584dd commit e2e2b5d
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 50 deletions.
12 changes: 7 additions & 5 deletions include/boost/process/async_system.hpp
Expand Up @@ -25,6 +25,7 @@
#include <type_traits>
#include <memory>
#include <boost/asio/async_result.hpp>
#include <boost/asio/post.hpp>
#include <boost/system/error_code.hpp>
#include <tuple>

Expand Down Expand Up @@ -64,11 +65,12 @@ struct async_system_handler : ::boost::process::detail::api::async_handler
errored = true;
#endif
auto & h = init.completion_handler;
ios.post(
[h, ec]() mutable
{
h(boost::system::error_code(ec.value(), boost::system::system_category()), -1);
});
boost::asio::post(
ios.get_executor(),
[h, ec]() mutable
{
h(boost::system::error_code(ec.value(), boost::system::system_category()), -1);
});
}

BOOST_ASIO_INITFN_RESULT_TYPE(ExitHandler, void (boost::system::error_code, int))
Expand Down
9 changes: 5 additions & 4 deletions include/boost/process/detail/posix/async_pipe.hpp
Expand Up @@ -9,6 +9,7 @@

#include <boost/process/detail/posix/basic_pipe.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/post.hpp>
#include <system_error>
#include <string>
#include <utility>
Expand Down Expand Up @@ -109,9 +110,9 @@ class async_pipe
void async_close()
{
if (_sink.is_open())
_sink.get_io_context(). post([this]{_sink.close();});
boost::asio::post(_sink.get_executor(), [this]{_sink.close();});
if (_source.is_open())
_source.get_io_context().post([this]{_source.close();});
boost::asio::post(_source.get_executor(), [this]{_source.close();});
}

template<typename MutableBufferSequence>
Expand Down Expand Up @@ -218,8 +219,8 @@ async_pipe::async_pipe(boost::asio::io_context & ios_source,
}

async_pipe::async_pipe(const async_pipe & p) :
_source(const_cast<async_pipe&>(p)._source.get_io_context()),
_sink( const_cast<async_pipe&>(p)._sink.get_io_context())
_source(const_cast<async_pipe&>(p)._source.get_executor().context()),
_sink( const_cast<async_pipe&>(p)._sink.get_executor().context())
{

//cannot get the handle from a const object.
Expand Down
11 changes: 7 additions & 4 deletions include/boost/process/detail/posix/sigchld_service.hpp
Expand Up @@ -7,6 +7,8 @@
#ifndef BOOST_PROCESS_DETAIL_POSIX_SIGCHLD_SERVICE_HPP_
#define BOOST_PROCESS_DETAIL_POSIX_SIGCHLD_SERVICE_HPP_

#include <boost/asio/dispatch.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/strand.hpp>
#include <boost/optional.hpp>
Expand Down Expand Up @@ -38,7 +40,8 @@ class sigchld_service : public boost::asio::detail::service_base<sigchld_service
SignalHandler, void(boost::system::error_code)> init{handler};

auto & h = init.completion_handler;
_strand.dispatch(
boost::asio::dispatch(
_strand,
[this, pid, h]
{
//check if the child actually is running first
Expand All @@ -54,15 +57,15 @@ class sigchld_service : public boost::asio::detail::service_base<sigchld_service
_signal_set.async_wait(
[this](const boost::system::error_code &ec, int)
{
_strand.dispatch([this, ec]{this->_handle_signal(ec);});
boost::asio::dispatch(_strand, [this, ec]{this->_handle_signal(ec);});
});
_receivers.emplace_back(pid, h);
}
});

return init.result.get();
}
void shutdown_service() override
void shutdown() override
{
_receivers.clear();
}
Expand Down Expand Up @@ -115,7 +118,7 @@ void sigchld_service::_handle_signal(const boost::system::error_code & ec)
_signal_set.async_wait(
[this](const boost::system::error_code & ec, int)
{
_strand.post([this, ec]{this->_handle_signal(ec);});
boost::asio::post(_strand, [this, ec]{this->_handle_signal(ec);});
});
}
}
Expand Down
21 changes: 11 additions & 10 deletions include/boost/process/detail/windows/async_pipe.hpp
Expand Up @@ -14,6 +14,7 @@
#include <boost/winapi/access_rights.hpp>
#include <boost/winapi/process.hpp>
#include <boost/process/detail/windows/basic_pipe.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/windows/stream_handle.hpp>
#include <atomic>
#include <system_error>
Expand Down Expand Up @@ -99,25 +100,25 @@ class async_pipe
if (_sink.is_open())
{
_sink.close();
_sink = handle_type(_sink.get_io_context());
_sink = handle_type(_sink.get_executor().context());
}
if (_source.is_open())
{
_source.close();
_source = handle_type(_source.get_io_context());
_source = handle_type(_source.get_executor().context());
}
}
void close(boost::system::error_code & ec)
{
if (_sink.is_open())
{
_sink.close(ec);
_sink = handle_type(_sink.get_io_context());
_sink = handle_type(_sink.get_executor().context());
}
if (_source.is_open())
{
_source.close(ec);
_source = handle_type(_source.get_io_context());
_source = handle_type(_source.get_executor().context());
}
}

Expand All @@ -128,9 +129,9 @@ class async_pipe
void async_close()
{
if (_sink.is_open())
_sink.get_io_context(). post([this]{_sink.close();});
boost::asio::post(_sink.get_executor(), [this]{_sink.close();});
if (_source.is_open())
_source.get_io_context().post([this]{_source.close();});
boost::asio::post(_source.get_executor(), [this]{_source.close();});
}

template<typename MutableBufferSequence>
Expand Down Expand Up @@ -237,8 +238,8 @@ class async_pipe


async_pipe::async_pipe(const async_pipe& p) :
_source(const_cast<handle_type&>(p._source).get_io_context()),
_sink (const_cast<handle_type&>(p._sink).get_io_context())
_source(const_cast<handle_type&>(p._source).get_executor().context()),
_sink (const_cast<handle_type&>(p._sink).get_executor().context())
{
auto proc = ::boost::winapi::GetCurrentProcess();

Expand Down Expand Up @@ -337,8 +338,8 @@ async_pipe& async_pipe::operator=(const async_pipe & p)
throw_last_error("Duplicate Pipe Failed");

//so we also assign the io_context
_source = ::boost::asio::windows::stream_handle(source_in.get_io_context(), source);
_sink = ::boost::asio::windows::stream_handle(source_in.get_io_context(), sink);
_source = ::boost::asio::windows::stream_handle(source_in.get_executor().context(), source);
_sink = ::boost::asio::windows::stream_handle(source_in.get_executor().context(), sink);

return *this;
}
Expand Down
7 changes: 6 additions & 1 deletion include/boost/process/detail/windows/basic_pipe.hpp
Expand Up @@ -143,8 +143,13 @@ basic_pipe<Char, Traits>::basic_pipe(const std::string & name)
static constexpr int FILE_FLAG_OVERLAPPED_ = 0x40000000; //temporary
//static constexpr int FILE_ATTRIBUTE_NORMAL_ = 0x00000080; //temporary

#if BOOST_NO_ANSI_APIS
std::wstring name_ = boost::process::detail::convert(name);
#else
auto &name_ = name;
#endif
::boost::winapi::HANDLE_ source = ::boost::winapi::create_named_pipe(
name.c_str(),
name_.c_str(),
::boost::winapi::PIPE_ACCESS_INBOUND_
| FILE_FLAG_OVERLAPPED_, //write flag
0, 1, 8192, 8192, 0, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion include/boost/process/detail/windows/wait_group.hpp
Expand Up @@ -17,7 +17,7 @@ namespace boost { namespace process { namespace detail { namespace windows {
struct group_handle;


inline bool wait_impl(const group_handle & p, std::error_code & ec, int wait_time)
inline bool wait_impl(const group_handle & p, std::error_code & ec, std::chrono::system_clock::rep wait_time)
{
::boost::winapi::DWORD_ completion_code;
::boost::winapi::ULONG_PTR_ completion_key;
Expand Down
12 changes: 6 additions & 6 deletions include/boost/process/pipe.hpp
Expand Up @@ -250,7 +250,7 @@ template<
>
class basic_ipstream : public std::basic_istream<CharT, Traits>
{
basic_pipebuf<CharT, Traits> _buf;
mutable basic_pipebuf<CharT, Traits> _buf;
public:

typedef basic_pipe<CharT, Traits> pipe_type;
Expand All @@ -262,7 +262,7 @@ class basic_ipstream : public std::basic_istream<CharT, Traits>
typedef typename Traits::off_type off_type ;

///Get access to the underlying stream_buf
basic_pipebuf<CharT, Traits>* rdbuf() {return &_buf;};
basic_pipebuf<CharT, Traits>* rdbuf() const {return &_buf;};

///Default constructor.
basic_ipstream() : std::basic_istream<CharT, Traits>(nullptr)
Expand Down Expand Up @@ -334,7 +334,7 @@ template<
>
class basic_opstream : public std::basic_ostream<CharT, Traits>
{
basic_pipebuf<CharT, Traits> _buf;
mutable basic_pipebuf<CharT, Traits> _buf;
public:
typedef basic_pipe<CharT, Traits> pipe_type;

Expand All @@ -346,7 +346,7 @@ class basic_opstream : public std::basic_ostream<CharT, Traits>


///Get access to the underlying stream_buf
basic_pipebuf<CharT, Traits>* rdbuf() const {return _buf;};
basic_pipebuf<CharT, Traits>* rdbuf() const {return &_buf;};

///Default constructor.
basic_opstream() : std::basic_ostream<CharT, Traits>(nullptr)
Expand Down Expand Up @@ -417,7 +417,7 @@ template<
>
class basic_pstream : public std::basic_iostream<CharT, Traits>
{
basic_pipebuf<CharT, Traits> _buf;
mutable basic_pipebuf<CharT, Traits> _buf;
public:
typedef basic_pipe<CharT, Traits> pipe_type;

Expand All @@ -429,7 +429,7 @@ class basic_pstream : public std::basic_iostream<CharT, Traits>


///Get access to the underlying stream_buf
basic_pipebuf<CharT, Traits>* rdbuf() const {return _buf;};
basic_pipebuf<CharT, Traits>* rdbuf() const {return &_buf;};

///Default constructor.
basic_pstream() : std::basic_iostream<CharT, Traits>(nullptr)
Expand Down
3 changes: 2 additions & 1 deletion include/boost/process/system.hpp
Expand Up @@ -22,6 +22,7 @@
#include <boost/process/child.hpp>
#include <boost/process/detail/async_handler.hpp>
#include <boost/process/detail/execute_impl.hpp>
#include <boost/asio/post.hpp>
#include <type_traits>
#include <mutex>
#include <condition_variable>
Expand Down Expand Up @@ -62,7 +63,7 @@ inline int system_impl(
::boost::process::on_exit(
[&](int, const std::error_code&)
{
ios.post([&]{exited.store(true);});
boost::asio::post(ios.get_executor(), [&]{exited.store(true);});
}));
if (!c.valid() || !check.succeeded)
return -1;
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.jam
Expand Up @@ -19,6 +19,7 @@ if [ os.name ] = NT
}

project : requirements
<define>BOOST_ASIO_NO_DEPRECATED
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
<toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
<toolset>msvc:<cxxflags>/bigobj
Expand Down
3 changes: 2 additions & 1 deletion test/async_system_stackful.cpp
Expand Up @@ -15,6 +15,7 @@

#include <string>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/asio/use_future.hpp>
Expand Down Expand Up @@ -45,7 +46,7 @@ BOOST_AUTO_TEST_CASE(stackful, *boost::unit_test::timeout(15))
};

boost::asio::spawn(ios, stackful);
ios.post([&]{did_something_else = true;});
boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});

ios.run();
BOOST_CHECK(did_something_else);
Expand Down
7 changes: 4 additions & 3 deletions test/async_system_stackful_error.cpp
Expand Up @@ -15,6 +15,7 @@

#include <string>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/asio/use_future.hpp>
Expand Down Expand Up @@ -45,7 +46,7 @@ BOOST_AUTO_TEST_CASE(stackful, *boost::unit_test::timeout(15))
};

boost::asio::spawn(ios, stackful);
ios.post([&]{did_something_else = true;});
boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});

ios.run();
BOOST_CHECK(did_something_else);
Expand All @@ -71,7 +72,7 @@ BOOST_AUTO_TEST_CASE(stackful_except, *boost::unit_test::timeout(15))
};

boost::asio::spawn(ios, stackful);
ios.post([&]{did_something_else = true;});
boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});
ios.run();

BOOST_CHECK(did_something_else);
Expand Down Expand Up @@ -100,7 +101,7 @@ BOOST_AUTO_TEST_CASE(stackful_error, *boost::unit_test::timeout(15))
};

boost::asio::spawn(ios, stackful);
ios.post([&]{did_something_else = true;});
boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});
ios.run();

BOOST_CHECK(did_something_else);
Expand Down
3 changes: 2 additions & 1 deletion test/async_system_stackful_except.cpp
Expand Up @@ -15,6 +15,7 @@

#include <string>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/asio/use_future.hpp>
Expand Down Expand Up @@ -44,7 +45,7 @@ BOOST_AUTO_TEST_CASE(stackful_except, *boost::unit_test::timeout(15))
};

boost::asio::spawn(ios, stackful);
ios.post([&]{did_something_else = true;});
boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});
ios.run();

BOOST_CHECK(did_something_else);
Expand Down
5 changes: 3 additions & 2 deletions test/async_system_stackless.cpp
Expand Up @@ -15,6 +15,7 @@

#include <string>
#include <boost/asio/io_context.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/asio/use_future.hpp>
Expand Down Expand Up @@ -57,8 +58,8 @@ BOOST_AUTO_TEST_CASE(stackless, *boost::unit_test::timeout(15))
}
} stackless{ios, did_something_else};

ios.post([&]{stackless();});
ios.post([&]{did_something_else = true;});
boost::asio::post(ios.get_executor(), [&]{stackless();});
boost::asio::post(ios.get_executor(), [&]{did_something_else = true;});

ios.run();

Expand Down
24 changes: 13 additions & 11 deletions test/system_test2.cpp
Expand Up @@ -70,17 +70,19 @@ BOOST_AUTO_TEST_CASE(explicit_async_io_running, *boost::unit_test::timeout(10))
std::future<std::string> fut;
std::error_code ec;

ios.post([&]
{
bp::system(
master_test_suite().argv[1],
"test", "--echo-stdout", "abc",
bp::std_out > fut,
ios,
ec
);
BOOST_REQUIRE(!ec);
});
boost::asio::post(
ios.get_executor(),
[&] {
bp::system(
master_test_suite().argv[1],
"test", "--echo-stdout", "abc",
bp::std_out > fut,
ios,
ec
);
BOOST_REQUIRE(!ec);
}
);


ios.run();
Expand Down

0 comments on commit e2e2b5d

Please sign in to comment.