summaryrefslogtreecommitdiffstats
path: root/sbin/hastd/proto.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-04-29 15:36:32 +0000
committerpjd <pjd@FreeBSD.org>2010-04-29 15:36:32 +0000
commit0dcf2ac7ada163fca882dcaa5c89ddfcef286bf9 (patch)
tree8e157b7fbed074af6570c80464a3a00cc302ae60 /sbin/hastd/proto.c
parent37a9ab0c6732ace50747a5e47b4eae9c67b72bba (diff)
downloadFreeBSD-src-0dcf2ac7ada163fca882dcaa5c89ddfcef286bf9.zip
FreeBSD-src-0dcf2ac7ada163fca882dcaa5c89ddfcef286bf9.tar.gz
Fix a problem where hastd will stuck in recv(2) after sending request to
secondary, which died between send(2) and recv(2). Do it by adding timeout to recv(2) for primary incoming and outgoing sockets and secondary outgoing socket. Reported by: Mikolaj Golub <to.my.trociny@gmail.com> Tested by: Mikolaj Golub <to.my.trociny@gmail.com> MFC after: 3 days
Diffstat (limited to 'sbin/hastd/proto.c')
-rw-r--r--sbin/hastd/proto.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sbin/hastd/proto.c b/sbin/hastd/proto.c
index 103f20c..531e7e5 100644
--- a/sbin/hastd/proto.c
+++ b/sbin/hastd/proto.c
@@ -30,7 +30,9 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
#include <sys/queue.h>
+#include <sys/socket.h>
#include <assert.h>
#include <errno.h>
@@ -247,6 +249,30 @@ proto_remote_address(const struct proto_conn *conn, char *addr, size_t size)
conn->pc_proto->hp_remote_address(conn->pc_ctx, addr, size);
}
+int
+proto_timeout(const struct proto_conn *conn, int timeout)
+{
+ struct timeval tv;
+ int fd;
+
+ assert(conn != NULL);
+ assert(conn->pc_magic == PROTO_CONN_MAGIC);
+ assert(conn->pc_proto != NULL);
+
+ fd = proto_descriptor(conn);
+ if (fd < 0)
+ return (-1);
+
+ tv.tv_sec = timeout;
+ tv.tv_usec = 0;
+ if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0)
+ return (-1);
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
+ return (-1);
+
+ return (0);
+}
+
void
proto_close(struct proto_conn *conn)
{
OpenPOWER on IntegriCloud