From da465168cadb79dc29fa086651cdd4d7e4ab9cbf Mon Sep 17 00:00:00 2001
From: Ben Burwell <bburwell1@gmail.com>
Date: Wed, 1 May 2013 19:25:32 -0400
Subject: Request timeout recognized by receiver

---
 chat_acceptor.h |  3 +++
 localchat.c     |  2 ++
 user_command.h  | 20 +++++++++++++++++---
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/chat_acceptor.h b/chat_acceptor.h
index cb42d75..a67374b 100644
--- a/chat_acceptor.h
+++ b/chat_acceptor.h
@@ -74,6 +74,9 @@ void *chat_acceptor(void *arg) {
 		printf("\n*** CHAT REQUEST *** \n");
 		printf("Accept [y/n]? ");
 		fflush(stdout);
+
+		// update the request time
+		time(&chat_requested_time);
 		
 		respond_to_chat_request = 1;
 	}
diff --git a/localchat.c b/localchat.c
index be6b57a..d0c3a16 100644
--- a/localchat.c
+++ b/localchat.c
@@ -60,6 +60,8 @@ struct sockaddr_in  accepted_addr;
 // indicates whether needs to respond to a request
 int                 respond_to_chat_request = 0;
 
+time_t              chat_requested_time;
+
 // include functions
 #include "clean_table.h"
 #include "online.h"
diff --git a/user_command.h b/user_command.h
index 24c2f3e..2e73c90 100644
--- a/user_command.h
+++ b/user_command.h
@@ -14,10 +14,24 @@ void process_user_command() {
 		// reset the global variable
 		respond_to_chat_request = 0;
 
-		if (strcmp(command, "y\n") == 0) {
-			accept_callback_accept();
+		// first check that we haven't expired
+		time_t now;
+		time(&now);
+
+		double diff = difftime(now, chat_requested_time);
+
+		if (diff > REQUEST_TIMEOUT) {
+
+			printf("The request has timed out. \n");
+
 		} else {
-			accept_callback_decline();
+
+			if (strcmp(command, "y\n") == 0) {
+				accept_callback_accept();
+			} else {
+				accept_callback_decline();
+			}
+
 		}
 
 		return;
-- 
cgit v1.2.3