aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <bburwell1@gmail.com>2013-05-01 19:25:32 -0400
committerBen Burwell <bburwell1@gmail.com>2013-05-01 19:25:32 -0400
commitda465168cadb79dc29fa086651cdd4d7e4ab9cbf (patch)
treeb7c4265ddd69a3f90c46cc5f5cac4ce0508803e7
parentebfcf94471a78dd48d6a5a63c0d40da3a67c2486 (diff)
Request timeout recognized by receiver
-rw-r--r--chat_acceptor.h3
-rw-r--r--localchat.c2
-rw-r--r--user_command.h20
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;