Send close event on +LINK_CONN1,x,... and on x,CLOSED messages
@@ -556,7 +556,7 @@ espi_parse_received(esp_recv_t* rcv) {
if (!strncmp("SEND OK", rcv->data, 7)) { /* Data were sent successfully */
esp.msg->msg.conn_send.wait_send_ok_err = 0;
is_ok = espi_tcpip_process_data_sent(1); /* Process as data were sent */
- if (is_ok) {
+ if (is_ok && esp.msg->msg.conn_send.conn->status.f.active) {
CONN_SEND_DATA_FREE(esp.msg); /* Free message data */
esp.cb.type = ESP_CB_CONN_DATA_SENT; /* Data were fully sent */
esp.cb.cb.conn_data_sent.conn = esp.msg->msg.conn_send.conn;
@@ -566,7 +566,7 @@ espi_parse_received(esp_recv_t* rcv) {
} else if (is_error || !strncmp("SEND FAIL", rcv->data, 9)) {
esp.msg->msg.conn_send.wait_send_ok_err = 0;
is_error = espi_tcpip_process_data_sent(0); /* Data were not sent due to SEND FAIL or command didn't even start */
- if (is_error) {
+ if (is_error && esp.msg->msg.conn_send.conn->status.f.active) {
CONN_SEND_DATA_FREE(esp.msg); /* Free message data */
esp.cb.type = ESP_CB_CONN_DATA_SEND_ERR;/* Error sending data */
esp.cb.cb.conn_data_send_err.conn = esp.msg->msg.conn_send.conn;
@@ -600,6 +600,22 @@ espi_parse_received(esp_recv_t* rcv) {
if (espi_parse_link_conn(s) && esp.link_conn.num < ESP_CFG_MAX_CONNS) {
uint8_t id;
esp_conn_t* conn = &esp.conns[esp.link_conn.num]; /* Get connection pointer */
+ if (esp.link_conn.failed && conn->status.f.active) {/* Connection failed and now closed? */
+ conn->status.f.active = 0; /* Connection was just closed */
+
+ esp.cb.type = ESP_CB_CONN_CLOSED; /* Connection just active */
+ esp.cb.cb.conn_active_closed.conn = conn; /* Set connection */
+ esp.cb.cb.conn_active_closed.client = conn->status.f.client; /* Set if it is client or not */
+ /** @todo: Check if we really tried to close connection which was just closed */
+ esp.cb.cb.conn_active_closed.forced = IS_CURR_CMD(ESP_CMD_TCPIP_CIPCLOSE); /* Set if action was forced = current action = close connection */
+ espi_send_conn_cb(conn, NULL); /* Send event */
+
+ /* Check if write buffer is set */
+ if (conn->buff != NULL) {
+ esp_mem_free(conn->buff); /* Free the memory */
+ conn->buff = NULL;
+ }
+ } else if (!esp.link_conn.failed && !conn->status.f.active) {
id = conn->val_id;
memset(conn, 0x00, sizeof(*conn)); /* Reset connection parameters */
conn->num = esp.link_conn.num; /* Set connection number */
@@ -630,6 +646,7 @@ espi_parse_received(esp_recv_t* rcv) {
esp.cb.cb.conn_active_closed.forced = conn->status.f.client; /* Set if action was forced = if client mode */
espi_send_conn_cb(conn, NULL); /* Send event */
}
+ }
/*
} else if (!strncmp(",CLOSED", &rcv->data[1], 7)) {
const char* tmp = rcv->data; */
