aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/socket_api.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2019-05-08 19:57:24 -0700
committerDave Wallace <dwallacelf@gmail.com>2019-05-09 16:46:27 +0000
commit1f30a5993a88958a09956418e825396e516e382f (patch)
tree3f414b5e25033625a2cc6fd2ea87427848684a2b /src/vlibmemory/socket_api.c
parentb7e3dba7b1b040d42b02a173b525aba77c5b02a7 (diff)
bapi: separate init shm reply from fd exchange
Wait for init shm reply to be consumed before sending fd over the socket. Change-Id: I5cd0246d8debcc3c8a163b7e2dd400ca0050a2fb Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vlibmemory/socket_api.c')
-rw-r--r--src/vlibmemory/socket_api.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index a8a45a7e6bc..f0c7f1feeb1 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -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);
}