diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-03-14 14:38:45 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-03-17 12:59:35 +0300 |
commit | 0b6b57f9acaa2ec648bf582ff67851331f8e6eef (patch) | |
tree | 7ce5da6a1c37f3674762d5514b0a34bf05e38df7 /web/apache/service.txx | |
parent | 637d5650b91cb1da2605e5f7049ccc8bab5591f3 (diff) |
Use serializable transaction isolation level
Diffstat (limited to 'web/apache/service.txx')
-rw-r--r-- | web/apache/service.txx | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/web/apache/service.txx b/web/apache/service.txx index b57befc..961c19b 100644 --- a/web/apache/service.txx +++ b/web/apache/service.txx @@ -3,9 +3,9 @@ // license : MIT; see accompanying LICENSE file #include <unistd.h> // getppid() -#include <signal.h> // kill() +#include <signal.h> // kill(), SIGTERM -#include <http_log.h> +#include <http_log.h> // APLOG_* #include <utility> // move() #include <exception> @@ -132,21 +132,31 @@ namespace web const M* e (dynamic_cast<const M*> (exemplar)); assert (e != nullptr); - M m (*e); - - if (static_cast<module&> (m).handle (rq, rq, lg)) - return rq.flush (); + for (M m (*e);;) + { + try + { + if (static_cast<module&> (m).handle (rq, rq, lg)) + return rq.flush (); - if (!rq.get_write_state ()) - return DECLINED; + if (rq.state () == request_state::initial) + return DECLINED; - lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, - "handling declined while unbuffered content " - "has been written"); + lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, + "handling declined being partially executed"); + break; + } + catch (const module::retry&) + { + // Retry to handle the request. + // + rq.rewind (); + } + } } catch (const invalid_request& e) { - if (!e.content.empty () && !rq.get_write_state ()) + if (!e.content.empty () && rq.state () < request_state::writing) { try { @@ -165,11 +175,12 @@ namespace web { lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, e.what ()); - if (*e.what () && !rq.get_write_state ()) + if (*e.what () && rq.state () < request_state::writing) { try { - rq.content (HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") + rq.content ( + HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") << e.what (); return rq.flush (); @@ -184,11 +195,12 @@ namespace web { lg.write (nullptr, 0, func_name.c_str (), APLOG_ERR, "unknown error"); - if (!rq.get_write_state ()) + if (rq.state () < request_state::writing) { try { - rq.content (HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") + rq.content ( + HTTP_INTERNAL_SERVER_ERROR, "text/plain;charset=utf-8") << "unknown error"; return rq.flush (); |