From 44b9f74301d0dca2ecb7e2a34dd3e914fd8862d3 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 7 Oct 2024 14:08:59 +0200 Subject: [PATCH 1/2] mm-port-serial: add new MM_SERIAL_ERROR_SEND_TIMEOUT This new error code 'MM_SERIAL_ERROR_SEND_TIMEOUT' is used to make it easier to distinguish why the transmission failed. Until now, 'MM_SERIAL_ERROR_SEND_FAILED' was always returned. This new error code is now returned for an 'EAGAIN', as this is more likely to be a TIMEOUT. This makes debugging easier, as a better error analysis is now possible. Signed-off-by: Florian Eckert --- include/ModemManager-errors.h | 2 ++ src/mm-error-helpers.c | 1 + src/mm-port-serial.c | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/ModemManager-errors.h b/include/ModemManager-errors.h index 572b8a00..1d397f10 100644 --- a/include/ModemManager-errors.h +++ b/include/ModemManager-errors.h @@ -521,6 +521,7 @@ typedef enum { /*< underscore_name=mm_connection_error >*/ * @MM_SERIAL_ERROR_NOT_OPEN: The serial port is not open. * @MM_SERIAL_ERROR_PARSE_FAILED: The serial port specific parsing failed. * @MM_SERIAL_ERROR_FRAME_NOT_FOUND: The serial port reported that the frame marker wasn't found (e.g. for QCDM). Since 1.6. + * @MM_SERIAL_ERROR_SEND_TIMEOUT: Could not write once again to the serial device. * * Serial errors that may be reported by ModemManager. * @@ -536,6 +537,7 @@ typedef enum { /*< underscore_name=mm_serial_error >*/ MM_SERIAL_ERROR_NOT_OPEN = 6, /*< nick=NotOpen >*/ MM_SERIAL_ERROR_PARSE_FAILED = 7, /*< nick=ParseFailed >*/ MM_SERIAL_ERROR_FRAME_NOT_FOUND = 8, /*< nick=FrameNotFound >*/ + MM_SERIAL_ERROR_SEND_TIMEOUT = 9, /*< nick=SendTimeout >*/ } MMSerialError; /** diff --git a/src/mm-error-helpers.c b/src/mm-error-helpers.c index 75598c46..6eb65d18 100644 --- a/src/mm-error-helpers.c +++ b/src/mm-error-helpers.c @@ -329,6 +329,7 @@ static const gchar *serial_error_messages[] = { [MM_SERIAL_ERROR_NOT_OPEN] = "Not open", [MM_SERIAL_ERROR_PARSE_FAILED] = "Parse failed", [MM_SERIAL_ERROR_FRAME_NOT_FOUND] = "Frame not found", + [MM_SERIAL_ERROR_SEND_TIMEOUT] = "Send timeout", }; static const gchar * diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c index d1976972..f520ff83 100644 --- a/src/mm-port-serial.c +++ b/src/mm-port-serial.c @@ -596,7 +596,7 @@ port_serial_process_command (MMPortSerial *self, self->priv->n_consecutive_timeouts++; g_signal_emit_by_name (self, MM_PORT_SIGNAL_TIMED_OUT, self->priv->n_consecutive_timeouts); - g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED, + g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_TIMEOUT, "Sending command failed: '%s'", g_strerror (errno)); return FALSE; } @@ -631,7 +631,7 @@ port_serial_process_command (MMPortSerial *self, /* If we reach the limit of EAGAIN errors, treat as a timeout error. */ self->priv->n_consecutive_timeouts++; g_signal_emit_by_name (self, MM_PORT_SIGNAL_TIMED_OUT, self->priv->n_consecutive_timeouts); - g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_FAILED, + g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_SEND_TIMEOUT, "Sending command failed: '%s'", g_strerror (errno)); return FALSE; } From 6a2cb8dd8ebf215a2d4193c2a984a79c6a488de5 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 7 Oct 2024 14:17:32 +0200 Subject: [PATCH 2/2] mm-port-probe-at: also check for MM_SERIAL_ERROR_SEND_TIMEOUT Check here for the new error 'MM_SERIAL_ERROR_SEND_TIMEOUT'. Signed-off-by: Florian Eckert --- src/mm-port-probe-at.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mm-port-probe-at.c b/src/mm-port-probe-at.c index 4505fc76..c9832b6c 100644 --- a/src/mm-port-probe-at.c +++ b/src/mm-port-probe-at.c @@ -47,7 +47,10 @@ mm_port_probe_response_processor_is_at (const gchar *command, MM_SERIAL_ERROR_RESPONSE_TIMEOUT) || g_error_matches (error, MM_SERIAL_ERROR, - MM_SERIAL_ERROR_SEND_FAILED)) { + MM_SERIAL_ERROR_SEND_FAILED) || + g_error_matches (error, + MM_SERIAL_ERROR, + MM_SERIAL_ERROR_SEND_TIMEOUT)) { return FALSE; }