Remove dynamic exceptions
[anna.git] / example / timex / ArithmeticHTTPServer / Transaction.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <anna/app/functions.hpp>
10
11 #include <anna/comm/ClientSocket.hpp>
12 #include <anna/comm/Communicator.hpp>
13
14 #include <anna/http/Response.hpp>
15
16 #include "Transaction.hpp"
17
18 using namespace std;
19 using namespace anna;
20 using namespace test;
21
22 http4comm::Transaction::Transaction () : 
23    a_clientSocket (NULL) 
24
25    a_httpResponse = new http::Response;
26 }
27
28 /**
29  * Si el servidor aritmético no contesta antes de que se cumpla el tiempo de espera
30  * de la transación se contesta al cliente con un error indicando la situación.
31  */
32 void http4comm::Transaction::expire (anna::timex::Engine*)
33    noexcept(false)
34 {
35     comm::Communicator* communicator = app::functions::component <comm::Communicator> (ANNA_FILE_LOCATION);
36
37     comm::ClientSocket* clientSocket = getClientSocket ();
38
39     if (communicator->isUsable (clientSocket) == false)
40        return;
41
42     a_httpResponse->setStatusCode (408);
43     a_httpResponse->clearBody ();
44
45     clientSocket->send (a_httpResponse);
46 }
47
48