From 15a14d28983b0451a3fc7da5157d08e7d85b7501 Mon Sep 17 00:00:00 2001 From: Jason Gauci Date: Tue, 15 Jan 2019 16:32:34 -0800 Subject: [PATCH] Make readMessage bail if it can't read a message instead of blocking forever (#168) * Make readMessage bail if it can't read a message instead of blocking forever * Only change TerminalClient's call to readMessage --- src/base/Connection.hpp | 5 +++-- src/terminal/TerminalClient.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/base/Connection.hpp b/src/base/Connection.hpp index 7be0e12e6..44533065c 100644 --- a/src/base/Connection.hpp +++ b/src/base/Connection.hpp @@ -15,6 +15,9 @@ class Connection { virtual ~Connection(); + virtual bool read(string* buf); + virtual bool write(const string& buf); + virtual bool readMessage(string* buf); virtual void writeMessage(const string& message); @@ -63,8 +66,6 @@ class Connection { inline bool isShuttingDown() { return shuttingDown; } protected: - virtual bool read(string* buf); - virtual bool write(const string& buf); bool recover(int newSocketFd); shared_ptr socketHandler; diff --git a/src/terminal/TerminalClient.cpp b/src/terminal/TerminalClient.cpp index 9e14091bb..3635fb3cd 100644 --- a/src/terminal/TerminalClient.cpp +++ b/src/terminal/TerminalClient.cpp @@ -427,7 +427,7 @@ int main(int argc, char** argv) { while (globalClient->hasData()) { VLOG(4) << "GlobalClient has data"; string packetTypeString; - if (!globalClient->readMessage(&packetTypeString)) { + if (!globalClient->read(&packetTypeString)) { break; } if (packetTypeString.length() != 1) {