clean up the socket close logic in caipserver
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Thu, 12 May 2016 10:33:48 +0000 (19:33 +0900)
committerJon A. Cruz <jon@joncruz.org>
Tue, 17 May 2016 06:46:37 +0000 (06:46 +0000)
clean up the socket close logic in caipserver

Change-Id: I8db6137b582dc7656b3180276e3d65d7d405e480
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8117
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/src/ip_adapter/caipserver.c

index da0375f..4f5f6a5 100644 (file)
@@ -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)
     {