tcp_transport: Fix error propogation

- Made tcp_transport_errors codes public to indicate
  TCP connection issues not covered in socket's errno
- Added API to translate tcp_transport_error codes
  to esp_err_t codes for TCP Transport

Co-authored-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
This commit is contained in:
Laukik Hase
2022-03-07 10:59:54 +05:30
parent 01d014c42d
commit cc7c67ad4e
5 changed files with 105 additions and 36 deletions
@@ -37,6 +37,22 @@ typedef esp_transport_handle_t (*payload_transfer_func)(esp_transport_handle_t);
typedef struct esp_tls_last_error* esp_tls_error_handle_t;
/**
* @brief Error types for TCP connection issues not covered in socket's errno
*/
enum esp_tcp_transport_err_t {
ERR_TCP_TRANSPORT_NO_MEM = -3,
ERR_TCP_TRANSPORT_CONNECTION_FAILED = -2,
ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN = -1,
ERR_TCP_TRANSPORT_CONNECTION_TIMEOUT = 0,
};
#define ESP_ERR_TCP_TRANSPORT_BASE (0xe000) /*!< Starting number of TCP Transport error codes */
#define ESP_ERR_TCP_TRANSPORT_CONNECTION_TIMEOUT (ESP_ERR_TCP_TRANSPORT_BASE + 1) /*!< Connection has timed out */
#define ESP_ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN (ESP_ERR_TCP_TRANSPORT_BASE + 2) /*!< Read FIN from peer and the connection has closed (in a clean way) */
#define ESP_ERR_TCP_TRANSPORT_CONNECTION_FAILED (ESP_ERR_TCP_TRANSPORT_BASE + 3) /*!< Failed to connect to the peer */
#define ESP_ERR_TCP_TRANSPORT_NO_MEM (ESP_ERR_TCP_TRANSPORT_BASE + 4) /*!< Memory allocation failed */
/**
* @brief Create transport list
*
@@ -169,7 +185,11 @@ int esp_transport_connect_async(esp_transport_handle_t t, const char *host, int
*
* @return
* - Number of bytes was read
* - (-1) if there are any errors, should check errno
* - 0 Read timed-out
* - (<0) For other errors
*
* @note: Please refer to the enum `esp_tcp_transport_err_t` for all the possible return values
*
*/
int esp_transport_read(esp_transport_handle_t t, char *buffer, int len, int timeout_ms);
@@ -334,6 +354,15 @@ esp_tls_error_handle_t esp_transport_get_error_handle(esp_transport_handle_t t);
*/
int esp_transport_get_errno(esp_transport_handle_t t);
/**
* @brief Translates the TCP transport error codes to esp_err_t error codes
*
* @param[in] error TCP Transport specific error code
*
* @return Corresponding esp_err_t based error code
*/
esp_err_t esp_transport_translate_error(enum esp_tcp_transport_err_t error);
#ifdef __cplusplus
}
#endif