1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
10 El objetivo de éste programa es generar errores en el cliente que se conecte a él.
12 Como no atiendo ningún tipo de.tráfico llegará un momento en el que su cola de entrada
13 alcanzará el límite y el cliente obtendrá un error al intentar enviar el mensaje.
15 Se trata de verificar que los servicios de reparto son capaces de asumir ciertos
21 #include <anna/core/core.hpp>
22 #include <anna/comm/comm.hpp>
24 #include <anna/xml/Node.hpp>
25 #include <anna/xml/Attribute.hpp>
29 class MyCommunicator : public Communicator {
34 void eventReceiveMessage (comm::ClientSocket&, const Message&) noexcept(false);
37 class Blocker : public comm::Application {
42 MyCommunicator a_communicator;
43 comm::ServerSocket* a_blockerSocket;
45 void initialize () noexcept(false);
46 void run () noexcept(false);
50 using namespace anna::comm;
52 int main (int argc, const char** argv)
54 CommandLine& commandLine (CommandLine::instantiate ());
62 commandLine.initialize (argv, argc);
63 commandLine.verify ();
65 Logger::setLevel (Logger::Debug);
66 Logger::initialize ("Blocker", new TraceWriter ("file.trace",4096000));
70 catch (Exception& ex) {
71 cout << ex.asString () << endl;
78 Application ("Blocker", "Bloqueador de comunicaciones", "1.0")
80 CommandLine& commandLine (CommandLine::instantiate ());
82 commandLine.add ("p", CommandLine::Argument::Mandatory, "Puerto en el que atender peticiones");
83 commandLine.add ("a", CommandLine::Argument::Mandatory, "Direccin IP en la que atender");
84 commandLine.add ("trace", CommandLine::Argument::Optional, "Nivel de trazas (debug,warning, error,...)");
87 //-----------------------------------------------------------------------------------------
88 // Inicializa el servidor de sockets.
89 //-----------------------------------------------------------------------------------------
90 void Blocker::initialize ()
93 CommandLine& cl (CommandLine::instantiate ());
95 int port = cl.getIntegerValue ("p");
96 const comm::Device* device = Network::instantiate ().find (Device::asAddress (cl.getValue ("a")));
98 a_blockerSocket = new ServerSocket (INetAddress (device, port), false);
99 a_blockerSocket->setCategory (777);
102 //-----------------------------------------------------------------------------------------
103 // Atiende las peticiones.
104 // Cuando hay un nuevo mensaje invocar�a Communicator::eventReceiveMessage
105 //-----------------------------------------------------------------------------------------
109 CommandLine& cl (CommandLine::instantiate ());
111 a_communicator.attach (a_blockerSocket);
113 if (cl.exists ("trace"))
114 Logger::setLevel (Logger::asLevel (cl.getValue ("trace")));
116 a_communicator.accept ();
119 //-----------------------------------------------------------------------------------------
120 // Cuando recibe el primer mensaje deja al sistema bloqueado esperando una tecla.
121 //-----------------------------------------------------------------------------------------
122 void MyCommunicator::eventReceiveMessage (ClientSocket& clientSocket, const Message& message)
125 LOGMETHOD (TraceMethod tm ("MyCommunicator", "eventReceiveMessage", ANNA_FILE_LOCATION));
126 static bool blocking = true;
128 if (blocking == false)
134 app::Application& app = app::functions::getApp ();
135 cout << "Bloqueando las comunicaciones ejecute (kill -9 " << app.getPid () << ") ... " << flush;
136 while (stop == false) {
137 if (fgets(aux, sizeof(aux), stdin) != NULL) {
138 if (aux [0] == 'q' || aux [0] == 'Q')