Opened 13 years ago

Closed 13 years ago

#3254 closed Bugs (invalid)

Cannot cancel async_write to a serial port

Reported by: kevin.arunski@… Owned by: chris_kohlhoff
Milestone: Boost 1.40.0 Component: asio
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:

Description

Attached is a test program that demonstrates some curious behavior I see while using serial port on a Linux system (epoll reactor).

The order of operations is: create serial_port, call async_write to send some data over the port, call cancel to cancel the write operation, enter io_service.

I would expect the write completion handler to be called with the error_code argument set. Instead, no error_code is set and some bytes are transferred.

Attachments (1)

serial_test.cpp (1.1 KB ) - added by kevin.arunski@… 13 years ago.
Async write cancel test

Download all attachments as: .zip

Change History (3)

by kevin.arunski@…, 13 years ago

Attachment: serial_test.cpp added

Async write cancel test

comment:1 by kevin.arunski@…, 13 years ago

I think I've traced the problem to the speculative write code path in the reactor service. The write is sent to the file descriptor ahead of queueing a work operation. So there is no way for the cancel operation to find the pending write operation. So I would think the speculative write path would need to at least provide some mechanism for the cancel operation to find the write operation and deliver the error code to the handler.

comment:2 by chris_kohlhoff, 13 years ago

Resolution: invalid
Status: newclosed

This is expected behaviour. The async operation can complete any time from when you call async_write to when your handler runs. In this case it completes immediately, is no longer pending, and so there is nothing to cancel.

Note: See TracTickets for help on using tickets.