diff options
author | dimitri staessens <[email protected]> | 2017-08-22 09:54:45 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2017-08-22 09:56:08 +0200 |
commit | e539f82d2af8aac684ead174e22c04897e0f85c0 (patch) | |
tree | 8183f8f00f55f3af23c6d135b37984bcc4e2e28c /src/irmd/ipcp.c | |
parent | 198b70909a337698520455a063e46b1fa6c12aa0 (diff) | |
download | ouroboros-e539f82d2af8aac684ead174e22c04897e0f85c0.tar.gz ouroboros-e539f82d2af8aac684ead174e22c04897e0f85c0.zip |
lib, irmd: Use static buffer for messages
Diffstat (limited to 'src/irmd/ipcp.c')
-rw-r--r-- | src/irmd/ipcp.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index b8f11508..e1689b91 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -52,9 +52,9 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) { int sockfd = 0; - buffer_t buf; + uint8_t buf[IPCP_MSG_BUF_SIZE]; char * sock_path = NULL; - ssize_t count = 0; + ssize_t len; ipcp_msg_t * recv_msg = NULL; struct timeval tv; @@ -73,14 +73,8 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, free(sock_path); - buf.len = ipcp_msg__get_packed_size(msg); - if (buf.len == 0) { - close(sockfd); - return NULL; - } - - buf.data = malloc(IPCP_MSG_BUF_SIZE); - if (buf.data == NULL) { + len = ipcp_msg__get_packed_size(msg); + if (len == 0) { close(sockfd); return NULL; } @@ -113,18 +107,16 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, log_warn("Failed to set timeout on socket."); pthread_cleanup_push(close_ptr, (void *) &sockfd); - pthread_cleanup_push((void (*)(void *)) free, (void *) buf.data); - ipcp_msg__pack(msg, buf.data); + ipcp_msg__pack(msg, buf); - if (write(sockfd, buf.data, buf.len) != -1) - count = read(sockfd, buf.data, IPCP_MSG_BUF_SIZE); + if (write(sockfd, buf, len) != -1) + len = read(sockfd, buf, IPCP_MSG_BUF_SIZE); - if (count > 0) - recv_msg = ipcp_msg__unpack(NULL, count, buf.data); + if (len > 0) + recv_msg = ipcp_msg__unpack(NULL, len, buf); pthread_cleanup_pop(true); - pthread_cleanup_pop(true); return recv_msg; } |