aboutsummaryrefslogtreecommitdiff
path: root/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocol.c')
-rw-r--r--protocol.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/protocol.c b/protocol.c
index d350221..5c8127f 100644
--- a/protocol.c
+++ b/protocol.c
@@ -3,13 +3,13 @@
#include "protocol.h"
-#define TIMEOUT 100000 // 100ms in microseconds
+#define TCP_TIMEOUT 100000 // 100ms in microseconds
int send_all(int sock, char *buf, int *len)
{
struct timeval timeout;
timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
+ timeout.tv_usec = TCP_TIMEOUT;
// if (setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, &timeout,
// sizeof timeout) < 0)
// perror("setsockopt failed\n");
@@ -35,7 +35,7 @@ int recv_all(int sock, char *buf, int *len)
// setup the timeout on the socket
struct timeval timeout;
timeout.tv_sec = 0;
- timeout.tv_usec = TIMEOUT;
+ timeout.tv_usec = TCP_TIMEOUT;
if (setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, &timeout,
sizeof timeout) < 0)
perror("setsockopt failed\n");
@@ -64,3 +64,30 @@ int recv_all(int sock, char *buf, int *len)
return n==-1?-1:0; // return -1 on failure, 0 on success
}
+
+int apply_timeout(int fd) {
+ // handle handshake
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = TCP_TIMEOUT;
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
+ perror("setsockopt (in apply_timeout)");
+ return -1;
+ }
+
+ return 1;
+}
+
+int remove_timeout(int fd)
+{
+ // handle handshake
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
+ perror("setsockopt (in remove_timeout)");
+ return -1;
+ }
+
+ return 1;
+} \ No newline at end of file