aboutsummaryrefslogtreecommitdiff
path: root/protocol.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-24 00:11:53 +0000
committersotech117 <michael_foiani@brown.edu>2023-09-24 00:11:53 +0000
commit72e7559c68c78345c0d59d1207f40b569bfbd3b9 (patch)
tree40fde6572564e6720c89bc77e87702331a42edf3 /protocol.c
parent759b0550996b251d1bf4ae64a6a6f5c2059d2479 (diff)
pass all control tests!
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