Commit 1b2fdc0d authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

[serial] Improve logging of errors on Windows

This change captures a few cases where SYSTEM_ERROR could be returned
without a more detailed error being printed for debugging purposes.

Bug: 1070798
Change-Id: I9450d1f89b87483f5e7442736752d4b199f62161
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2220743
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773052}
parent 89031e66
...@@ -371,9 +371,13 @@ void SerialIoHandlerWin::OnIOCompleted( ...@@ -371,9 +371,13 @@ void SerialIoHandlerWin::OnIOCompleted(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (context == comm_context_.get()) { if (context == comm_context_.get()) {
DWORD errors; DWORD errors;
COMSTAT status; if (!ClearCommError(file().GetPlatformFile(), &errors, nullptr)) {
if (!ClearCommError(file().GetPlatformFile(), &errors, &status) || VPLOG(1) << "Failed to clear communication error";
errors != 0) { ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
return;
}
if (errors != 0) {
if (errors & CE_BREAK) { if (errors & CE_BREAK) {
ReadCompleted(0, mojom::SerialReceiveError::BREAK); ReadCompleted(0, mojom::SerialReceiveError::BREAK);
} else if (errors & CE_FRAME) { } else if (errors & CE_FRAME) {
...@@ -385,7 +389,8 @@ void SerialIoHandlerWin::OnIOCompleted( ...@@ -385,7 +389,8 @@ void SerialIoHandlerWin::OnIOCompleted(
} else if (errors & CE_RXPARITY) { } else if (errors & CE_RXPARITY) {
ReadCompleted(0, mojom::SerialReceiveError::PARITY_ERROR); ReadCompleted(0, mojom::SerialReceiveError::PARITY_ERROR);
} else { } else {
ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR); NOTIMPLEMENTED() << "Unexpected communication error: " << std::hex
<< errors;
} }
return; return;
} }
...@@ -393,6 +398,8 @@ void SerialIoHandlerWin::OnIOCompleted( ...@@ -393,6 +398,8 @@ void SerialIoHandlerWin::OnIOCompleted(
if (read_canceled()) { if (read_canceled()) {
ReadCompleted(bytes_transferred, read_cancel_reason()); ReadCompleted(bytes_transferred, read_cancel_reason());
} else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) { } else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) {
VLOG(1) << "Waiting for communcations event failed: "
<< logging::SystemErrorCodeToString(error);
ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR); ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
} else if (pending_read_buffer()) { } else if (pending_read_buffer()) {
BOOL ok = ::ReadFile(file().GetPlatformFile(), pending_read_buffer(), BOOL ok = ::ReadFile(file().GetPlatformFile(), pending_read_buffer(),
...@@ -406,19 +413,20 @@ void SerialIoHandlerWin::OnIOCompleted( ...@@ -406,19 +413,20 @@ void SerialIoHandlerWin::OnIOCompleted(
} else if (context == read_context_.get()) { } else if (context == read_context_.get()) {
if (read_canceled()) { if (read_canceled()) {
ReadCompleted(bytes_transferred, read_cancel_reason()); ReadCompleted(bytes_transferred, read_cancel_reason());
} else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) { } else if (error == ERROR_SUCCESS || error == ERROR_OPERATION_ABORTED) {
ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR); ReadCompleted(bytes_transferred, mojom::SerialReceiveError::NONE);
} else { } else {
ReadCompleted(bytes_transferred, VLOG(1) << "Read failed: " << logging::SystemErrorCodeToString(error);
error == ERROR_SUCCESS ReadCompleted(0, mojom::SerialReceiveError::SYSTEM_ERROR);
? mojom::SerialReceiveError::NONE
: mojom::SerialReceiveError::SYSTEM_ERROR);
} }
} else if (context == write_context_.get()) { } else if (context == write_context_.get()) {
DCHECK(pending_write_buffer()); DCHECK(pending_write_buffer());
if (write_canceled()) { if (write_canceled()) {
WriteCompleted(0, write_cancel_reason()); WriteCompleted(0, write_cancel_reason());
} else if (error != ERROR_SUCCESS && error != ERROR_OPERATION_ABORTED) { } else if (error == ERROR_SUCCESS || error == ERROR_OPERATION_ABORTED) {
WriteCompleted(bytes_transferred, mojom::SerialSendError::NONE);
} else {
VLOG(1) << "Write failed: " << logging::SystemErrorCodeToString(error);
WriteCompleted(0, mojom::SerialSendError::SYSTEM_ERROR); WriteCompleted(0, mojom::SerialSendError::SYSTEM_ERROR);
if (error == ERROR_GEN_FAILURE && IsReadPending()) { if (error == ERROR_GEN_FAILURE && IsReadPending()) {
// For devices using drivers such as FTDI, CP2xxx, when device is // For devices using drivers such as FTDI, CP2xxx, when device is
...@@ -432,11 +440,6 @@ void SerialIoHandlerWin::OnIOCompleted( ...@@ -432,11 +440,6 @@ void SerialIoHandlerWin::OnIOCompleted(
// disconnection. // disconnection.
CancelRead(mojom::SerialReceiveError::SYSTEM_ERROR); CancelRead(mojom::SerialReceiveError::SYSTEM_ERROR);
} }
} else {
WriteCompleted(bytes_transferred,
error == ERROR_SUCCESS
? mojom::SerialSendError::NONE
: mojom::SerialSendError::SYSTEM_ERROR);
} }
} else { } else {
NOTREACHED() << "Invalid IOContext"; NOTREACHED() << "Invalid IOContext";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment