Skip to content

Commit cefc70c

Browse files
committed
Add support for release() on serial ports
Fixes #1182
1 parent bd500f0 commit cefc70c

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

include/asio/basic_serial_port.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,37 @@ class basic_serial_port
491491
return impl_.get_service().native_handle(impl_.get_implementation());
492492
}
493493

494+
/// Release ownership of the underlying native serial port.
495+
/*
496+
* This function causes all outstanding asynchronous read operations to
497+
* finish immediately, and the handlers for cancelled operations will be
498+
* passed the asio::error::operation_aborted error. Ownership of the
499+
* native serial port is then transferred to the caller.
500+
*
501+
* @throws asio::system_error Thrown on failure.
502+
*/
503+
native_handle_type release()
504+
{
505+
asio::error_code ec;
506+
native_handle_type s = impl_.get_service().release(
507+
impl_.get_implementation(), ec);
508+
asio::detail::throw_error(ec, "release");
509+
return s;
510+
}
511+
512+
/// Release ownership of the underlying native serial port.
513+
/*
514+
* This function causes all outstanding asynchronous read operations to
515+
* finish immediately, and the handlers for cancelled operations will be
516+
* passed the asio::error::operation_aborted error. Ownership of the
517+
* native serial port is then transferred to the caller.
518+
*
519+
* @param ec Set to indicate what error occurred, if any.
520+
*/
521+
native_handle_type release(asio::error_code& ec)
522+
{
523+
return impl_.get_service().release(impl_.get_implementation(), ec);
524+
}
494525
/// Cancel all asynchronous operations associated with the serial port.
495526
/**
496527
* This function causes all outstanding asynchronous read or write operations

include/asio/detail/posix_serial_port_service.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ class posix_serial_port_service :
122122
return descriptor_service_.native_handle(impl);
123123
}
124124

125+
// Release ownership of the native serial port representation.
126+
native_handle_type release(implementation_type& impl,
127+
asio::error_code& ec)
128+
{
129+
return descriptor_service_.release(impl, ec);
130+
}
131+
125132
// Cancel all operations associated with the serial port.
126133
asio::error_code cancel(implementation_type& impl,
127134
asio::error_code& ec)

0 commit comments

Comments
 (0)