init / exit function ordering
[vpp.git] / src / vlibmemory / socket_api.c
index a8a45a7..31c1ff9 100644 (file)
@@ -591,7 +591,7 @@ vl_api_sock_init_shm_t_handler (vl_api_sock_init_shm_t * mp)
   clib_file_t *cf;
   vl_api_shm_elem_config_t *config = 0;
   vl_shmem_hdr_t *shmem_hdr;
-  int rv;
+  int rv, tries = 1000;
 
   regp = vl_api_client_index_to_registration (mp->client_index);
   if (regp == 0)
@@ -671,6 +671,22 @@ reply:
 
   /* Send the magic "here's your sign (aka fd)" socket message */
   cf = vl_api_registration_file (regp);
+
+  /* Wait for reply to be consumed before sending the fd */
+  while (tries-- > 0)
+    {
+      int bytes;
+      rv = ioctl (cf->file_descriptor, TIOCOUTQ, &bytes);
+      if (rv < 0)
+       {
+         clib_unix_warning ("ioctl returned");
+         break;
+       }
+      if (bytes == 0)
+       break;
+      usleep (1e3);
+    }
+
   vl_sock_api_send_fd_msg (cf->file_descriptor, &memfd->fd, 1);
 }
 
@@ -789,14 +805,11 @@ socksvr_config (vlib_main_t * vm, unformat_input_t * input)
 
 VLIB_CONFIG_FUNCTION (socksvr_config, "socksvr");
 
-clib_error_t *
-vlibsocket_init (vlib_main_t * vm)
+void
+vlibsocket_reference ()
 {
-  return 0;
 }
 
-VLIB_INIT_FUNCTION (vlibsocket_init);
-
 /*
  * fd.io coding-style-patch-verification: ON
  *