Skip to content

Commit

Permalink
feat: add empty message type to monitor for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth committed Nov 28, 2024
1 parent 8e48c9d commit 9b9cb31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/atclient/include/atclient/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ 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
ATCLIENT_MONITOR_ERROR_READ, // could be a read timeout or some other error, indicates the caller to access
// `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
Expand Down
5 changes: 4 additions & 1 deletion packages/atclient/src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b9cb31

Please sign in to comment.