From 9b9cb315a8af08a19e9679c9dad98572536f2ee4 Mon Sep 17 00:00:00 2001 From: xavierchanth Date: Thu, 28 Nov 2024 11:35:34 -0500 Subject: [PATCH] feat: add empty message type to monitor for timeouts --- packages/atclient/include/atclient/monitor.h | 2 ++ packages/atclient/src/monitor.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/atclient/include/atclient/monitor.h b/packages/atclient/include/atclient/monitor.h index 8ca8f4ed..57f161f2 100644 --- a/packages/atclient/include/atclient/monitor.h +++ b/packages/atclient/include/atclient/monitor.h @@ -19,6 +19,7 @@ enum atclient_monitor_response_type { ATCLIENT_MONITOR_MESSAGE_TYPE_NOTIFICATION, // indicates caller to access `notification` from the union ATCLIENT_MONITOR_MESSAGE_TYPE_DATA_RESPONSE, // indicates caller to access `data_response` from the union ATCLIENT_MONITOR_MESSAGE_TYPE_ERROR_RESPONSE, // indicates caller to access `error_response` from the union + ATCLIENT_MONITOR_MESSAGE_TYPE_EMPTY, // indicates that no message was received // the following 3 enums help indicate what type of error occurred when reading from the monitor connection, you will // expect one of these enums along with a non-zero return value from atclient_monitor_read @@ -26,6 +27,7 @@ enum atclient_monitor_response_type { // `error_read` from the union ATCLIENT_MONITOR_ERROR_PARSE_NOTIFICATION, ATCLIENT_MONITOR_ERROR_DECRYPT_NOTIFICATION, + }; // Represents error information when `ATCLIENT_MONITOR_ERROR_READ` is the message type given by atclient_monitor_read diff --git a/packages/atclient/src/monitor.c b/packages/atclient/src/monitor.c index e8508fcd..55402cf3 100644 --- a/packages/atclient/src/monitor.c +++ b/packages/atclient/src/monitor.c @@ -152,7 +152,10 @@ int atclient_monitor_read(atclient *monitor_conn, atclient *atclient, atclient_m case MBEDTLS_ERR_SSL_WANT_WRITE: // handshake incomplete usleep(10000); // Try again in 10 milliseconds break; - + // Timeout means nothing to read, return EMPTY message type + case MBEDTLS_ERR_SSL_TIMEOUT: + message->type = ATCLIENT_MONITOR_MESSAGE_TYPE_EMPTY; + return 0; // Monitor connection bad, must be discarded case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY: // transport closed with close notify case 0: // transport closed without close notify