summaryrefslogtreecommitdiff
path: root/src/lib/sockets.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-08-22 09:54:45 +0200
committerdimitri staessens <[email protected]>2017-08-22 09:56:08 +0200
commite539f82d2af8aac684ead174e22c04897e0f85c0 (patch)
tree8183f8f00f55f3af23c6d135b37984bcc4e2e28c /src/lib/sockets.c
parent198b70909a337698520455a063e46b1fa6c12aa0 (diff)
downloadouroboros-e539f82d2af8aac684ead174e22c04897e0f85c0.tar.gz
ouroboros-e539f82d2af8aac684ead174e22c04897e0f85c0.zip
lib, irmd: Use static buffer for messages
Diffstat (limited to 'src/lib/sockets.c')
-rw-r--r--src/lib/sockets.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 263d2356..9f1b326e 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -95,40 +95,32 @@ static void close_ptr(void * o)
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;
+ int sockfd;
+ uint8_t buf[IRM_MSG_BUF_SIZE];
+ ssize_t len;
+ irm_msg_t * recv_msg;
sockfd = client_socket_open(IRM_SOCK_PATH);
if (sockfd < 0)
return NULL;
- buf.len = irm_msg__get_packed_size(msg);
- if (buf.len == 0) {
- close(sockfd);
- return NULL;
- }
-
- buf.data = malloc(IRM_MSG_BUF_SIZE);
- if (buf.data == NULL) {
+ len = irm_msg__get_packed_size(msg);
+ if (len == 0) {
close(sockfd);
return NULL;
}
pthread_cleanup_push(close_ptr, &sockfd);
- pthread_cleanup_push((void (*)(void *)) free, (void *) buf.data);
- irm_msg__pack(msg, buf.data);
+ irm_msg__pack(msg, buf);
- if (write(sockfd, buf.data, buf.len) != -1)
- count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE);
+ if (write(sockfd, buf, len) != -1)
+ len = read(sockfd, buf, IRM_MSG_BUF_SIZE);
- if (count > 0)
- recv_msg = irm_msg__unpack(NULL, count, buf.data);
+ if (len > 0)
+ recv_msg = irm_msg__unpack(NULL, len, buf);
pthread_cleanup_pop(true);
- pthread_cleanup_pop(true);
return recv_msg;
}