session: fix reentrant listens

Change-Id: I72d400401a308012b43513179870823f6f921e44
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index ae426fb..2d7126a 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -522,6 +522,7 @@
 u32
 tls_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
 {
+  vnet_bind_args_t _bargs, *args = &_bargs;
   app_worker_t *app_wrk;
   tls_main_t *tm = &tls_main;
   session_handle_t tls_handle;
@@ -529,7 +530,7 @@
   stream_session_t *tls_listener;
   stream_session_t *app_listener;
   tls_engine_type_t engine_type;
-  application_t *app, *tls_app;
+  application_t *app;
   tls_ctx_t *lctx;
   u32 lctx_index;
 
@@ -543,15 +544,15 @@
       return -1;
     }
 
-  lctx_index = tls_listener_ctx_alloc ();
-
-  /* TODO hide this by calling vnet_bind() */
-  tls_app = application_get (tm->app_index);
-//  tls_app_wrk = application_get_default_worker (tls_app);
   sep->transport_proto = TRANSPORT_PROTO_TCP;
-  if (application_start_listen (tls_app, sep, &tls_handle))
-    return ~0;
+  memset (args, 0, sizeof (*args));
+  args->app_index = tm->app_index;
+  args->sep_ext = *sep;
+  if (vnet_bind (args))
+    return -1;
 
+  tls_handle = args->handle;
+  lctx_index = tls_listener_ctx_alloc ();
   tls_listener = listen_session_get_from_handle (tls_handle);
   tls_listener->opaque = lctx_index;