diff options
author | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-05 20:02:28 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@ugent.be> | 2017-04-06 10:36:24 +0200 |
commit | e1c0714d5827cd927961f3a687d9720e6e9aa802 (patch) | |
tree | d8e793cffbe829d64855eaa5a429b90ebe3dc3a4 /src/lib | |
parent | c6ad4f96f8bb2f1ee749e92308e7173523ddd0b8 (diff) | |
download | ouroboros-e1c0714d5827cd927961f3a687d9720e6e9aa802.tar.gz ouroboros-e1c0714d5827cd927961f3a687d9720e6e9aa802.zip |
lib, irmd: Implement flow allocation timeout
Setting the timeouts on flow_alloc and flow_accept will now work. This
makes some changes to the UNIX sockets used for management
communication between the APs, IRMd and IPCPs.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dev.c | 31 | ||||
-rw-r--r-- | src/lib/irm.c | 4 | ||||
-rw-r--r-- | src/lib/irmd_messages.proto | 2 | ||||
-rw-r--r-- | src/lib/sockets.c | 14 |
4 files changed, 27 insertions, 24 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index c063fd47..389ff278 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -276,7 +276,7 @@ int ap_init(const char * ap_name) shm_flow_set_destroy(ai.fqset); bmp_destroy(ai.fqueues); bmp_destroy(ai.fds); - return -1; + return -EIRMD; } ai.flows = malloc(sizeof(*ai.flows) * AP_MAX_FLOWS); @@ -393,9 +393,9 @@ int flow_accept(qosspec_t * qs, if (timeo != NULL) { msg.has_timeo_sec = true; - msg.has_timeo_usec = true; + msg.has_timeo_nsec = true; msg.timeo_sec = timeo->tv_sec; - msg.timeo_usec = timeo->tv_nsec / 1000; + msg.timeo_nsec = timeo->tv_nsec; } pthread_rwlock_rdlock(&ai.data_lock); @@ -404,15 +404,21 @@ int flow_accept(qosspec_t * qs, pthread_rwlock_unlock(&ai.data_lock); - recv_msg = send_recv_irm_msg_b(&msg); + recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -EIRMD; } + if (recv_msg->result != 0) { + int res = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + return res; + } + if (!recv_msg->has_api || !recv_msg->has_port_id) { irm_msg__free_unpacked(recv_msg, NULL); return -1; @@ -496,9 +502,9 @@ int flow_alloc(const char * dst_name, if (timeo != NULL) { msg.has_timeo_sec = true; - msg.has_timeo_usec = true; + msg.has_timeo_nsec = true; msg.timeo_sec = timeo->tv_sec; - msg.timeo_usec = timeo->tv_nsec / 1000; + msg.timeo_nsec = timeo->tv_nsec; } pthread_rwlock_rdlock(&ai.data_lock); @@ -511,6 +517,17 @@ int flow_alloc(const char * dst_name, if (recv_msg == NULL) return -EIRMD; + if (!recv_msg->has_result) { + irm_msg__free_unpacked(recv_msg, NULL); + return -EIRMD; + } + + if (recv_msg->result != 0) { + int res = recv_msg->result; + irm_msg__free_unpacked(recv_msg, NULL); + return res; + } + if (!recv_msg->has_api || !recv_msg->has_port_id) { irm_msg__free_unpacked(recv_msg, NULL); return -1; diff --git a/src/lib/irm.c b/src/lib/irm.c index 0e4bfc40..57e09369 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -177,10 +177,8 @@ ssize_t irm_list_ipcps(const char * name, msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); - if (recv_msg == NULL) { - free(msg.dif_name); + if (recv_msg == NULL) return -EIRMD; - } if (recv_msg->apis == NULL) { irm_msg__free_unpacked(recv_msg, NULL); diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index 4fbd676e..e218f6f6 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -62,6 +62,6 @@ message irm_msg { optional uint32 opts = 12; repeated sint32 apis = 13; optional uint32 timeo_sec = 14; - optional uint32 timeo_usec = 15; + optional uint32 timeo_nsec = 15; optional sint32 result = 16; }; diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 3a26a2cf..63f928cf 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -95,23 +95,17 @@ static void close_ptr(void * o) close(*(int *) o); } -static irm_msg_t * send_recv_irm_msg_timed(irm_msg_t * msg, bool timed) +irm_msg_t * send_recv_irm_msg(irm_msg_t * msg) { int sockfd; buffer_t buf; ssize_t count = 0; irm_msg_t * recv_msg = NULL; - struct timeval tv = {(SOCKET_TIMEOUT / 1000), - (SOCKET_TIMEOUT % 1000) * 1000}; sockfd = client_socket_open(IRM_SOCK_PATH); if (sockfd < 0) return NULL; - if (timed) - setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, - (void *) &tv, sizeof(tv)); - buf.len = irm_msg__get_packed_size(msg); if (buf.len == 0) { close(sockfd); @@ -141,12 +135,6 @@ static irm_msg_t * send_recv_irm_msg_timed(irm_msg_t * msg, bool timed) return recv_msg; } -irm_msg_t * send_recv_irm_msg(irm_msg_t * msg) -{ return send_recv_irm_msg_timed(msg, true); } - -irm_msg_t * send_recv_irm_msg_b(irm_msg_t * msg) -{ return send_recv_irm_msg_timed(msg, false); } - char * ipcp_sock_path(pid_t api) { char * full_name = NULL; |