$Id$
-- Agregar timeouts (recvtimeout y sendtimeout).
+- Agregar timeouts (recvtimeout() y sendtimeout()).
- Darle bola al header Connection para saber si cerramos la conexión al
finalizar el request o no.
-- Ver por que el ControlClient tira una señal de error despues de una respuesta
- buena.
+- Hacer un try/catch en cada llamada al socket por si se desconecto, para que no
+ muera con un segmentation fault.
/// Conexión.
class Connection: public Runnable {
- // Constantes.
+ // Tipos.
- protected:
+ public:
- /// Tamaño del buffer usado para enviar y recibir datos.
- //static const int BUFFER_SIZE = 4096;
+ /// Puerto.
+ typedef unsigned Port;
// Atributos.
/// Socket a usar en la conexión.
iosockinet socket;
+ /// Host.
+ std::string host;
+
+ /// Puerto.
+ Port port;
+
/// Mutex para el socket.
//Glib::Mutex socket_mutex;
*
* \param type Tipo de socket a usar.
*/
- Connection(sockbuf::type type);
+ Connection(const sockbuf::type& type);
+
+ /**
+ * Constructor.
+ *
+ * \param host Host a donde conectarse.
+ * \param port Puerto a donde conectarse.
+ */
+ Connection(const std::string& host, const Port& port);
/**
* Finaliza la conexión.
/**
* Obtiene el nombre del host local de la conexión.
*/
- std::string get_peerhost(void);
+ const std::string& get_host(void) const;
/**
* Obtiene el puerto local de la conexión.
*/
- unsigned get_peerport(void);
+ const Port& get_port(void) const;
};
static const unsigned OK = 200;
static const unsigned BAD_REQUEST = 401;
static const unsigned NOT_FOUND = 404;
+ static const unsigned CONFLICT = 409;
static const unsigned LENGTH_REQUIRED = 411;
static const unsigned INTERNAL_SERVER_ERROR = 500;
static const unsigned NOT_IMPLEMENTED = 501;
--- /dev/null
+// vim: set noexpandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// PlaQui
+//----------------------------------------------------------------------------
+// This file is part of PlaQui.
+//
+// PlaQui 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 2 of the License, or (at your option) any later
+// version.
+//
+// PlaQui 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 PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: sáb nov 15 17:29:44 ART 2003
+// Autores: Leandro Lucarella <llucare@fi.uba.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#ifndef PLAQUI_PLANT_H
+#define PLAQUI_PLANT_H
+
+#include "plaqui/server/runnable.h"
+#include <sigc++/signal.h>
+
+namespace PlaQui {
+
+namespace Server {
+
+ /// Planta Química.
+ class Plant: public Runnable {
+
+
+ // Tipos.
+
+ public:
+
+ /// Tipo de señal para indicar que se actualizó la planta.
+ typedef SigC::Signal0<void> SignalUpdated;
+
+
+ // Atributos.
+
+ private:
+
+ /// Señal para indicar que se actualizó la planta.
+ SignalUpdated updated;
+
+
+ // Métodos.
+
+ protected:
+
+ /**
+ * Corre la planta (la monitorea o la simula).
+ */
+ virtual void real_run(void);
+
+ public:
+
+ /**
+ * Destructor.
+ */
+ virtual ~Plant(void);
+
+ /**
+ * Constructor desde un archivo.
+ *
+ * \param filename Nombre del archivo de donde obtener la planta.
+ */
+ Plant(const std::string& filename);
+
+ /**
+ * Obtiene la señal para indicar que se actualizó la planta.
+ */
+ SignalUpdated& signal_updated(void);
+
+ };
+
+}
+
+}
+
+#endif // PLAQUI_PLANT_H
#include "plaqui/server/tcpserver.h"
#include "plaqui/server/controlserver.h"
#include "plaqui/server/transmitter.h"
+#include "plaqui/server/plant.h"
#include "plaqui/server/command.h"
#include <socket++/sockinet.h>
#include <string>
/// Lista de conexiones de control.
typedef std::list<Transmitter*> TransmitterList;
- // TODO:
- // typedef std::list<Plant*> PlantList;
+ /// Lista de plantas químicas.
+ typedef std::list<Plant*> PlantList;
// Atributos.
/// Transmisiones del estado de las plantas.
TransmitterList transmissions;
- // TODO:
- // PlantList plants;
+ /// Mutex para las transmisiones.
+ Glib::Mutex transmissions_mutex;
+
+ // Plantas disponibles en el servidor.
+ PlantList plants;
+
+ /// Mutex para las plantas.
+ Glib::Mutex plants_mutex;
// Métodos.
*/
virtual Connection* new_connection(const sockbuf::sockdesc& sd);
+ /**
+ * Maneja el comando server/status.
+ */
+ HTTPResponse* cmd_server_status(void) const;
+
+ /**
+ * Maneja el comando connection/list.
+ */
+ HTTPResponse* cmd_connection_list(void);
+
+ /**
+ * Maneja el comando connection/stop.
+ */
+ HTTPResponse* cmd_connection_stop(const Command& command);
+
public:
/**
/**
* Maneja los comandos recibidos por las conexiones.
- *
- * \todo Hacer un tipo Command abstracto o algo así.
*/
void on_control_command_received(const Command& command,
- ControlServer* server);
+ ControlServer* controlserver);
};
#define PLAQUI_STRING_H
#include <string>
+#include <sstream>
#include <vector>
namespace PlaQui {
static String join(const std::vector<std::string>& v,
const std::string& sep);
+ /**
+ * Convierte un string a otro tipo.
+ *
+ * \param p Parametro del tipo al que se quiere convertir.
+ */
+ template < class T > T& to(T& p) const {
+ std::stringstream ss(*this);
+ ss >> p;
+ return p;
+ }
+
+ /**
+ * Convierte un tipo a string.
+ *
+ * \param p Parametro del tipo que se quiere convertir a string.
+ */
+ template < class T > String& from(const T& p) {
+ std::stringstream ss;
+ ss << p;
+ ss >> (*this);
+ return *this;
+ }
+
};
}
/// Host.
std::string host;
/// Port.
- unsigned port;
+ Connection::Port port;
};
/// Lista de información de conexiones de control.
/// Socket para escuchar conexiones.
sockinetbuf socket;
- /// Mutex para las conexiones.
- Glib::Mutex connections_mutex;
-
/// Conexiones de control.
ConnectionList connections;
+ /// Mutex para las conexiones.
+ Glib::Mutex connections_mutex;
+
// Métodos.
private:
*
* \param port Puerto en el cual escuchar.
*/
- TCPServer(int port);
+ TCPServer(const Connection::Port& port);
+
+ /**
+ * Finaliza la tarea.
+ *
+ * \param attach Si es true, la función no retorna hasta que no
+ * finalice la tearea (no recomendable).
+ *
+ * \note Para saber cuando la tarea fue finalizada puede utilizar
+ * la señal signal_finished().
+ */
+ virtual void finish(bool attach = false);
/**
* Se encarga de borrar una conexión de la lista cuando finaliza.
*/
void on_connection_finished(Connection* connection);
+ /**
+ * Detiene una conexión.
+ */
+ bool disconnect(const std::string& host,
+ const Connection::Port& port);
+
/**
* Obtiene una lista conexiones de control abiertas.
*/
`pkg-config --cflags glibmm-2.0 gthread-2.0`
CXXFLAGS+=-g -DDEBUG
#CXXFLAGS+=-g
-#CXXFLAGS+=-O3
+#CXXFLAGS+=-O2
#LDFLAGS=-lsocket++ `pkg-config --libs glibmm-2.0 gthread-2.0`
TARGETS=server.a
Connection::Connection(const sockbuf::sockdesc& sd):
socket(sd) {
#ifdef DEBUG
- cerr << __FILE__ << ": sd = " << sd.sock << endl;
+ cerr << __FILE__ << ": sd = " << sd.sock;
+#endif // DEBUG
+ host = socket->peerhost();
+ port = socket->peerport();
+#ifdef DEBUG
+ cerr << " | host = " << host << " | port = " << port << endl;
#endif // DEBUG
}
-Connection::Connection(sockbuf::type type):
+Connection::Connection(const sockbuf::type& type):
socket(type) {
#ifdef DEBUG
cerr << __FILE__ << ": type = " << type << endl;
#endif // DEBUG
}
+Connection::Connection(const std::string& host, const Port& port):
+ host(host), port(port) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": host = " << host << " | port = " << port << endl;
+#endif // DEBUG
+}
+
void Connection::finish(bool attach) {
//socket_mutex.lock();
socket->shutdown(sockbuf::shut_readwrite);
Runnable::finish(attach);
}
-string Connection::get_peerhost(void) {
- //socket_mutex.lock();
- string host = socket->peerhost();
- //socket_mutex.unlock();
+const string& Connection::get_host(void) const {
return host;
}
-unsigned Connection::get_peerport(void) {
- //socket_mutex.lock();
- unsigned port = socket->peerport();
- //socket_mutex.unlock();
+const Connection::Port& Connection::get_port(void) const {
return port;
}
#ifdef DEBUG
cerr << __FILE__ << ": real_run." << endl;
#endif // DEBUG
- socket->connect(host.c_str(), port);
- // TODO - mejorar manejo de errores de conexion.
- // volver a poner signal_disconnected()? reciclar signal_error_received()
- // y/o llamarla signal_error()?
- if (false) {
+ try {
+ socket->connect(host.c_str(), port);
+ } catch (const sockerr& e) {
+ // Poner una señal de error específica?
+ error_received(1);
finish();
- } else {
- connected();
+ return;
}
+ // TODO sacar a la mierda?
+ connected();
while (!stop) {
HTTPResponse response;
try {
/// \todo Implementar.
void Server::on_control_command_received(const Command& command,
- ControlServer* server) {
+ ControlServer* controlserver) {
#ifdef DEBUG
cerr << __FILE__ << ": on_control_command_received(target = "
<< command.get_target() << ", command = " << command.get_command()
<< ", args = [" << String::join(command.get_args(), ", ") << "])"
<< endl;
#endif // DEBUG
- HTTPResponse response(HTTPMessage::OK);
+ HTTPResponse* response;
+ //bool stop_controlserver = false;
if (command.get_target() == "server") {
-#ifdef DEBUG
- cerr << __FILE__ << ": server" << endl;
-#endif // DEBUG
if (command.get_command() == "status") {
- // FIXME
- stringstream response_xml;
- response_xml << "<html>" << endl;
- response_xml << " <head>" << endl;
- response_xml << " <title>PlaQui v0.6</title>" << endl;
- response_xml << " </head>" << endl;
- response_xml << " <body>" << endl;
- response_xml << " <h1>PlaQui</h1>" << endl;
- response_xml << " <p>versión 0.6</p>" << endl;
- response_xml << " <h2>Comando</h2>" << endl;
- response_xml << " <ul>" << endl;
- response_xml << " <li><b>Target:</b> " << command.get_target() << endl;
- response_xml << " <li><b>Command:</b> " << command.get_command() << endl;
- response_xml << " <li><b>Argumentos:</b>" << endl;
- response_xml << " <ol>" << endl;
- for (Command::Arguments::const_iterator i = command.get_args().begin();
- i != command.get_args().end(); i++) {
- response_xml << " <li>" << *i << "</li>" << endl;
- }
- response_xml << " </ol>" << endl;
- response_xml << " </ul>" << endl;
- response_xml << " <h2>Desarrollado por</h2>" << endl;
- response_xml << " <ul>" << endl;
- response_xml << " <li>Nicolás Dimov.</li>" << endl;
- response_xml << " <li>Leandro Lucarella.</li>" << endl;
- response_xml << " <li>Ricardo Markiewicz.</li>" << endl;
- response_xml << " </ul>" << endl;
- response_xml << " <address>" << endl;
- response_xml << " Copyleft 2003 - bajo los " << endl;
- response_xml << " términos de la licencia GPL" << endl;
- response_xml << " </address>" << endl;
- response_xml << " </body>" << endl;
- response_xml << "</html>" << endl;
- response.status_code = HTTPMessage::OK;
- response.set_body(response_xml.str());
+ response = cmd_server_status();
} else if (command.get_command() == "stop") {
- stop = true;
- response.set_body("El server se apagará en instantes...");
+ finish();
+ response = new HTTPResponse(HTTPMessage::OK,
+ "El server se apagará en instantes...");
} else {
- response.status_code = HTTPMessage::NOT_FOUND;
- response.set_body("Invalid command for 'server' taget!");
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND,
+ "Invalid command for 'server' taget!");
}
} else if (command.get_target() == "connection") {
if (command.get_command() == "list") {
- // FIXME
- TCPServer::ConnectionInfoList cil = get_connected();
- stringstream response_xml;
- response_xml << "<html>" << endl;
- response_xml << " <head>" << endl;
- response_xml << " <title>PlaQui v0.6</title>" << endl;
- response_xml << " </head>" << endl;
- response_xml << " <body>" << endl;
- response_xml << " <h1>PlaQui</h1>" << endl;
- response_xml << " <p>versión 0.6</p>" << endl;
- response_xml << " <h2>Lista de conexiones:</h2>" << endl;
- response_xml << " <ul>" << endl;
- for (TCPServer::ConnectionInfoList::const_iterator i = cil.begin();
- i != cil.end(); i++) {
- response_xml << " <li>" << i->host
- << ":" << i->port << " [<a href=\"/connection/disconnect/"
- << i->host << "/" << i->port << "\">deconectar</a>]</li>"
- << endl;
- }
- response_xml << " </ul>" << endl;
- response_xml << " <address>" << endl;
- response_xml << " Copyleft 2003 - bajo los " << endl;
- response_xml << " términos de la licencia GPL" << endl;
- response_xml << " </address>" << endl;
- response_xml << " </body>" << endl;
- response_xml << "</html>" << endl;
- response.status_code = HTTPMessage::OK;
- response.set_body(response_xml.str());
+ response = cmd_connection_list();
} else if (command.get_command() == "stop") {
- // TODO server->finish();
- response.set_body("La conexión se cerrará en instantes...");
+ response = cmd_connection_stop(command);
} else {
- response.status_code = HTTPMessage::NOT_FOUND;
- response.set_body("Invalid command for 'connection' taget!");
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND,
+ "Invalid command for 'connection' taget!");
}
} else if (command.get_target() == "transmission") {
- response.status_code = HTTPMessage::NOT_FOUND;
- response.set_body("Invalid command for 'transmission' taget!");
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND,
+ "Invalid command for 'transmission' taget!");
} else if (command.get_target() == "plant") {
- response.status_code = HTTPMessage::NOT_FOUND;
- response.set_body("Invalid command for 'plant' taget!");
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND,
+ "Invalid command for 'plant' taget!");
} else {
- response.status_code = HTTPMessage::NOT_FOUND;
- response.set_body("Invalid Target!");
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND, "Invalid taget!");
}
// FIXME
- response.headers["Content-Type"] = "text/html; charset=iso-8859-1";
- response.headers["Connection"] = "close";
- server->send(response);
+ response->headers["Content-Type"] = "text/html; charset=iso-8859-1";
+ //response->headers["Connection"] = "close";
+ controlserver->send(*response);
+ delete response;
// FIXME con timeout no debería ser necesario. Verificar cabecera Connection
// para saber si hay que finish()earlo o no.
- // server->finish();
+ //if (stop_controlserver) {
+ // controlserver->finish();
+ //}
+}
+
+HTTPResponse* Server::cmd_server_status(void) const {
+ // FIXME
+ stringstream response_xml;
+ response_xml << "<html>" << endl;
+ response_xml << " <head>" << endl;
+ response_xml << " <title>PlaQui v0.7</title>" << endl;
+ response_xml << " </head>" << endl;
+ response_xml << " <body>" << endl;
+ response_xml << " <h1>PlaQui</h1>" << endl;
+ response_xml << " <p>versión 0.7</p>" << endl;
+/* response_xml << " <h2>Comando</h2>" << endl;
+ response_xml << " <ul>" << endl;
+ response_xml << " <li><b>Target:</b> " << command.get_target() << endl;
+ response_xml << " <li><b>Command:</b> " << command.get_command() << endl;
+ response_xml << " <li><b>Argumentos:</b>" << endl;
+ response_xml << " <ol>" << endl;
+ for (Command::Arguments::const_iterator i = command.get_args().begin();
+ i != command.get_args().end(); i++) {
+ response_xml << " <li>" << *i << "</li>" << endl;
+ }
+ response_xml << " </ol>" << endl;
+ response_xml << " </ul>" << endl;
+*/ response_xml << " <h2>Desarrollado por</h2>" << endl;
+ response_xml << " <ul>" << endl;
+ response_xml << " <li>Nicolás Dimov.</li>" << endl;
+ response_xml << " <li>Leandro Lucarella.</li>" << endl;
+ response_xml << " <li>Ricardo Markiewicz.</li>" << endl;
+ response_xml << " </ul>" << endl;
+ response_xml << " <address>" << endl;
+ response_xml << " Copyleft 2003 - bajo los " << endl;
+ response_xml << " términos de la licencia GPL" << endl;
+ response_xml << " </address>" << endl;
+ response_xml << " </body>" << endl;
+ response_xml << "</html>" << endl;
+ return new HTTPResponse(HTTPMessage::OK, response_xml.str());
+}
+
+HTTPResponse* Server::cmd_connection_list(void) {
+ // FIXME
+ TCPServer::ConnectionInfoList cil = get_connected();
+ stringstream response_xml;
+ response_xml << "<html>" << endl;
+ response_xml << " <head>" << endl;
+ response_xml << " <title>PlaQui v0.7</title>" << endl;
+ response_xml << " </head>" << endl;
+ response_xml << " <body>" << endl;
+ response_xml << " <h1>PlaQui</h1>" << endl;
+ response_xml << " <p>versión 0.7</p>" << endl;
+ response_xml << " <h2>Lista de conexiones:</h2>" << endl;
+ response_xml << " <ul>" << endl;
+ for (TCPServer::ConnectionInfoList::const_iterator i = cil.begin();
+ i != cil.end(); i++) {
+ response_xml << " <li>" << i->host
+ << ":" << i->port << " [<a href=\"/connection/stop/"
+ << i->host << "/" << i->port << "\">deconectar</a>]</li>"
+ << endl;
+ }
+ response_xml << " </ul>" << endl;
+ response_xml << " <address>" << endl;
+ response_xml << " Copyleft 2003 - bajo los " << endl;
+ response_xml << " términos de la licencia GPL" << endl;
+ response_xml << " </address>" << endl;
+ response_xml << " </body>" << endl;
+ response_xml << "</html>" << endl;
+ return new HTTPResponse(HTTPMessage::OK, response_xml.str());
+}
+
+HTTPResponse* Server::cmd_connection_stop(const Command& command) {
+ const Command::Arguments& args = command.get_args();
+ Connection::Port port;
+ if (args.size() < 2) {
+ return new HTTPResponse(HTTPMessage::CONFLICT,
+ "Faltan argumentos.");
+ } else if (disconnect(args[0], String(args[1]).to(port))) {
+ return new HTTPResponse(HTTPMessage::OK,
+ string("La conexión a ") + args[0] + ":" + args[1]
+ + " se cerrará en instantes...");
+ } else {
+ return new HTTPResponse(HTTPMessage::NOT_FOUND,
+ string("No existe una conexión a ") + args[0]
+ + ":" + args[1]);
+ }
}
} // namespace Server
return ss.str();
}
+/*
+template < class T > T& String::to(T& p) const {
+ stringstream ss(*this);
+ ss >> p;
+ return p;
+}
+
+template < class T > String& String::from(const T& p) {
+ stringstream ss;
+ ss << p;
+ ss >> (*this);
+ return *this;
+}
+*/
+
} // namespace Server
} // namespace PlaQui
#endif // DEBUG
}
-TCPServer::TCPServer(int port): socket(sockbuf::sock_stream) {
+TCPServer::TCPServer(const Connection::Port& port): socket(sockbuf::sock_stream) {
#ifdef DEBUG
cerr << __FILE__ << ": port = " << port << endl;
#endif // DEBUG
+ // FIXME
+ //cerr << "recvtimeout = " << socket.recvtimeout(1) << endl;
+ //cerr << "sendtimeout = " << socket.sendtimeout(1) << endl;
+ //cerr << "recvtimeout = " << socket.recvtimeout(1) << endl;
+ //cerr << "sendtimeout = " << socket.sendtimeout(1) << endl;
socket.bind(port);
#ifdef DEBUG
cerr << __FILE__ << ": escuchando en " << socket.localhost()
#endif // DEBUG
}
+void TCPServer::finish(bool attach) {
+ //socket_mutex.lock();
+ socket.shutdown(sockbuf::shut_readwrite);
+ //socket_mutex.unlock();
+ Runnable::finish(attach);
+}
+
void TCPServer::on_connection_finished(Connection* connection) {
#ifdef DEBUG
cerr << __FILE__ << ": on_connection_finished(connection = "
}
}
+bool TCPServer::disconnect(const std::string& host, const Connection::Port& port) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": disconnect(host = " << host
+ << ", port = " << port << ")" << endl;
+#endif // DEBUG
+ Glib::Mutex::Lock lock(connections_mutex);
+ for (ConnectionList::iterator con = connections.begin();
+ con != connections.end(); con++) {
+ if (((*con)->get_host() == host) && ((*con)->get_port() == port)) {
+ (*con)->finish();
+ return true;
+ }
+ }
+ return false;
+}
+
TCPServer::ConnectionInfoList TCPServer::get_connected(void) {
#ifdef DEBUG
cerr << __FILE__ << ": get_connected()" << endl;
#endif // DEBUG
- TCPServer::ConnectionInfoList con;
+ TCPServer::ConnectionInfoList cl;
Glib::Mutex::Lock lock(connections_mutex);
- for (ConnectionList::const_iterator i = connections.begin();
- i != connections.end(); i++) {
+ for (ConnectionList::const_iterator con = connections.begin();
+ con != connections.end(); con++) {
TCPServer::ConnectionInfo ci =
- { (*i)->get_peerhost(), (*i)->get_peerport() };
- con.push_back(ci);
+ { (*con)->get_host(), (*con)->get_port() };
+ cl.push_back(ci);
}
- return con;
+ return cl;
}
} // namespace Server
`pkg-config --cflags glibmm-2.0 gthread-2.0`
CXXFLAGS+=-g -DDEBUG
#CXXFLAGS+=-g
-#CXXFLAGS+=-O3
+#CXXFLAGS+=-O2
LDFLAGS=-lsocket++ `pkg-config --libs glibmm-2.0 gthread-2.0` #-L$(LIB_FILES)
TARGETS=server_test client_test
client->signal_error_received().connect(SigC::slot(on_error_received));
client->run();
char buf[BUFSIZ];
- while (client && cin.getline(buf, BUFSIZ)) {
+ while (cin.getline(buf, BUFSIZ)) {
+ if (!client) {
+ break;
+ }
vector<string> v = String(buf).split(' ');
switch (v.size()) {
case 0:
break;
}
}
+ } catch (const sockerr& e) {
+ cerr << "Socket Error: " << e.operation() << " | serrno = "
+ << e.serrno() << " | errstr = " << e.errstr() << endl;
+ if (e.io()) {
+ cerr << "Es: non-blocking and interrupt io recoverable error."
+ << endl;
+ } else if (e.arg()) {
+ cerr << "Es: incorrect argument supplied. recoverable error."
+ << endl;
+ } else if (e.op()) {
+ cerr << "Es: operational error. recovery difficult." << endl;
+ } else if (e.conn()) {
+ cerr << "Es: connection error." << endl;
+ } else if (e.addr()) {
+ cerr << "Es: address error." << endl;
+ } else if (e.benign()) {
+ cerr << "Es: recoverable read/write error like EINTR etc." << endl;
+ }
+ } catch (const exception& e) {
+ cerr << "Error: " << e.what() << endl;
} catch (const char* e) {
cerr << "Error: " << e << endl;
- } catch (exception& e) {
- cerr << "Error: " << e.what() << endl;
} catch (...) {
cerr << "Error desconocido!" << endl;
}
Glib::thread_init();
try {
- // Corre el server.
- Server server(port);
- server.run(false);
+ // Corre el server.
+ Server server(port);
+ server.run(false);
+ } catch (const sockerr& e) {
+ cerr << "Socket Error: " << e.operation() << " | serrno = "
+ << e.serrno() << " | errstr = " << e.errstr() << endl;
+ if (e.io()) {
+ cerr << "Es: non-blocking and interrupt io recoverable error."
+ << endl;
+ } else if (e.arg()) {
+ cerr << "Es: incorrect argument supplied. recoverable error."
+ << endl;
+ } else if (e.op()) {
+ cerr << "Es: operational error. recovery difficult." << endl;
+ } else if (e.conn()) {
+ cerr << "Es: connection error." << endl;
+ } else if (e.addr()) {
+ cerr << "Es: address error." << endl;
+ } else if (e.benign()) {
+ cerr << "Es: recoverable read/write error like EINTR etc." << endl;
+ }
+ } catch (const exception& e) {
+ cerr << "Error: " << e.what() << endl;
} catch (const char* e) {
cerr << "Error: " << e << endl;
- } catch (exception e) {
- cerr << "Error: " << e.what() << endl;
} catch (...) {
cerr << "Error desconocido!" << endl;
}