aboutsummaryrefslogtreecommitdiffstats
path: root/examples/example6_timeoutHandler.hpp
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2016-03-02 19:33:55 +0000
committerVincent Richard <[email protected]>2016-03-02 19:33:55 +0000
commit194a797055b9c1624fe8d5fbce09f4d6822d1a90 (patch)
tree67070c88a63eef5d61ed1da37f1422cb060c85cf /examples/example6_timeoutHandler.hpp
parentAdded support for TCP Keepalive. (diff)
downloadvmime-194a797055b9c1624fe8d5fbce09f4d6822d1a90.tar.gz
vmime-194a797055b9c1624fe8d5fbce09f4d6822d1a90.zip
Asynchronous resolving.
Diffstat (limited to 'examples/example6_timeoutHandler.hpp')
-rw-r--r--examples/example6_timeoutHandler.hpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/examples/example6_timeoutHandler.hpp b/examples/example6_timeoutHandler.hpp
index 7c2eb0e2..3e188baf 100644
--- a/examples/example6_timeoutHandler.hpp
+++ b/examples/example6_timeoutHandler.hpp
@@ -1,3 +1,4 @@
+#include <ctime>
/** Time out handler.
@@ -8,19 +9,27 @@ class timeoutHandler : public vmime::net::timeoutHandler
{
public:
+ timeoutHandler()
+ : m_start(time(NULL))
+ {
+ }
+
bool isTimeOut()
{
// This is a cancellation point: return true if you want to cancel
// the current operation. If you return true, handleTimeOut() will
// be called just after this, and before actually cancelling the
// operation
- return false;
+
+ // 10 seconds timeout
+ return (time(NULL) - m_start) >= 10; // seconds
}
void resetTimeOut()
{
// Called at the beginning of an operation (eg. connecting,
// a read() or a write() on a socket...)
+ m_start = time(NULL);
}
bool handleTimeOut()
@@ -29,10 +38,14 @@ public:
// allows you to interact with the user, ie. display a prompt to
// know whether he wants to cancel the operation.
- // If you return true here, the operation will be actually cancelled.
- // If not, the time out is reset and the operation continues.
- return true;
+ // If you return false here, the operation will be actually cancelled.
+ // If true, the time out is reset and the operation continues.
+ return false;
}
+
+private:
+
+ time_t m_start;
};