summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-08-22 08:06:57 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-08-22 08:06:57 +0000
commit589b91b7422d3923045c3422a5b790b26162439a (patch)
tree8183f8f00f55f3af23c6d135b37984bcc4e2e28c /src/lib
parent5b242e7207483860143d3c84438134430ac1448f (diff)
parente539f82d2af8aac684ead174e22c04897e0f85c0 (diff)
downloadouroboros-589b91b7422d3923045c3422a5b790b26162439a.tar.gz
ouroboros-589b91b7422d3923045c3422a5b790b26162439a.zip
Merged in dstaesse/ouroboros/be-connmgr (pull request #559)
ipcpd: Improve locking in connmgr
Diffstat (limited to 'src/lib')
-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;
}