diff options
| author | Vincent Richard <[email protected]> | 2014-03-09 09:28:56 +0000 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2014-03-09 09:28:56 +0000 |
| commit | baf79458fe77de02f00eae8a43bb56c87e3e7e38 (patch) | |
| tree | 1bae5f81c5a5dd3d09240d48639be0b6e4826bf1 /src | |
| parent | Fixed memory leak. (diff) | |
| download | vmime-baf79458fe77de02f00eae8a43bb56c87e3e7e38.tar.gz vmime-baf79458fe77de02f00eae8a43bb56c87e3e7e38.zip | |
Default timeout handler. Fixed spelling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/vmime/net/defaultTimeoutHandler.cpp | 78 | ||||
| -rw-r--r-- | src/vmime/net/defaultTimeoutHandler.hpp | 82 | ||||
| -rw-r--r-- | src/vmime/net/service.cpp | 4 | ||||
| -rw-r--r-- | src/vmime/net/service.hpp | 4 | ||||
| -rw-r--r-- | src/vmime/net/timeoutHandler.hpp | 10 |
5 files changed, 172 insertions, 6 deletions
diff --git a/src/vmime/net/defaultTimeoutHandler.cpp b/src/vmime/net/defaultTimeoutHandler.cpp new file mode 100644 index 00000000..306289c0 --- /dev/null +++ b/src/vmime/net/defaultTimeoutHandler.cpp @@ -0,0 +1,78 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2014 Vincent Richard <[email protected]> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 3 of +// the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#include "vmime/config.hpp" + + +#if VMIME_HAVE_MESSAGING_FEATURES + + +#include "vmime/net/defaultTimeoutHandler.hpp" + + +namespace vmime { +namespace net { + + +defaultTimeoutHandler::defaultTimeoutHandler() +{ + m_startTime = time(NULL); +} + + +defaultTimeoutHandler::~defaultTimeoutHandler() +{ +} + + +bool defaultTimeoutHandler::isTimeOut() +{ + return time(NULL) - m_startTime >= 30; +} + + +void defaultTimeoutHandler::resetTimeOut() +{ + m_startTime = time(NULL); +} + + +bool defaultTimeoutHandler::handleTimeOut() +{ + return false; +} + + + + +shared_ptr <timeoutHandler> defaultTimeoutHandlerFactory::create() +{ + return make_shared <defaultTimeoutHandler>(); +} + + +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES diff --git a/src/vmime/net/defaultTimeoutHandler.hpp b/src/vmime/net/defaultTimeoutHandler.hpp new file mode 100644 index 00000000..a45b9739 --- /dev/null +++ b/src/vmime/net/defaultTimeoutHandler.hpp @@ -0,0 +1,82 @@ +// +// VMime library (http://www.vmime.org) +// Copyright (C) 2002-2014 Vincent Richard <[email protected]> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 3 of +// the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// Linking this library statically or dynamically with other modules is making +// a combined work based on this library. Thus, the terms and conditions of +// the GNU General Public License cover the whole combination. +// + +#ifndef VMIME_NET_DEFAULTTIMEOUTHANDLER_HPP_INCLUDED +#define VMIME_NET_DEFAULTTIMEOUTHANDLER_HPP_INCLUDED + + +#include "vmime/config.hpp" + + +#if VMIME_HAVE_MESSAGING_FEATURES + + +#include "vmime/net/timeoutHandler.hpp" + +#include <ctime> + + +namespace vmime { +namespace net { + + +/** A default timeout handler for messaging services. The default action + * is to throw a exceptions::operation_timed_out exception when an + * operation is blocked for more than 30 seconds. + */ + +class VMIME_EXPORT defaultTimeoutHandler : public timeoutHandler +{ +public: + + defaultTimeoutHandler(); + ~defaultTimeoutHandler(); + + bool isTimeOut(); + void resetTimeOut(); + bool handleTimeOut(); + +private: + + time_t m_startTime; +}; + + +/** A class that creates default timeout handlers. + */ + +class defaultTimeoutHandlerFactory : public timeoutHandlerFactory +{ +public: + + shared_ptr <timeoutHandler> create(); +}; + + +} // net +} // vmime + + +#endif // VMIME_HAVE_MESSAGING_FEATURES + +#endif // VMIME_NET_DEFAULTTIMEOUTHANDLER_HPP_INCLUDED diff --git a/src/vmime/net/service.cpp b/src/vmime/net/service.cpp index c52ba592..482b141c 100644 --- a/src/vmime/net/service.cpp +++ b/src/vmime/net/service.cpp @@ -31,6 +31,8 @@ #include "vmime/platform.hpp" +#include "vmime/net/defaultTimeoutHandler.hpp" + #if VMIME_HAVE_SASL_SUPPORT #include "vmime/security/sasl/defaultSASLAuthenticator.hpp" #else @@ -66,6 +68,8 @@ service::service(shared_ptr <session> sess, const serviceInfos& /* infos */, #endif // VMIME_HAVE_TLS_SUPPORT m_socketFactory = platform::getHandler()->getSocketFactory(); + + m_toHandlerFactory = make_shared <defaultTimeoutHandlerFactory>(); } diff --git a/src/vmime/net/service.hpp b/src/vmime/net/service.hpp index 6969ac20..59352dea 100644 --- a/src/vmime/net/service.hpp +++ b/src/vmime/net/service.hpp @@ -169,8 +169,8 @@ public: shared_ptr <socketFactory> getSocketFactory(); /** Set the factory used to create timeoutHandler objects for - * this service. By default, no timeout handler is used. Not all - * services support timeout handling. + * this service. By default, the defaultTimeoutHandler class + * is used. Not all services support timeout handling. * * @param thf timeoutHandler factory */ diff --git a/src/vmime/net/timeoutHandler.hpp b/src/vmime/net/timeoutHandler.hpp index 24129701..397cc796 100644 --- a/src/vmime/net/timeoutHandler.hpp +++ b/src/vmime/net/timeoutHandler.hpp @@ -38,7 +38,9 @@ namespace vmime { namespace net { -/** A class to manage time-out in messaging services. +/** A class to manage timeouts in messaging services. This can be used + * to stop operations that takes too much time to complete (ie. no data + * received from the server for a long time if the network link is down). */ class VMIME_EXPORT timeoutHandler : public object @@ -49,18 +51,18 @@ public: /** Called to test if the time limit has been reached. * - * @return true if the time-out delay is elapsed + * @return true if the timeout delay is elapsed */ virtual bool isTimeOut() = 0; - /** Called to reset the time-out counter. + /** Called to reset the timeout counter. */ virtual void resetTimeOut() = 0; /** Called when the time limit has been reached (when * isTimeOut() returned true). * - * @return true to continue (and reset the time-out) + * @return true to continue (and reset the timeout) * or false to cancel the current operation */ virtual bool handleTimeOut() = 0; |
