// basic_serial_port.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
#if defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/win_iocp_serial_port_service.hpp>
#else
-# include <boost/asio/detail/reactive_serial_port_service.hpp>
+# include <boost/asio/detail/posix_serial_port_service.hpp>
#endif
#if defined(BOOST_ASIO_HAS_MOVE)
typedef detail::win_iocp_serial_port_service::native_handle_type
native_handle_type;
#else
- typedef detail::reactive_serial_port_service::native_handle_type
+ typedef detail::posix_serial_port_service::native_handle_type
native_handle_type;
#endif
* serial port.
*/
explicit basic_serial_port(const executor_type& ex)
- : impl_(ex)
+ : impl_(0, ex)
{
}
*/
template <typename ExecutionContext>
explicit basic_serial_port(ExecutionContext& context,
- typename enable_if<
+ typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value,
- basic_serial_port
- >::type* = 0)
- : impl_(context)
+ defaulted_constraint
+ >::type = defaulted_constraint())
+ : impl_(0, 0, context)
{
}
* port.
*/
basic_serial_port(const executor_type& ex, const char* device)
- : impl_(ex)
+ : impl_(0, ex)
{
boost::system::error_code ec;
impl_.get_service().open(impl_.get_implementation(), device, ec);
*/
template <typename ExecutionContext>
basic_serial_port(ExecutionContext& context, const char* device,
- typename enable_if<
+ typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value
- >::type* = 0)
- : impl_(context)
+ >::type = 0)
+ : impl_(0, 0, context)
{
boost::system::error_code ec;
impl_.get_service().open(impl_.get_implementation(), device, ec);
* port.
*/
basic_serial_port(const executor_type& ex, const std::string& device)
- : impl_(ex)
+ : impl_(0, ex)
{
boost::system::error_code ec;
impl_.get_service().open(impl_.get_implementation(), device, ec);
*/
template <typename ExecutionContext>
basic_serial_port(ExecutionContext& context, const std::string& device,
- typename enable_if<
+ typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value
- >::type* = 0)
- : impl_(context)
+ >::type = 0)
+ : impl_(0, 0, context)
{
boost::system::error_code ec;
impl_.get_service().open(impl_.get_implementation(), device, ec);
*/
basic_serial_port(const executor_type& ex,
const native_handle_type& native_serial_port)
- : impl_(ex)
+ : impl_(0, ex)
{
boost::system::error_code ec;
impl_.get_service().assign(impl_.get_implementation(),
template <typename ExecutionContext>
basic_serial_port(ExecutionContext& context,
const native_handle_type& native_serial_port,
- typename enable_if<
+ typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value
- >::type* = 0)
- : impl_(context)
+ >::type = 0)
+ : impl_(0, 0, context)
{
boost::system::error_code ec;
impl_.get_service().assign(impl_.get_implementation(),
/// Start an asynchronous write.
/**
* This function is used to asynchronously write data to the serial port.
- * The function call always returns immediately.
+ * It is an initiating function for an @ref asynchronous_operation, and always
+ * returns immediately.
*
* @param buffers One or more data buffers to be written to the serial port.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
- * that they remain valid until the handler is called.
+ * that they remain valid until the completion handler is called.
*
- * @param handler The handler to be called when the write operation completes.
- * Copies will be made of the handler as required. The function signature of
- * the handler must be:
+ * @param token The @ref completion_token that will be used to produce a
+ * completion handler, which will be called when the write completes.
+ * Potential completion tokens include @ref use_future, @ref use_awaitable,
+ * @ref yield_context, or a function object with the correct completion
+ * signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
- * std::size_t bytes_transferred // Number of bytes written.
+ * std::size_t bytes_transferred // Number of bytes written.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. On
- * immediate completion, invocation of the handler will be performed in a
+ * not, the completion handler will not be invoked from within this function.
+ * On immediate completion, invocation of the handler will be performed in a
* manner equivalent to using boost::asio::post().
*
+ * @par Completion Signature
+ * @code void(boost::system::error_code, std::size_t) @endcode
+ *
* @note The write operation may not transmit all of the data to the peer.
* Consider using the @ref async_write function if you need to ensure that all
* data is written before the asynchronous operation completes.
* See the @ref buffer documentation for information on writing multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
+ *
+ * @par Per-Operation Cancellation
+ * On POSIX or Windows operating systems, this asynchronous operation supports
+ * cancellation for the following boost::asio::cancellation_type values:
+ *
+ * @li @c cancellation_type::terminal
+ *
+ * @li @c cancellation_type::partial
+ *
+ * @li @c cancellation_type::total
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
- std::size_t)) WriteHandler
+ std::size_t)) WriteToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
+ BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
void (boost::system::error_code, std::size_t))
async_write_some(const ConstBufferSequence& buffers,
- BOOST_ASIO_MOVE_ARG(WriteHandler) handler
+ BOOST_ASIO_MOVE_ARG(WriteToken) token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
- return async_initiate<WriteHandler,
+ return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
- initiate_async_write_some(this), handler, buffers);
+ initiate_async_write_some(this), token, buffers);
}
/// Read some data from the serial port.
/// Start an asynchronous read.
/**
* This function is used to asynchronously read data from the serial port.
- * The function call always returns immediately.
+ * It is an initiating function for an @ref asynchronous_operation, and always
+ * returns immediately.
*
* @param buffers One or more buffers into which the data will be read.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
- * that they remain valid until the handler is called.
+ * that they remain valid until the completion handler is called.
*
- * @param handler The handler to be called when the read operation completes.
- * Copies will be made of the handler as required. The function signature of
- * the handler must be:
+ * @param token The @ref completion_token that will be used to produce a
+ * completion handler, which will be called when the read completes.
+ * Potential completion tokens include @ref use_future, @ref use_awaitable,
+ * @ref yield_context, or a function object with the correct completion
+ * signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
- * std::size_t bytes_transferred // Number of bytes read.
+ * std::size_t bytes_transferred // Number of bytes read.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. On
- * immediate completion, invocation of the handler will be performed in a
+ * not, the completion handler will not be invoked from within this function.
+ * On immediate completion, invocation of the handler will be performed in a
* manner equivalent to using boost::asio::post().
*
+ * @par Completion Signature
+ * @code void(boost::system::error_code, std::size_t) @endcode
+ *
* @note The read operation may not read all of the requested number of bytes.
* Consider using the @ref async_read function if you need to ensure that the
* requested amount of data is read before the asynchronous operation
* See the @ref buffer documentation for information on reading into multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
+ *
+ * @par Per-Operation Cancellation
+ * On POSIX or Windows operating systems, this asynchronous operation supports
+ * cancellation for the following boost::asio::cancellation_type values:
+ *
+ * @li @c cancellation_type::terminal
+ *
+ * @li @c cancellation_type::partial
+ *
+ * @li @c cancellation_type::total
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
- std::size_t)) ReadHandler
+ std::size_t)) ReadToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
- BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
+ BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
void (boost::system::error_code, std::size_t))
async_read_some(const MutableBufferSequence& buffers,
- BOOST_ASIO_MOVE_ARG(ReadHandler) handler
+ BOOST_ASIO_MOVE_ARG(ReadToken) token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
- return async_initiate<ReadHandler,
+ return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
- initiate_async_read_some(this), handler, buffers);
+ initiate_async_read_some(this), token, buffers);
}
private:
#if defined(BOOST_ASIO_HAS_IOCP)
detail::io_object_impl<detail::win_iocp_serial_port_service, Executor> impl_;
#else
- detail::io_object_impl<detail::reactive_serial_port_service, Executor> impl_;
+ detail::io_object_impl<detail::posix_serial_port_service, Executor> impl_;
#endif
};