@@ -31,6 +31,17 @@ static uint32_t session_id = PROTOCOMM_NO_SESSION_ID;
31
31
32
32
#define MAX_REQ_BODY_LEN 4096
33
33
34
+ static void protocomm_httpd_session_close (void * ctx )
35
+ {
36
+ if (pc_httpd -> sec && pc_httpd -> sec -> close_transport_session ) {
37
+ ESP_LOGW (TAG , "Closing session as socket %d was closed" , session_id );
38
+ if (pc_httpd -> sec -> close_transport_session ((protocomm_security_handle_t )ctx , session_id ) != ESP_OK ) {
39
+ ESP_LOGW (TAG , "Error closing session with ID: %d" , session_id );
40
+ }
41
+ }
42
+ session_id = PROTOCOMM_NO_SESSION_ID ;
43
+ }
44
+
34
45
static esp_err_t common_post_handler (httpd_req_t * req )
35
46
{
36
47
esp_err_t ret ;
@@ -42,6 +53,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
42
53
int cur_session_id = httpd_req_to_sockfd (req );
43
54
44
55
if (cur_session_id != session_id ) {
56
+ ESP_LOGI (TAG , "Creating new session: %d" , cur_session_id );
45
57
/* Initialize new security session */
46
58
if (session_id != PROTOCOMM_NO_SESSION_ID ) {
47
59
ESP_LOGD (TAG , "Closing session with ID: %d" , session_id );
@@ -62,6 +74,9 @@ static esp_err_t common_post_handler(httpd_req_t *req)
62
74
ret = ESP_FAIL ;
63
75
goto out ;
64
76
}
77
+ req -> sess_ctx = pc_httpd -> sec_inst ;
78
+ req -> free_ctx = protocomm_httpd_session_close ;
79
+
65
80
}
66
81
session_id = cur_session_id ;
67
82
ESP_LOGD (TAG , "New session with ID: %d" , cur_session_id );
0 commit comments