vcl: add ldp implementation for recvmmsg 27/38127/5
authorFlorin Coras <fcoras@cisco.com>
Fri, 3 Feb 2023 06:56:03 +0000 (22:56 -0800)
committerDave Barach <vpp@barachs.net>
Tue, 7 Feb 2023 18:06:44 +0000 (18:06 +0000)
Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I7322abc3d3b0aa81399667bf02b03786fc62c958

src/vcl/ldp.c

index 482af3f..ade19a7 100644 (file)
@@ -1843,47 +1843,55 @@ int
 recvmmsg (int fd, struct mmsghdr *vmessages,
          unsigned int vlen, int flags, struct timespec *tmo)
 {
-  ssize_t size;
-  const char *func_str;
-  u32 sh = ldp_fd_to_vlsh (fd);
+  ldp_worker_ctx_t *ldpw = ldp_worker_get_current ();
+  u32 sh;
 
   ldp_init_check ();
 
+  sh = ldp_fd_to_vlsh (fd);
+
   if (sh != VLS_INVALID_HANDLE)
     {
-      clib_warning ("LDP<%d>: LDP-TBD", getpid ());
-      errno = ENOSYS;
-      size = -1;
-    }
-  else
-    {
-      func_str = "libc_recvmmsg";
+      struct mmsghdr *mh;
+      ssize_t rv = 0;
+      u32 nvecs = 0;
+      f64 time_out;
 
-      if (LDP_DEBUG > 2)
-       clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
-                     "vmessages %p, vlen %u, flags 0x%x, tmo %p",
-                     getpid (), fd, fd, func_str, vmessages, vlen,
-                     flags, tmo);
-
-      size = libc_recvmmsg (fd, vmessages, vlen, flags, tmo);
-    }
-
-  if (LDP_DEBUG > 2)
-    {
-      if (size < 0)
+      if (PREDICT_FALSE (ldpw->clib_time.init_cpu_time == 0))
+       clib_time_init (&ldpw->clib_time);
+      if (tmo)
        {
-         int errno_val = errno;
-         perror (func_str);
-         clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
-                       "rv %d, errno = %d", getpid (), fd, fd,
-                       func_str, size, errno_val);
-         errno = errno_val;
+         time_out = (f64) tmo->tv_sec + (f64) tmo->tv_nsec / (f64) 1e9;
+         time_out += clib_time_now (&ldpw->clib_time);
        }
       else
-       clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
-                     getpid (), fd, fd, size, size);
+       {
+         time_out = (f64) ~0;
+       }
+
+      while (nvecs < vlen)
+       {
+         mh = &vmessages[nvecs];
+         rv = recvmsg (fd, &mh->msg_hdr, flags);
+         if (rv > 0)
+           {
+             mh->msg_len = rv;
+             nvecs += 1;
+             continue;
+           }
+
+         if (!time_out || clib_time_now (&ldpw->clib_time) >= time_out)
+           break;
+
+         usleep (1);
+       }
+
+      return nvecs > 0 ? nvecs : rv;
+    }
+  else
+    {
+      return libc_recvmmsg (fd, vmessages, vlen, flags, tmo);
     }
-  return size;
 }
 #endif