aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge@cisco.com>2019-10-30 17:56:08 +0100
committerJordan Augé <jordan.auge@cisco.com>2019-10-31 13:41:47 +0100
commit95170bf3a69597b49238bb7ff396d41f6dc94f30 (patch)
tree2f9b565e84514d7ee25cfd874235dd25e9300a0f /ctrl/libhicnctrl
parentfc6dfe9f7ee02834ae1e6f56e0aaee36ac3e88dd (diff)
[HICN-369] Implement reconciliation state machine in face manager incl. reattempts in case of errors
Change-Id: Ia4ecf621fbd513d9e29313d2aaa487aa65811183 Signed-off-by: Jordan Augé <jordan.auge@cisco.com>
Diffstat (limited to 'ctrl/libhicnctrl')
-rw-r--r--ctrl/libhicnctrl/src/api.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c
index 0e5b529c5..783245e8a 100644
--- a/ctrl/libhicnctrl/src/api.c
+++ b/ctrl/libhicnctrl/src/api.c
@@ -325,7 +325,7 @@ hc_data_create(size_t in_element_size, size_t out_element_size)
return data;
ERR_BUFFER:
- free(data);
+ hc_data_free(data);
ERR_MALLOC:
return NULL;
}
@@ -645,12 +645,9 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
}
s->remaining = msg->hdr.length;
if (s->remaining == 0) {
- if (data) {
- *data = request->data;
-// } else {
-// free(request->data);
- }
hc_data_set_complete(request->data);
+ if (data)
+ *data = request->data;
hc_sock_request_free(request);
} else {
/* We only remember it if there is still data to parse */
@@ -696,12 +693,9 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
ERROR("[hc_sock_process] Error removing request from map");
return -1;
}
- if (data) {
- *data = s->cur_request->data;
-// } else {
-// free(s->cur_request->data);
- }
hc_data_set_complete(s->cur_request->data);
+ if (data)
+ *data = s->cur_request->data;
hc_sock_request_free(s->cur_request);
s->cur_request = NULL;
}
@@ -724,9 +718,9 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
}
int
-hc_sock_callback(hc_sock_t * s, hc_data_t ** data)
+hc_sock_callback(hc_sock_t * s, hc_data_t ** pdata)
{
- *data = NULL;
+ hc_data_t * data;
for (;;) {
int n = hc_sock_recv(s);
@@ -739,22 +733,28 @@ hc_sock_callback(hc_sock_t * s, hc_data_t ** data)
case ENODEV:
/* Forwarder restarted */
WARN("Forwarder likely restarted: not (yet) implemented");
- goto ERR_EOF;
+ goto ERR;
case EWOULDBLOCK:
//DEBUG("Would block... stop reading from socket");
goto END;
default:
perror("hc_sock_recv");
- goto ERR_EOF;
+ goto ERR;
}
}
- if (hc_sock_process(s, data) < 0) {
- return -1;
+ if (hc_sock_process(s, &data) < 0) {
+ goto ERR;
}
}
END:
+ if (pdata)
+ *pdata = data;
+ else
+ hc_data_free(data);
return 0;
+ERR:
+ hc_data_free(data);
ERR_EOF:
return -1;
}
@@ -865,6 +865,9 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len,
}
}
+ if (!pdata)
+ hc_data_free(data);
+
return 0;
ERR_PROCESS:
@@ -872,7 +875,7 @@ ERR_MAP:
hc_sock_request_free(request);
ERR_REQUEST:
ERR_SEQ:
- free(data);
+ hc_data_free(data);
ERR_DATA:
return -1;
}