X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/ab9300aaf1217f0c3b45dd5f1f1fdc1c5e5bd1be..eb95b779b5006ce4ef16ee1ffc1d15557d31ccef:/Server/src/transmitter.cpp?ds=sidebyside diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index 75f622d..a1ac7b0 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -26,40 +26,55 @@ // #include "plaqui/server/transmitter.h" +#include #include #include #ifdef DEBUG # include #endif // DEBUG -PlaQui::Server::Transmitter::~Transmitter(void) { +using namespace std; + +namespace PlaQui { + +namespace Server { + +Transmitter::~Transmitter(void) { #ifdef DEBUG - std::cerr << __FILE__ << ": destructor." << std::endl; + cerr << __FILE__ << ": destructor." << endl; #endif // DEBUG } -/// \todo debría conectarse en real_run() (?) -PlaQui::Server::Transmitter::Transmitter(std::string host, int port): - Connection(sockbuf::sock_dgram) { +Transmitter::Transmitter(const string& _host, const Connection::Port& _port): + Connection(sockbuf::sock_dgram, _host, _port) { #ifdef DEBUG - std::cerr << __FILE__ << ": host = " << host - << " | port = " << port << std::endl; + cerr << __FILE__ << ": _host = " << _host + << " | _port = " << _port << endl; #endif // DEBUG - // FIXME - deberia ir en run(). socket->connect(host.c_str(), port); + host = socket->peerhost(); + port = socket->peerport(); } /// \todo debría dar una excepción (?) -void PlaQui::Server::Transmitter::real_run(void) { +void Transmitter::real_run(void) { #ifdef DEBUG - // 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; + cerr << __FILE__ << ": real_run()." << endl; +#endif // DEBUG + // No hace nada, porque solo actua cuando se manda algo con send(). + while (!stop) { + Glib::usleep(1000); } +} + +void Transmitter::send(const string& data) { +#ifdef DEBUG + cerr << __FILE__ << ": send(data = " << data << ")." << endl; #endif // DEBUG + socket << data << flush; } +} // namespace Server + +} // namespace PlaQui +