aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/src/api.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctrl/libhicnctrl/src/api.c')
-rw-r--r--ctrl/libhicnctrl/src/api.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c
index b836ef800..5e8536480 100644
--- a/ctrl/libhicnctrl/src/api.c
+++ b/ctrl/libhicnctrl/src/api.c
@@ -26,6 +26,12 @@
#include <sys/socket.h> // socket
#include <unistd.h> // close, fcntl
#include <fcntl.h> // fcntl
+#include <sys/types.h> // getpid
+#include <unistd.h> // getpid
+#ifdef __linux__
+#include <sys/syscall.h>
+#define gettid() syscall(SYS_gettid)
+#endif /* __linux__ */
#include <hicn/ctrl/api.h>
#include <hicn/ctrl/commands.h>
@@ -435,7 +441,11 @@ hc_sock_parse_url(const char * url, struct sockaddr * sa)
/* FIXME URL parsing is currently not implemented */
assert(!url);
- srand(time(NULL));
+#ifdef __linux__
+ srand(time(NULL) ^ getpid() ^ gettid());
+#else
+ srand(time(NULL) ^ getpid());
+#endif /* __linux__ */
/*
* A temporary solution is to inspect the sa_family fields of the passed in
@@ -704,16 +714,22 @@ hc_sock_process(hc_sock_t * s, hc_data_t ** data)
} else {
int rc;
rc = hc_data_ensure_available(s->cur_request->data, num_chunks);
- if (rc < 0)
- return -99;
+ if (rc < 0) {
+ ERROR("[hc_sock_process] Error in hc_data_ensure_available");
+ return -99;
+ }
for (int i = 0; i < num_chunks; i++) {
u8 * dst = hc_data_get_next(s->cur_request->data);
- if (!dst)
- return -99;
+ if (!dst) {
+ ERROR("[hc_sock_process] Error in hc_data_get_next");
+ return -99;
+ }
rc = s->cur_request->parse(s->buf + s->roff + i * s->cur_request->data->in_element_size, dst);
- if (rc < 0)
+ if (rc < 0) {
+ ERROR("[hc_sock_process] Error in parse");
err = -99; /* FIXME we let the loop complete (?) */
+ }
s->cur_request->data->size++;
}
}
@@ -757,9 +773,8 @@ hc_sock_callback(hc_sock_t * s, hc_data_t ** pdata)
for (;;) {
int n = hc_sock_recv(s);
- if (n == 0) {
+ if (n == 0)
goto ERR_EOF;
- }
if (n < 0) {
switch(errno) {
case ECONNRESET:
@@ -858,7 +873,7 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len,
}
int seq = hc_sock_get_next_seq(s);
-
+
/* Create state used to process the request */
hc_sock_request_t * request = NULL;
request = hc_sock_request_create(seq, data, params->parse);
@@ -887,7 +902,10 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len,
* several times before success... shall we alternate between blocking
* and non-blocking mode ?
*/
- if (hc_sock_recv(s) < 0)
+ int n = hc_sock_recv(s);
+ if (n == 0)
+ goto ERR_EOF;
+ if (n < 0)
continue; //break;
int rc = hc_sock_process(s, pdata);
switch(rc) {
@@ -898,15 +916,18 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len,
break;
case -99:
ERROR("[hc_execute_command] Error processing socket results");
- goto ERR_PROCESS;
+ goto ERR;
break;
default:
ERROR("[hc_execute_command] Unexpected return value");
- goto ERR_PROCESS;
+ goto ERR;
}
}
+ERR_EOF:
ret = data->ret;
+ if (!data->complete)
+ return -1;
if (!pdata)
hc_data_free(data);
@@ -915,6 +936,7 @@ hc_execute_command(hc_sock_t * s, hc_msg_t * msg, size_t msg_len,
ERR_PROCESS:
ERR_MAP:
hc_sock_request_free(request);
+ERR:
ERR_REQUEST:
hc_data_free(data);
ERR_DATA:
@@ -1939,12 +1961,16 @@ hc_route_parse(void * in, hc_route_t * route)
{
list_routes_command * cmd = (list_routes_command *) in;
- if (!IS_VALID_ADDR_TYPE(cmd->addressType))
- return -1;
+ if (!IS_VALID_ADDR_TYPE(cmd->addressType)) {
+ ERROR("[hc_route_parse] Invalid address type");
+ return -1;
+ }
int family = map_from_addr_type[cmd->addressType];
- if (!IS_VALID_FAMILY(family))
- return -1;
+ if (!IS_VALID_FAMILY(family)) {
+ ERROR("[hc_route_parse] Invalid address family");
+ return -1;
+ }
*route = (hc_route_t) {
.face_id = cmd->connid,