Mercurial > thymian
annotate 3rdparty/vmime/examples/example6_timeoutHandler.hpp @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
| rev | line source |
|---|---|
| ferencd@0 | 1 |
| ferencd@0 | 2 |
| ferencd@0 | 3 /** Time out handler. |
| ferencd@0 | 4 * Used to stop the current operation after too much time, or if the user |
| ferencd@0 | 5 * requested cancellation. |
| ferencd@0 | 6 */ |
| ferencd@0 | 7 class timeoutHandler : public vmime::net::timeoutHandler |
| ferencd@0 | 8 { |
| ferencd@0 | 9 public: |
| ferencd@0 | 10 |
| ferencd@0 | 11 bool isTimeOut() |
| ferencd@0 | 12 { |
| ferencd@0 | 13 // This is a cancellation point: return true if you want to cancel |
| ferencd@0 | 14 // the current operation. If you return true, handleTimeOut() will |
| ferencd@0 | 15 // be called just after this, and before actually cancelling the |
| ferencd@0 | 16 // operation |
| ferencd@0 | 17 return false; |
| ferencd@0 | 18 } |
| ferencd@0 | 19 |
| ferencd@0 | 20 void resetTimeOut() |
| ferencd@0 | 21 { |
| ferencd@0 | 22 // Called at the beginning of an operation (eg. connecting, |
| ferencd@0 | 23 // a read() or a write() on a socket...) |
| ferencd@0 | 24 } |
| ferencd@0 | 25 |
| ferencd@0 | 26 bool handleTimeOut() |
| ferencd@0 | 27 { |
| ferencd@0 | 28 // If isTimeOut() returned true, this function will be called. This |
| ferencd@0 | 29 // allows you to interact with the user, ie. display a prompt to |
| ferencd@0 | 30 // know whether he wants to cancel the operation. |
| ferencd@0 | 31 |
| ferencd@0 | 32 // If you return true here, the operation will be actually cancelled. |
| ferencd@0 | 33 // If not, the time out is reset and the operation continues. |
| ferencd@0 | 34 return true; |
| ferencd@0 | 35 } |
| ferencd@0 | 36 }; |
| ferencd@0 | 37 |
| ferencd@0 | 38 |
| ferencd@0 | 39 class timeoutHandlerFactory : public vmime::net::timeoutHandlerFactory |
| ferencd@0 | 40 { |
| ferencd@0 | 41 public: |
| ferencd@0 | 42 |
| ferencd@0 | 43 vmime::shared_ptr <vmime::net::timeoutHandler> create() |
| ferencd@0 | 44 { |
| ferencd@0 | 45 return vmime::make_shared <timeoutHandler>(); |
| ferencd@0 | 46 } |
| ferencd@0 | 47 }; |
| ferencd@0 | 48 |
