]> granicus.if.org Git - esp-idf/commitdiff
tcp_transport: transport set handle refactoring, web socket client name updated
authorDavid Cermak <cermak@espressif.com>
Tue, 2 Oct 2018 13:19:46 +0000 (15:19 +0200)
committerDavid Cermak <cermak@espressif.com>
Tue, 2 Oct 2018 13:19:46 +0000 (15:19 +0200)
components/mqtt/esp-mqtt
components/tcp_transport/include/esp_transport.h
components/tcp_transport/transport.c
components/tcp_transport/transport_ssl.c
components/tcp_transport/transport_tcp.c
components/tcp_transport/transport_ws.c

index fe3ac2af1b708f44e710f35c4731584a3f69acd5..85ee406d03fd84f5613c6dead1ea653e384b9559 160000 (submodule)
@@ -1 +1 @@
-Subproject commit fe3ac2af1b708f44e710f35c4731584a3f69acd5
+Subproject commit 85ee406d03fd84f5613c6dead1ea653e384b9559
index 1f8e07809a2c742b69e4638abd3987cd5c81c56d..e163a010cd990721637f6c9c214e55904cd6af9e 100644 (file)
@@ -260,7 +260,6 @@ esp_err_t esp_transport_set_context_data(esp_transport_handle_t t, void *data);
  * @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
@@ -272,8 +271,7 @@ esp_err_t esp_transport_set_func(esp_transport_handle_t t,
                              trans_func _close,
                              poll_func _poll_read,
                              poll_func _poll_write,
-                             trans_func _destroy,
-                             payload_transfer_func _parrent_transport);
+                             trans_func _destroy);
 
 
 /**
@@ -288,6 +286,18 @@ esp_err_t esp_transport_set_func(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);
 
+/**
+ * @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
index c6f9d0ca80c3a6e7792fa29936f3b481468589ba..5c2f913fe96a052482e2775b61f87b2606e99937 100644 (file)
@@ -41,7 +41,7 @@ struct esp_transport_item_t {
     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;
 };
@@ -52,6 +52,13 @@ struct esp_transport_item_t {
  */
 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()
 {
@@ -123,7 +130,7 @@ esp_transport_handle_t esp_transport_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;
 }
@@ -219,8 +226,7 @@ esp_err_t esp_transport_set_func(esp_transport_handle_t t,
                              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;
@@ -233,7 +239,7 @@ esp_err_t esp_transport_set_func(esp_transport_handle_t t,
     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;
 }
 
@@ -254,16 +260,20 @@ esp_err_t esp_transport_set_default_port(esp_transport_handle_t t, int port)
     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;
 }
index 9034fd4e7059d080a4f1e2d972aefa6846718ec2..08afe3c19a53d29a6cfea9032146bd076938d1aa 100644 (file)
@@ -43,8 +43,6 @@ typedef struct {
     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)
@@ -176,7 +174,7 @@ esp_transport_handle_t esp_transport_ssl_init()
     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;
 }
index 3939e98214bb24b2f996dc5af02d6b2ae27ca82b..ff6925b2d160f320a9acbcbbcfda67723eee09ff 100644 (file)
@@ -32,8 +32,6 @@ typedef struct {
     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;
@@ -161,7 +159,7 @@ esp_transport_handle_t esp_transport_tcp_init()
     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;
index 28de6c5bee63c590d2c4d36d5e7b8404632d2449..b453a3e553abe3ff042043d1d512db4abf8b612f 100644 (file)
@@ -99,7 +99,7 @@ static int ws_connect(esp_transport_handle_t t, const char *host, int port, int
                          "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);
@@ -283,7 +283,10 @@ esp_transport_handle_t esp_transport_ws_init(esp_transport_handle_t parent_handl
         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;
 }