2 // basic_serial_port.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_ASIO_BASIC_SERIAL_PORT_HPP
13 #define BOOST_ASIO_BASIC_SERIAL_PORT_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
21 #if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
22 || defined(GENERATING_DOCUMENTATION)
25 #include <boost/asio/async_result.hpp>
26 #include <boost/asio/detail/handler_type_requirements.hpp>
27 #include <boost/asio/detail/io_object_impl.hpp>
28 #include <boost/asio/detail/non_const_lvalue.hpp>
29 #include <boost/asio/detail/throw_error.hpp>
30 #include <boost/asio/detail/type_traits.hpp>
31 #include <boost/asio/error.hpp>
32 #include <boost/asio/execution_context.hpp>
33 #include <boost/asio/executor.hpp>
34 #include <boost/asio/serial_port_base.hpp>
35 #if defined(BOOST_ASIO_HAS_IOCP)
36 # include <boost/asio/detail/win_iocp_serial_port_service.hpp>
38 # include <boost/asio/detail/reactive_serial_port_service.hpp>
41 #if defined(BOOST_ASIO_HAS_MOVE)
43 #endif // defined(BOOST_ASIO_HAS_MOVE)
45 #include <boost/asio/detail/push_options.hpp>
50 /// Provides serial port functionality.
52 * The basic_serial_port class provides a wrapper over serial port
56 * @e Distinct @e objects: Safe.@n
57 * @e Shared @e objects: Unsafe.
59 template <typename Executor = executor>
60 class basic_serial_port
61 : public serial_port_base
64 /// The type of the executor associated with the object.
65 typedef Executor executor_type;
67 /// Rebinds the serial port type to another executor.
68 template <typename Executor1>
69 struct rebind_executor
71 /// The serial port type when rebound to the specified executor.
72 typedef basic_serial_port<Executor1> other;
75 /// The native representation of a serial port.
76 #if defined(GENERATING_DOCUMENTATION)
77 typedef implementation_defined native_handle_type;
78 #elif defined(BOOST_ASIO_HAS_IOCP)
79 typedef detail::win_iocp_serial_port_service::native_handle_type
82 typedef detail::reactive_serial_port_service::native_handle_type
86 /// A basic_basic_serial_port is always the lowest layer.
87 typedef basic_serial_port lowest_layer_type;
89 /// Construct a basic_serial_port without opening it.
91 * This constructor creates a serial port without opening it.
93 * @param ex The I/O executor that the serial port will use, by default, to
94 * dispatch handlers for any asynchronous operations performed on the
97 explicit basic_serial_port(const executor_type& ex)
102 /// Construct a basic_serial_port without opening it.
104 * This constructor creates a serial port without opening it.
106 * @param context An execution context which provides the I/O executor that
107 * the serial port will use, by default, to dispatch handlers for any
108 * asynchronous operations performed on the serial port.
110 template <typename ExecutionContext>
111 explicit basic_serial_port(ExecutionContext& context,
113 is_convertible<ExecutionContext&, execution_context&>::value,
120 /// Construct and open a basic_serial_port.
122 * This constructor creates and opens a serial port for the specified device
125 * @param ex The I/O executor that the serial port will use, by default, to
126 * dispatch handlers for any asynchronous operations performed on the
129 * @param device The platform-specific device name for this serial
132 basic_serial_port(const executor_type& ex, const char* device)
135 boost::system::error_code ec;
136 impl_.get_service().open(impl_.get_implementation(), device, ec);
137 boost::asio::detail::throw_error(ec, "open");
140 /// Construct and open a basic_serial_port.
142 * This constructor creates and opens a serial port for the specified device
145 * @param context An execution context which provides the I/O executor that
146 * the serial port will use, by default, to dispatch handlers for any
147 * asynchronous operations performed on the serial port.
149 * @param device The platform-specific device name for this serial
152 template <typename ExecutionContext>
153 basic_serial_port(ExecutionContext& context, const char* device,
155 is_convertible<ExecutionContext&, execution_context&>::value
159 boost::system::error_code ec;
160 impl_.get_service().open(impl_.get_implementation(), device, ec);
161 boost::asio::detail::throw_error(ec, "open");
164 /// Construct and open a basic_serial_port.
166 * This constructor creates and opens a serial port for the specified device
169 * @param ex The I/O executor that the serial port will use, by default, to
170 * dispatch handlers for any asynchronous operations performed on the
173 * @param device The platform-specific device name for this serial
176 basic_serial_port(const executor_type& ex, const std::string& device)
179 boost::system::error_code ec;
180 impl_.get_service().open(impl_.get_implementation(), device, ec);
181 boost::asio::detail::throw_error(ec, "open");
184 /// Construct and open a basic_serial_port.
186 * This constructor creates and opens a serial port for the specified device
189 * @param context An execution context which provides the I/O executor that
190 * the serial port will use, by default, to dispatch handlers for any
191 * asynchronous operations performed on the serial port.
193 * @param device The platform-specific device name for this serial
196 template <typename ExecutionContext>
197 basic_serial_port(ExecutionContext& context, const std::string& device,
199 is_convertible<ExecutionContext&, execution_context&>::value
203 boost::system::error_code ec;
204 impl_.get_service().open(impl_.get_implementation(), device, ec);
205 boost::asio::detail::throw_error(ec, "open");
208 /// Construct a basic_serial_port on an existing native serial port.
210 * This constructor creates a serial port object to hold an existing native
213 * @param ex The I/O executor that the serial port will use, by default, to
214 * dispatch handlers for any asynchronous operations performed on the
217 * @param native_serial_port A native serial port.
219 * @throws boost::system::system_error Thrown on failure.
221 basic_serial_port(const executor_type& ex,
222 const native_handle_type& native_serial_port)
225 boost::system::error_code ec;
226 impl_.get_service().assign(impl_.get_implementation(),
227 native_serial_port, ec);
228 boost::asio::detail::throw_error(ec, "assign");
231 /// Construct a basic_serial_port on an existing native serial port.
233 * This constructor creates a serial port object to hold an existing native
236 * @param context An execution context which provides the I/O executor that
237 * the serial port will use, by default, to dispatch handlers for any
238 * asynchronous operations performed on the serial port.
240 * @param native_serial_port A native serial port.
242 * @throws boost::system::system_error Thrown on failure.
244 template <typename ExecutionContext>
245 basic_serial_port(ExecutionContext& context,
246 const native_handle_type& native_serial_port,
248 is_convertible<ExecutionContext&, execution_context&>::value
252 boost::system::error_code ec;
253 impl_.get_service().assign(impl_.get_implementation(),
254 native_serial_port, ec);
255 boost::asio::detail::throw_error(ec, "assign");
258 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
259 /// Move-construct a basic_serial_port from another.
261 * This constructor moves a serial port from one object to another.
263 * @param other The other basic_serial_port object from which the move will
266 * @note Following the move, the moved-from object is in the same state as if
267 * constructed using the @c basic_serial_port(const executor_type&)
270 basic_serial_port(basic_serial_port&& other)
271 : impl_(std::move(other.impl_))
275 /// Move-assign a basic_serial_port from another.
277 * This assignment operator moves a serial port from one object to another.
279 * @param other The other basic_serial_port object from which the move will
282 * @note Following the move, the moved-from object is in the same state as if
283 * constructed using the @c basic_serial_port(const executor_type&)
286 basic_serial_port& operator=(basic_serial_port&& other)
288 impl_ = std::move(other.impl_);
291 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
293 /// Destroys the serial port.
295 * This function destroys the serial port, cancelling any outstanding
296 * asynchronous wait operations associated with the serial port as if by
303 /// Get the executor associated with the object.
304 executor_type get_executor() BOOST_ASIO_NOEXCEPT
306 return impl_.get_executor();
309 /// Get a reference to the lowest layer.
311 * This function returns a reference to the lowest layer in a stack of
312 * layers. Since a basic_serial_port cannot contain any further layers, it
313 * simply returns a reference to itself.
315 * @return A reference to the lowest layer in the stack of layers. Ownership
316 * is not transferred to the caller.
318 lowest_layer_type& lowest_layer()
323 /// Get a const reference to the lowest layer.
325 * This function returns a const reference to the lowest layer in a stack of
326 * layers. Since a basic_serial_port cannot contain any further layers, it
327 * simply returns a reference to itself.
329 * @return A const reference to the lowest layer in the stack of layers.
330 * Ownership is not transferred to the caller.
332 const lowest_layer_type& lowest_layer() const
337 /// Open the serial port using the specified device name.
339 * This function opens the serial port for the specified device name.
341 * @param device The platform-specific device name.
343 * @throws boost::system::system_error Thrown on failure.
345 void open(const std::string& device)
347 boost::system::error_code ec;
348 impl_.get_service().open(impl_.get_implementation(), device, ec);
349 boost::asio::detail::throw_error(ec, "open");
352 /// Open the serial port using the specified device name.
354 * This function opens the serial port using the given platform-specific
357 * @param device The platform-specific device name.
359 * @param ec Set the indicate what error occurred, if any.
361 BOOST_ASIO_SYNC_OP_VOID open(const std::string& device,
362 boost::system::error_code& ec)
364 impl_.get_service().open(impl_.get_implementation(), device, ec);
365 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
368 /// Assign an existing native serial port to the serial port.
370 * This function opens the serial port to hold an existing native serial port.
372 * @param native_serial_port A native serial port.
374 * @throws boost::system::system_error Thrown on failure.
376 void assign(const native_handle_type& native_serial_port)
378 boost::system::error_code ec;
379 impl_.get_service().assign(impl_.get_implementation(),
380 native_serial_port, ec);
381 boost::asio::detail::throw_error(ec, "assign");
384 /// Assign an existing native serial port to the serial port.
386 * This function opens the serial port to hold an existing native serial port.
388 * @param native_serial_port A native serial port.
390 * @param ec Set to indicate what error occurred, if any.
392 BOOST_ASIO_SYNC_OP_VOID assign(const native_handle_type& native_serial_port,
393 boost::system::error_code& ec)
395 impl_.get_service().assign(impl_.get_implementation(),
396 native_serial_port, ec);
397 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
400 /// Determine whether the serial port is open.
403 return impl_.get_service().is_open(impl_.get_implementation());
406 /// Close the serial port.
408 * This function is used to close the serial port. Any asynchronous read or
409 * write operations will be cancelled immediately, and will complete with the
410 * boost::asio::error::operation_aborted error.
412 * @throws boost::system::system_error Thrown on failure.
416 boost::system::error_code ec;
417 impl_.get_service().close(impl_.get_implementation(), ec);
418 boost::asio::detail::throw_error(ec, "close");
421 /// Close the serial port.
423 * This function is used to close the serial port. Any asynchronous read or
424 * write operations will be cancelled immediately, and will complete with the
425 * boost::asio::error::operation_aborted error.
427 * @param ec Set to indicate what error occurred, if any.
429 BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec)
431 impl_.get_service().close(impl_.get_implementation(), ec);
432 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
435 /// Get the native serial port representation.
437 * This function may be used to obtain the underlying representation of the
438 * serial port. This is intended to allow access to native serial port
439 * functionality that is not otherwise provided.
441 native_handle_type native_handle()
443 return impl_.get_service().native_handle(impl_.get_implementation());
446 /// Cancel all asynchronous operations associated with the serial port.
448 * This function causes all outstanding asynchronous read or write operations
449 * to finish immediately, and the handlers for cancelled operations will be
450 * passed the boost::asio::error::operation_aborted error.
452 * @throws boost::system::system_error Thrown on failure.
456 boost::system::error_code ec;
457 impl_.get_service().cancel(impl_.get_implementation(), ec);
458 boost::asio::detail::throw_error(ec, "cancel");
461 /// Cancel all asynchronous operations associated with the serial port.
463 * This function causes all outstanding asynchronous read or write operations
464 * to finish immediately, and the handlers for cancelled operations will be
465 * passed the boost::asio::error::operation_aborted error.
467 * @param ec Set to indicate what error occurred, if any.
469 BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec)
471 impl_.get_service().cancel(impl_.get_implementation(), ec);
472 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
475 /// Send a break sequence to the serial port.
477 * This function causes a break sequence of platform-specific duration to be
478 * sent out the serial port.
480 * @throws boost::system::system_error Thrown on failure.
484 boost::system::error_code ec;
485 impl_.get_service().send_break(impl_.get_implementation(), ec);
486 boost::asio::detail::throw_error(ec, "send_break");
489 /// Send a break sequence to the serial port.
491 * This function causes a break sequence of platform-specific duration to be
492 * sent out the serial port.
494 * @param ec Set to indicate what error occurred, if any.
496 BOOST_ASIO_SYNC_OP_VOID send_break(boost::system::error_code& ec)
498 impl_.get_service().send_break(impl_.get_implementation(), ec);
499 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
502 /// Set an option on the serial port.
504 * This function is used to set an option on the serial port.
506 * @param option The option value to be set on the serial port.
508 * @throws boost::system::system_error Thrown on failure.
510 * @sa SettableSerialPortOption @n
511 * boost::asio::serial_port_base::baud_rate @n
512 * boost::asio::serial_port_base::flow_control @n
513 * boost::asio::serial_port_base::parity @n
514 * boost::asio::serial_port_base::stop_bits @n
515 * boost::asio::serial_port_base::character_size
517 template <typename SettableSerialPortOption>
518 void set_option(const SettableSerialPortOption& option)
520 boost::system::error_code ec;
521 impl_.get_service().set_option(impl_.get_implementation(), option, ec);
522 boost::asio::detail::throw_error(ec, "set_option");
525 /// Set an option on the serial port.
527 * This function is used to set an option on the serial port.
529 * @param option The option value to be set on the serial port.
531 * @param ec Set to indicate what error occurred, if any.
533 * @sa SettableSerialPortOption @n
534 * boost::asio::serial_port_base::baud_rate @n
535 * boost::asio::serial_port_base::flow_control @n
536 * boost::asio::serial_port_base::parity @n
537 * boost::asio::serial_port_base::stop_bits @n
538 * boost::asio::serial_port_base::character_size
540 template <typename SettableSerialPortOption>
541 BOOST_ASIO_SYNC_OP_VOID set_option(const SettableSerialPortOption& option,
542 boost::system::error_code& ec)
544 impl_.get_service().set_option(impl_.get_implementation(), option, ec);
545 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
548 /// Get an option from the serial port.
550 * This function is used to get the current value of an option on the serial
553 * @param option The option value to be obtained from the serial port.
555 * @throws boost::system::system_error Thrown on failure.
557 * @sa GettableSerialPortOption @n
558 * boost::asio::serial_port_base::baud_rate @n
559 * boost::asio::serial_port_base::flow_control @n
560 * boost::asio::serial_port_base::parity @n
561 * boost::asio::serial_port_base::stop_bits @n
562 * boost::asio::serial_port_base::character_size
564 template <typename GettableSerialPortOption>
565 void get_option(GettableSerialPortOption& option) const
567 boost::system::error_code ec;
568 impl_.get_service().get_option(impl_.get_implementation(), option, ec);
569 boost::asio::detail::throw_error(ec, "get_option");
572 /// Get an option from the serial port.
574 * This function is used to get the current value of an option on the serial
577 * @param option The option value to be obtained from the serial port.
579 * @param ec Set to indicate what error occurred, if any.
581 * @sa GettableSerialPortOption @n
582 * boost::asio::serial_port_base::baud_rate @n
583 * boost::asio::serial_port_base::flow_control @n
584 * boost::asio::serial_port_base::parity @n
585 * boost::asio::serial_port_base::stop_bits @n
586 * boost::asio::serial_port_base::character_size
588 template <typename GettableSerialPortOption>
589 BOOST_ASIO_SYNC_OP_VOID get_option(GettableSerialPortOption& option,
590 boost::system::error_code& ec) const
592 impl_.get_service().get_option(impl_.get_implementation(), option, ec);
593 BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
596 /// Write some data to the serial port.
598 * This function is used to write data to the serial port. The function call
599 * will block until one or more bytes of the data has been written
600 * successfully, or until an error occurs.
602 * @param buffers One or more data buffers to be written to the serial port.
604 * @returns The number of bytes written.
606 * @throws boost::system::system_error Thrown on failure. An error code of
607 * boost::asio::error::eof indicates that the connection was closed by the
610 * @note The write_some operation may not transmit all of the data to the
611 * peer. Consider using the @ref write function if you need to ensure that
612 * all data is written before the blocking operation completes.
615 * To write a single data buffer use the @ref buffer function as follows:
617 * basic_serial_port.write_some(boost::asio::buffer(data, size));
619 * See the @ref buffer documentation for information on writing multiple
620 * buffers in one go, and how to use it with arrays, boost::array or
623 template <typename ConstBufferSequence>
624 std::size_t write_some(const ConstBufferSequence& buffers)
626 boost::system::error_code ec;
627 std::size_t s = impl_.get_service().write_some(
628 impl_.get_implementation(), buffers, ec);
629 boost::asio::detail::throw_error(ec, "write_some");
633 /// Write some data to the serial port.
635 * This function is used to write data to the serial port. The function call
636 * will block until one or more bytes of the data has been written
637 * successfully, or until an error occurs.
639 * @param buffers One or more data buffers to be written to the serial port.
641 * @param ec Set to indicate what error occurred, if any.
643 * @returns The number of bytes written. Returns 0 if an error occurred.
645 * @note The write_some operation may not transmit all of the data to the
646 * peer. Consider using the @ref write function if you need to ensure that
647 * all data is written before the blocking operation completes.
649 template <typename ConstBufferSequence>
650 std::size_t write_some(const ConstBufferSequence& buffers,
651 boost::system::error_code& ec)
653 return impl_.get_service().write_some(
654 impl_.get_implementation(), buffers, ec);
657 /// Start an asynchronous write.
659 * This function is used to asynchronously write data to the serial port.
660 * The function call always returns immediately.
662 * @param buffers One or more data buffers to be written to the serial port.
663 * Although the buffers object may be copied as necessary, ownership of the
664 * underlying memory blocks is retained by the caller, which must guarantee
665 * that they remain valid until the handler is called.
667 * @param handler The handler to be called when the write operation completes.
668 * Copies will be made of the handler as required. The function signature of
669 * the handler must be:
670 * @code void handler(
671 * const boost::system::error_code& error, // Result of operation.
672 * std::size_t bytes_transferred // Number of bytes written.
674 * Regardless of whether the asynchronous operation completes immediately or
675 * not, the handler will not be invoked from within this function. On
676 * immediate completion, invocation of the handler will be performed in a
677 * manner equivalent to using boost::asio::post().
679 * @note The write operation may not transmit all of the data to the peer.
680 * Consider using the @ref async_write function if you need to ensure that all
681 * data is written before the asynchronous operation completes.
684 * To write a single data buffer use the @ref buffer function as follows:
686 * basic_serial_port.async_write_some(
687 * boost::asio::buffer(data, size), handler);
689 * See the @ref buffer documentation for information on writing multiple
690 * buffers in one go, and how to use it with arrays, boost::array or
693 template <typename ConstBufferSequence,
694 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
695 std::size_t)) WriteHandler
696 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
697 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
698 void (boost::system::error_code, std::size_t))
699 async_write_some(const ConstBufferSequence& buffers,
700 BOOST_ASIO_MOVE_ARG(WriteHandler) handler
701 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
703 return async_initiate<WriteHandler,
704 void (boost::system::error_code, std::size_t)>(
705 initiate_async_write_some(this), handler, buffers);
708 /// Read some data from the serial port.
710 * This function is used to read data from the serial port. The function
711 * call will block until one or more bytes of data has been read successfully,
712 * or until an error occurs.
714 * @param buffers One or more buffers into which the data will be read.
716 * @returns The number of bytes read.
718 * @throws boost::system::system_error Thrown on failure. An error code of
719 * boost::asio::error::eof indicates that the connection was closed by the
722 * @note The read_some operation may not read all of the requested number of
723 * bytes. Consider using the @ref read function if you need to ensure that
724 * the requested amount of data is read before the blocking operation
728 * To read into a single data buffer use the @ref buffer function as follows:
730 * basic_serial_port.read_some(boost::asio::buffer(data, size));
732 * See the @ref buffer documentation for information on reading into multiple
733 * buffers in one go, and how to use it with arrays, boost::array or
736 template <typename MutableBufferSequence>
737 std::size_t read_some(const MutableBufferSequence& buffers)
739 boost::system::error_code ec;
740 std::size_t s = impl_.get_service().read_some(
741 impl_.get_implementation(), buffers, ec);
742 boost::asio::detail::throw_error(ec, "read_some");
746 /// Read some data from the serial port.
748 * This function is used to read data from the serial port. The function
749 * call will block until one or more bytes of data has been read successfully,
750 * or until an error occurs.
752 * @param buffers One or more buffers into which the data will be read.
754 * @param ec Set to indicate what error occurred, if any.
756 * @returns The number of bytes read. Returns 0 if an error occurred.
758 * @note The read_some operation may not read all of the requested number of
759 * bytes. Consider using the @ref read function if you need to ensure that
760 * the requested amount of data is read before the blocking operation
763 template <typename MutableBufferSequence>
764 std::size_t read_some(const MutableBufferSequence& buffers,
765 boost::system::error_code& ec)
767 return impl_.get_service().read_some(
768 impl_.get_implementation(), buffers, ec);
771 /// Start an asynchronous read.
773 * This function is used to asynchronously read data from the serial port.
774 * The function call always returns immediately.
776 * @param buffers One or more buffers into which the data will be read.
777 * Although the buffers object may be copied as necessary, ownership of the
778 * underlying memory blocks is retained by the caller, which must guarantee
779 * that they remain valid until the handler is called.
781 * @param handler The handler to be called when the read operation completes.
782 * Copies will be made of the handler as required. The function signature of
783 * the handler must be:
784 * @code void handler(
785 * const boost::system::error_code& error, // Result of operation.
786 * std::size_t bytes_transferred // Number of bytes read.
788 * Regardless of whether the asynchronous operation completes immediately or
789 * not, the handler will not be invoked from within this function. On
790 * immediate completion, invocation of the handler will be performed in a
791 * manner equivalent to using boost::asio::post().
793 * @note The read operation may not read all of the requested number of bytes.
794 * Consider using the @ref async_read function if you need to ensure that the
795 * requested amount of data is read before the asynchronous operation
799 * To read into a single data buffer use the @ref buffer function as follows:
801 * basic_serial_port.async_read_some(
802 * boost::asio::buffer(data, size), handler);
804 * See the @ref buffer documentation for information on reading into multiple
805 * buffers in one go, and how to use it with arrays, boost::array or
808 template <typename MutableBufferSequence,
809 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
810 std::size_t)) ReadHandler
811 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
812 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
813 void (boost::system::error_code, std::size_t))
814 async_read_some(const MutableBufferSequence& buffers,
815 BOOST_ASIO_MOVE_ARG(ReadHandler) handler
816 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
818 return async_initiate<ReadHandler,
819 void (boost::system::error_code, std::size_t)>(
820 initiate_async_read_some(this), handler, buffers);
824 // Disallow copying and assignment.
825 basic_serial_port(const basic_serial_port&) BOOST_ASIO_DELETED;
826 basic_serial_port& operator=(const basic_serial_port&) BOOST_ASIO_DELETED;
828 class initiate_async_write_some
831 typedef Executor executor_type;
833 explicit initiate_async_write_some(basic_serial_port* self)
838 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
840 return self_->get_executor();
843 template <typename WriteHandler, typename ConstBufferSequence>
844 void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
845 const ConstBufferSequence& buffers) const
847 // If you get an error on the following line it means that your handler
848 // does not meet the documented type requirements for a WriteHandler.
849 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
851 detail::non_const_lvalue<WriteHandler> handler2(handler);
852 self_->impl_.get_service().async_write_some(
853 self_->impl_.get_implementation(), buffers, handler2.value,
854 self_->impl_.get_implementation_executor());
858 basic_serial_port* self_;
861 class initiate_async_read_some
864 typedef Executor executor_type;
866 explicit initiate_async_read_some(basic_serial_port* self)
871 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
873 return self_->get_executor();
876 template <typename ReadHandler, typename MutableBufferSequence>
877 void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
878 const MutableBufferSequence& buffers) const
880 // If you get an error on the following line it means that your handler
881 // does not meet the documented type requirements for a ReadHandler.
882 BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
884 detail::non_const_lvalue<ReadHandler> handler2(handler);
885 self_->impl_.get_service().async_read_some(
886 self_->impl_.get_implementation(), buffers, handler2.value,
887 self_->impl_.get_implementation_executor());
891 basic_serial_port* self_;
894 #if defined(BOOST_ASIO_HAS_IOCP)
895 detail::io_object_impl<detail::win_iocp_serial_port_service, Executor> impl_;
897 detail::io_object_impl<detail::reactive_serial_port_service, Executor> impl_;
904 #include <boost/asio/detail/pop_options.hpp>
906 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
907 // || defined(GENERATING_DOCUMENTATION)
909 #endif // BOOST_ASIO_BASIC_SERIAL_PORT_HPP