summaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/src
diff options
context:
space:
mode:
authorAlberto Compagno <acompagn+fdio@cisco.com>2019-11-27 16:57:02 +0000
committerAlberto Compagno <acompagn+fdio@cisco.com>2019-11-28 11:53:39 +0000
commitfbd866f9abc43217f7d214907d784f75f1db6175 (patch)
tree75c664f1403cfd337c21cad7485be11c971a7f00 /ctrl/libhicnctrl/src
parentde378e3805f7be9e6185270f932e3e53beaf01c6 (diff)
[HICN-417] Creation of multiple sockets calls only one connect to vpp
vlibmemoryclient provided by vpp does not handle calling connect multiple times from the same application. Creation of multiple sockets call connect only one. Destruction of all the sockets call disconnet to vpp. Signed-off-by: Alberto Compagno <acompagn+fdio@cisco.com> Change-Id: I70f22c256f4f45640f80aae3da68541504852192
Diffstat (limited to 'ctrl/libhicnctrl/src')
-rw-r--r--ctrl/libhicnctrl/src/hicn_plugin_api.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/ctrl/libhicnctrl/src/hicn_plugin_api.c b/ctrl/libhicnctrl/src/hicn_plugin_api.c
index 7d2a4b4b4..d0f1eae10 100644
--- a/ctrl/libhicnctrl/src/hicn_plugin_api.c
+++ b/ctrl/libhicnctrl/src/hicn_plugin_api.c
@@ -51,6 +51,18 @@ DEFINE_VAPI_MSG_IDS_HICN_API_JSON
DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON
DEFINE_VAPI_MSG_IDS_IP_API_JSON
+typedef struct {
+ u32 sockets_count;
+ vapi_ctx_t g_vapi_ctx_instance;
+ bool async;
+} vapi_skc_ctx_t;
+
+vapi_skc_ctx_t vapi_skc = {
+ .sockets_count = 0,
+ .g_vapi_ctx_instance = NULL,
+ .async = false,
+};
+
/*
* Internal state associated to a pending request
*/
@@ -261,6 +273,12 @@ void hc_sock_free(hc_sock_t *s) {
if (s->url) free(s->url);
close(s->fd);
free(s);
+
+ vapi_skc.sockets_count--;
+ if (vapi_skc.sockets_count == 0) {
+ vapi_disconnect(vapi_skc.g_vapi_ctx_instance);
+ vapi_skc.g_vapi_ctx_instance = NULL;
+ }
}
int hc_sock_get_next_seq(hc_sock_t *s) {
@@ -332,20 +350,26 @@ END:
}
int hc_sock_connect(hc_sock_t *s) {
- if (s->g_vapi_ctx_instance == NULL) {
- vapi_error_e rv = vapi_ctx_alloc(&s->g_vapi_ctx_instance);
- rv = vapi_connect(s->g_vapi_ctx_instance, APP_NAME, NULL,
+ if (vapi_skc.g_vapi_ctx_instance == NULL) {
+ vapi_error_e rv = vapi_ctx_alloc(&vapi_skc.g_vapi_ctx_instance);
+ rv = vapi_connect(vapi_skc.g_vapi_ctx_instance, APP_NAME, NULL,
MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE,
s->async ? VAPI_MODE_NONBLOCKING : VAPI_MODE_BLOCKING, true);
+ vapi_skc.async = s->async;
if (rv != VAPI_OK) {
- vapi_ctx_free(s->g_vapi_ctx_instance);
+ vapi_ctx_free(vapi_skc.g_vapi_ctx_instance);
goto ERR_CONNECT;
}
printf("[hc_sock_connect] *connected %s ok", APP_NAME);
+ } else if (s->async == vapi_skc.async){
+ s->g_vapi_ctx_instance = vapi_skc.g_vapi_ctx_instance;
+ printf("[hc_sock_connect] *connected %s ok", APP_NAME);
} else {
- printf("connection %s keeping", APP_NAME);
+ printf("Unable to create %s socket", s->async ? "non blocking" : "blocking");
+ goto ERR_CONNECT;
}
+ vapi_skc.sockets_count++;
return 0;
ERR_CONNECT: