X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/802f79cdb0d688127b8a639cd3173d801a1466cd..c5c8d16a2d8c4a0ec1a8d3e83104f73512c91001:/Server/src/transmitter.cpp diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index 37113cc..9d0e24d 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -26,25 +26,73 @@ // #include "plaqui/server/transmitter.h" +#include #include #include +#ifdef DEBUG +# include +#endif // DEBUG -using namespace PlaQui::Server; +using namespace std; -Transmitter::Transmitter(std::string host, int port): - Connection(sockbuf::sock_dgram) { - // FIXME - deberia ir en run(). +namespace PlaQui { + +namespace Server { + +Transmitter::~Transmitter(void) { +#ifdef DEBUG + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": destructor." << endl; +#endif // DEBUG +} + +Transmitter::Transmitter(const string& _host, const Connection::Port& _port) + throw(sockerr): Connection(sockbuf::sock_dgram, _host, _port) { +#ifdef DEBUG + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": _host = " << _host + << " | _port = " << _port << endl; +#endif // DEBUG socket->connect(host.c_str(), port); + // Reasigno el host y puerto bien. + host = socket->peerhost(); + port = socket->peerport(); +#ifdef DEBUG + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": (real) host = " << _host + << " | port = " << _port << endl; +#endif // DEBUG +} + +void Transmitter::real_run(void) throw() { +#ifdef DEBUG + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": real_run()." << endl; +#endif // DEBUG + // No hace nada, porque solo actua cuando se manda algo con send(). + while (!stop()) { + Glib::usleep(500000); // 1/2 segundo + } } -void Transmitter::real_run(void) { - // FIXME - debería tirar una excepción? - if (!socket->is_open()) { - std::cerr << "No se pudo conectar a " << socket->peerhost() << - ":" << socket->peerport() << "." << std::endl; - } else { - std::cerr << "Conectado a " << socket->peerhost() << - ":" << socket->peerport() << "." << std::endl; +void Transmitter::send(const string& data) { +#ifdef DEBUG + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": send()." << endl; +// << ": send(data = " << data << ")." << endl; +#endif // DEBUG + if (stop()) { + return; + } + try { + socket << data << flush; + } catch (const sockerr& e) { + signal_error().emit(e.serrno(), e.errstr()); + stop(true); } } +} // namespace Server + +} // namespace PlaQui +