summaryrefslogtreecommitdiff
path: root/src/irmd/ipcp.c
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/irmd/ipcp.c
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/irmd/ipcp.c')
-rw-r--r--src/irmd/ipcp.c26
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;
}