summaryrefslogtreecommitdiff
path: root/src/lib/sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/sockets.c')
-rw-r--r--src/lib/sockets.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 7f0c4dd4..9f1b326e 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -20,7 +20,6 @@
* Foundation, Inc., http://www.fsf.org/about/contact/.
*/
-#include <ouroboros/config.h>
#include <ouroboros/errno.h>
#include <ouroboros/sockets.h>
#include <ouroboros/utils.h>
@@ -96,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;
}