From 7d77439354463e8523c7bc7f6c561f564ac5ef51 Mon Sep 17 00:00:00 2001 From: "hyuna0213.jo" Date: Thu, 12 May 2016 19:33:48 +0900 Subject: [PATCH] clean up the socket close logic in caipserver clean up the socket close logic in caipserver Change-Id: I8db6137b582dc7656b3180276e3d65d7d405e480 Signed-off-by: hyuna0213.jo Reviewed-on: https://gerrit.iotivity.org/gerrit/8117 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- .../csdk/connectivity/src/ip_adapter/caipserver.c | 62 ++++++---------------- 1 file changed, 15 insertions(+), 47 deletions(-) diff --git a/resource/csdk/connectivity/src/ip_adapter/caipserver.c b/resource/csdk/connectivity/src/ip_adapter/caipserver.c index da0375f..4f5f6a5 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipserver.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipserver.c @@ -119,55 +119,23 @@ static CAResult_t CAReceiveMessage(int fd, CATransportFlags_t flags); flags = FLAGS; \ } -void CADeInitializeIPGlobals() -{ - if (caglobals.ip.u6.fd != -1) - { - close(caglobals.ip.u6.fd); - caglobals.ip.u6.fd = -1; - } - - if (caglobals.ip.u6s.fd != -1) - { - close(caglobals.ip.u6s.fd); - caglobals.ip.u6s.fd = -1; - } - - if (caglobals.ip.u4.fd != -1) - { - close(caglobals.ip.u4.fd); - caglobals.ip.u4.fd = -1; - } - - if (caglobals.ip.u4s.fd != -1) - { - close(caglobals.ip.u4s.fd); - caglobals.ip.u4s.fd = -1; - } - - if (caglobals.ip.m6.fd != -1) - { - close(caglobals.ip.m6.fd); - caglobals.ip.m6.fd = -1; - } - - if (caglobals.ip.m6s.fd != -1) - { - close(caglobals.ip.m6s.fd); - caglobals.ip.m6s.fd = -1; - } - - if (caglobals.ip.m4.fd != -1) - { - close(caglobals.ip.m4.fd); - caglobals.ip.m4.fd = -1; +#define CLOSE_SOCKET(TYPE) \ + if (caglobals.ip.TYPE.fd != -1) \ + { \ + close(caglobals.ip.TYPE.fd); \ + caglobals.ip.TYPE.fd = -1; \ } - if (caglobals.ip.m4s.fd != -1) - { - close(caglobals.ip.m4s.fd); - caglobals.ip.m4s.fd = -1; - } +void CADeInitializeIPGlobals() +{ + CLOSE_SOCKET(u6); + CLOSE_SOCKET(u6s); + CLOSE_SOCKET(u4); + CLOSE_SOCKET(u4s); + CLOSE_SOCKET(m6); + CLOSE_SOCKET(m6s); + CLOSE_SOCKET(m4); + CLOSE_SOCKET(m4s); if (caglobals.ip.netlinkFd != -1) { -- 2.7.4