+ ccs = appns_sapi_alloc_socket (app_ns);
+
+ /* Grab server socket after client is initialized */
+ scs = appns_sapi_get_socket (app_ns, handle.aah_sock_index);
+ if (!scs)
+ goto error;
+
+ err = clib_socket_accept (scs, ccs);
+ if (err)
+ {
+ clib_error_report (err);
+ goto error;
+ }
+
+ cf.read_function = sapi_sock_read_ready;
+ cf.write_function = sapi_sock_write_ready;
+ cf.error_function = sapi_sock_error;
+ cf.file_descriptor = ccs->fd;
+ /* File points to app namespace and socket */
+ handle.aah_sock_index = appns_sapi_socket_index (app_ns, ccs);
+ cf.private_data = handle.as_u64;
+ cf.description = format (0, "app sock conn fd: %d", ccs->fd);
+
+ /* Poll until we get an attach message. Socket points to file and
+ * application that owns the socket */
+ handle.aah_app_wrk_index = APP_INVALID_INDEX;
+ handle.aah_file_index = clib_file_add (&file_main, &cf);
+ ccs->private_data = handle.as_u64;
+
+ return err;
+
+error:
+ appns_sapi_free_socket (app_ns, ccs);
+ return err;
+}
+
+int
+appns_sapi_add_ns_socket (app_namespace_t * app_ns)
+{
+ char *subdir = "/app_ns_sockets/";
+ app_ns_api_handle_t *handle;
+ clib_file_t cf = { 0 };
+ struct stat file_stat;
+ clib_error_t *err;
+ clib_socket_t *cs;
+ u8 *dir = 0;
+ int rv = 0;
+
+ vec_add (dir, vlib_unix_get_runtime_dir (),
+ strlen (vlib_unix_get_runtime_dir ()));
+ vec_add (dir, (u8 *) subdir, strlen (subdir));
+
+ err = vlib_unix_recursive_mkdir ((char *) dir);
+ if (err)
+ {
+ clib_error_report (err);
+ rv = -1;
+ goto error;
+ }
+
+ app_ns->sock_name = format (0, "%v%v%c", dir, app_ns->ns_id, 0);