-Subproject commit fe3ac2af1b708f44e710f35c4731584a3f69acd5
+Subproject commit 85ee406d03fd84f5613c6dead1ea653e384b9559
* @param[in] _poll_read The poll read function pointer
* @param[in] _poll_write The poll write function pointer
* @param[in] _destroy The destroy function pointer
- * @param[in] _parrent_transport The parrent transfer getter pointer
*
* @return
* - ESP_OK
trans_func _close,
poll_func _poll_read,
poll_func _poll_write,
- trans_func _destroy,
- payload_transfer_func _parrent_transport);
+ trans_func _destroy);
/**
*/
esp_err_t esp_transport_set_async_connect_func(esp_transport_handle_t t, connect_async_func _connect_async_func);
+/**
+ * @brief Set parent transport function to the handle
+ *
+ * @param[in] t The transport handle
+ * @param[in] _parent_transport The underlying transport getter pointer
+ *
+ * @return
+ * - ESP_OK
+ * - ESP_FAIL
+ */
+esp_err_t esp_transport_set_parent_transport_func(esp_transport_handle_t t, payload_transfer_func _parent_transport);
+
#ifdef __cplusplus
}
#endif
poll_func _poll_write; /*!< Poll and write */
trans_func _destroy; /*!< Destroy and free transport */
connect_async_func _connect_async; /*!< non-blocking connect function of this transport */
- payload_transfer_func _parrent_transfer; /*!< Function returning underlying transport layer */
+ payload_transfer_func _parent_transfer; /*!< Function returning underlying transport layer */
STAILQ_ENTRY(esp_transport_item_t) next;
};
*/
STAILQ_HEAD(esp_transport_list_t, esp_transport_item_t);
+static esp_transport_handle_t esp_transport_get_default_parent(esp_transport_handle_t t)
+{
+ /*
+ * By default, the underlying transport layer handle is the handle itself
+ */
+ return t;
+}
esp_transport_list_handle_t esp_transport_list_init()
{
esp_transport_handle_t esp_transport_get_payload_transport_handle(esp_transport_handle_t t)
{
if (t && t->_read) {
- return t->_parrent_transfer(t);
+ return t->_parent_transfer(t);
}
return NULL;
}
trans_func _close,
poll_func _poll_read,
poll_func _poll_write,
- trans_func _destroy,
- payload_transfer_func _parrent_transport)
+ trans_func _destroy)
{
if (t == NULL) {
return ESP_FAIL;
t->_poll_write = _poll_write;
t->_destroy = _destroy;
t->_connect_async = NULL;
- t->_parrent_transfer = _parrent_transport;
+ t->_parent_transfer = esp_transport_get_default_parent;
return ESP_OK;
}
return ESP_OK;
}
-esp_transport_handle_t transport_get_handle(esp_transport_handle_t t)
+esp_err_t esp_transport_set_async_connect_func(esp_transport_handle_t t, connect_async_func _connect_async_func)
{
- return t;
+ if (t == NULL) {
+ return ESP_FAIL;
+ }
+ t->_connect_async = _connect_async_func;
+ return ESP_OK;
}
-esp_err_t esp_transport_set_async_connect_func(esp_transport_handle_t t, connect_async_func _connect_async_func)
+esp_err_t esp_transport_set_parent_transport_func(esp_transport_handle_t t, payload_transfer_func _parent_transport)
{
if (t == NULL) {
return ESP_FAIL;
}
- t->_connect_async = _connect_async_func;
+ t->_parent_transfer = _parent_transport;
return ESP_OK;
}
transport_ssl_conn_state_t conn_state;
} transport_ssl_t;
-esp_transport_handle_t transport_get_handle(esp_transport_handle_t t);
-
static int ssl_close(esp_transport_handle_t t);
static int ssl_connect_async(esp_transport_handle_t t, const char *host, int port, int timeout_ms)
transport_ssl_t *ssl = calloc(1, sizeof(transport_ssl_t));
ESP_TRANSPORT_MEM_CHECK(TAG, ssl, return NULL);
esp_transport_set_context_data(t, ssl);
- esp_transport_set_func(t, ssl_connect, ssl_read, ssl_write, ssl_close, ssl_poll_read, ssl_poll_write, ssl_destroy, transport_get_handle);
+ esp_transport_set_func(t, ssl_connect, ssl_read, ssl_write, ssl_close, ssl_poll_read, ssl_poll_write, ssl_destroy);
esp_transport_set_async_connect_func(t, ssl_connect_async);
return t;
}
int sock;
} transport_tcp_t;
-esp_transport_handle_t transport_get_handle(esp_transport_handle_t t);
-
static int resolve_dns(const char *host, struct sockaddr_in *ip) {
struct hostent *he;
transport_tcp_t *tcp = calloc(1, sizeof(transport_tcp_t));
ESP_TRANSPORT_MEM_CHECK(TAG, tcp, return NULL);
tcp->sock = -1;
- esp_transport_set_func(t, tcp_connect, tcp_read, tcp_write, tcp_close, tcp_poll_read, tcp_poll_write, tcp_destroy, transport_get_handle);
+ esp_transport_set_func(t, tcp_connect, tcp_read, tcp_write, tcp_close, tcp_poll_read, tcp_poll_write, tcp_destroy);
esp_transport_set_context_data(t, tcp);
return t;
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Protocol: mqtt\r\n"
"Sec-WebSocket-Key: %s\r\n"
- "User-Agent: ESP32 MQTT Client\r\n\r\n",
+ "User-Agent: ESP32 Websocket Client\r\n\r\n",
ws->path,
host, port,
client_key);
return NULL;
});
- esp_transport_set_func(t, ws_connect, ws_read, ws_write, ws_close, ws_poll_read, ws_poll_write, ws_destroy, ws_get_payload_transport_handle);
+ esp_transport_set_func(t, ws_connect, ws_read, ws_write, ws_close, ws_poll_read, ws_poll_write, ws_destroy);
+ // webocket underlying transfer is the payload transfer handle
+ esp_transport_set_parent_transport_func(t, ws_get_payload_transport_handle);
+
esp_transport_set_context_data(t, ws);
return t;
}