vcl: notify vpp if connected inexistent session
[vpp.git] / src / vcl / vppcom.c
index b91c3a3..207e208 100644 (file)
@@ -508,10 +508,20 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
 
   session_index = mp->context;
   session = vcl_session_get (wrk, session_index);
-  if (!session)
+  if (PREDICT_FALSE (!session))
     {
       VDBG (0, "ERROR: vpp handle 0x%llx has no session index (%u)!",
            mp->handle, session_index);
+      /* Should not happen but if it does, force vpp session cleanup */
+      vcl_session_t tmp_session = {
+       .vpp_handle = mp->handle,
+       .vpp_evt_q = 0,
+      };
+      vcl_segment_attach_session (
+       mp->segment_handle, mp->server_rx_fifo, mp->server_tx_fifo,
+       mp->vpp_event_queue_address, mp->mq_index, 0, session);
+      if (tmp_session.vpp_evt_q)
+       vcl_send_session_disconnect (wrk, &tmp_session);
       return VCL_INVALID_SESSION_INDEX;
     }
   if (mp->retval)
@@ -3089,8 +3099,22 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
       sid = s->session_index;
       session_events = s->vep.ev.events;
       add_event = 1;
-      events[*num_ev].events = EPOLLHUP | EPOLLRDHUP;
+      if (EPOLLRDHUP & session_events)
+       {
+         /* If app can distinguish between RDHUP and HUP,
+          * we make finer control */
+         events[*num_ev].events = EPOLLRDHUP;
+         if (s->flags & VCL_SESSION_F_WR_SHUTDOWN)
+           {
+             events[*num_ev].events |= EPOLLHUP;
+           }
+       }
+      else
+       {
+         events[*num_ev].events = EPOLLHUP;
+       }
       session_evt_data = s->vep.ev.data.u64;
+
       break;
     case SESSION_CTRL_EVT_RESET:
       if (!e->postponed)