From: Sachin Agrawal Date: Fri, 12 Dec 2014 17:17:24 +0000 (-0800) Subject: Added code to send close_notify alert when OC stack shuts down. X-Git-Tag: 1.2.0+RC1~2048^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=563349fe03e528b94ca9c96bff4c425d2753ee12;p=platform%2Fupstream%2Fiotivity.git Added code to send close_notify alert when OC stack shuts down. When peers receive close_notify alert they clean up the DTLS session state. Change-Id: I56efabc3d73a428406cd0c1d5796f762d57f5089 Signed-off-by: Sachin Agrawal --- diff --git a/resource/csdk/libcoap-4.1.1/sec/netdtls.c b/resource/csdk/libcoap-4.1.1/sec/netdtls.c index 1535670..e90e64b 100644 --- a/resource/csdk/libcoap-4.1.1/sec/netdtls.c +++ b/resource/csdk/libcoap-4.1.1/sec/netdtls.c @@ -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; }