API: Use string type instead of u8.
[vpp.git] / src / vcl / ldp.c
index 5c70643..c3dc64a 100644 (file)
@@ -258,9 +258,12 @@ ldp_init (void)
   rv = vppcom_app_create (ldp_get_app_name ());
   if (rv != VPPCOM_OK)
     {
-      fprintf (stderr, "\nLDP<%d>: ERROR: ldp_init: vppcom_app_create()"
-              " failed!  rv = %d (%s)\n",
-              getpid (), rv, vppcom_retval_str (rv));
+      ldp->vcl_needs_real_epoll = 0;
+      if (rv == VPPCOM_EEXIST)
+       return 0;
+      LDBG (2, "\nLDP<%d>: ERROR: ldp_init: vppcom_app_create()"
+           " failed!  rv = %d (%s)\n",
+           getpid (), rv, vppcom_retval_str (rv));
       ldp->init = 0;
       return rv;
     }
@@ -346,7 +349,7 @@ ldp_init (void)
 int
 close (int fd)
 {
-  int rv;
+  int rv, refcnt;
   const char *func_str;
   u32 sid = ldp_sid_from_fd (fd);
 
@@ -388,13 +391,15 @@ close (int fd)
       LDBG (0, "LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x)",
            getpid (), fd, fd, func_str, sid, sid);
 
+      refcnt = vppcom_session_attr (sid, VPPCOM_ATTR_GET_REFCNT, 0, 0);
       rv = vppcom_session_close (sid);
       if (rv != VPPCOM_OK)
        {
          errno = -rv;
          rv = -1;
        }
-      ldp_fd_free_w_sid (sid);
+      if (refcnt == 1)
+       ldp_fd_free_w_sid (sid);
     }
   else
     {
@@ -3554,10 +3559,7 @@ ldp_destructor (void)
 {
   swrap_destructor ();
   if (ldp->init)
-    {
-      vppcom_app_destroy ();
-      ldp->init = 0;
-    }
+    ldp->init = 0;
 
   /* Don't use clib_warning() here because that calls writev()
    * which will call ldp_init().