Added code to send close_notify alert when OC stack shuts down.
authorSachin Agrawal <sachin.agrawal@intel.com>
Fri, 12 Dec 2014 17:17:24 +0000 (09:17 -0800)
committerSachin Agrawal <sachin.agrawal@intel.com>
Fri, 12 Dec 2014 17:17:24 +0000 (09:17 -0800)
When peers receive close_notify alert they clean up the DTLS
session state.

Change-Id: I56efabc3d73a428406cd0c1d5796f762d57f5089
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/libcoap-4.1.1/sec/netdtls.c

index 1535670..e90e64b 100644 (file)
@@ -406,7 +406,7 @@ int coap_dtls_init(coap_context_t *ctx, uint8_t ipAddr[]) {
     ret = 0;
 
 exit:
-    if (ret == -1 && coap_dtls_ctx) {
+    if (ret == -1) {
         coap_dtls_deinit(ctx);
     }
     return ret;
@@ -420,18 +420,21 @@ exit:
  *
  */
 void coap_dtls_deinit(coap_context_t *ctx) {
-    if (!ctx)
+
+    if (!ctx || !ctx->coap_dtls_ctx)
         return;
 
     coap_dtls_context_t *coap_dtls_ctx = ctx->coap_dtls_ctx;
 
-    if (coap_dtls_ctx) {
-        coap_delete_all(coap_dtls_ctx->cachedqueue);
-        if (ctx->sockfd_dtls != -1)
-            OCClose(ctx->sockfd_dtls);
-        dtls_free_context(coap_dtls_ctx->dtls_ctx);
-        coap_free(coap_dtls_ctx);
-    }
+    coap_delete_all(coap_dtls_ctx->cachedqueue);
+
+    dtls_free_context(coap_dtls_ctx->dtls_ctx);
+    coap_dtls_ctx->dtls_ctx = NULL;
+
+    if (ctx->sockfd_dtls != -1)
+        OCClose(ctx->sockfd_dtls);
+
+    coap_free(coap_dtls_ctx);
     ctx->coap_dtls_ctx = NULL;
 }