aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-11-03 23:17:46 +0000
committerlloyd <[email protected]>2014-11-03 23:17:46 +0000
commitc075ac86252ffc8f6f77990943aa6cce4994b598 (patch)
tree6522638397c6b1d086c7eaa93314b69186d2a5cd
parent85e0f9510fde42905e8d4883614ca1920a914c30 (diff)
Avoid crashing if user types before handshake completes
-rw-r--r--src/cmd/tls_client.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/cmd/tls_client.cpp b/src/cmd/tls_client.cpp
index 5ab015c33..5df6e72c5 100644
--- a/src/cmd/tls_client.cpp
+++ b/src/cmd/tls_client.cpp
@@ -190,7 +190,9 @@ int tls_client_main(int argc, char* argv[])
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
- FD_SET(STDIN_FILENO, &readfds);
+
+ if(client.is_active())
+ FD_SET(STDIN_FILENO, &readfds);
struct timeval timeout = { 1, 0 };
@@ -213,10 +215,10 @@ int tls_client_main(int argc, char* argv[])
continue;
}
- //std::cout << "Socket - got " << got << " bytes\n";
client.received_data(buf, got);
}
- else if(FD_ISSET(STDIN_FILENO, &readfds))
+
+ if(FD_ISSET(STDIN_FILENO, &readfds))
{
byte buf[1024] = { 0 };
ssize_t got = read(STDIN_FILENO, buf, sizeof(buf));
@@ -253,16 +255,15 @@ int tls_client_main(int argc, char* argv[])
else
client.send(buf, got);
}
- else
+
+ if(client.timeout_check())
{
- if(client.timeout_check())
- std::cerr << "Timeout detected\n";
+ std::cout << "Timeout detected\n";
}
}
::close(sockfd);
-
- }
+ }
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << "\n";