X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/989d0da7e93d155dde399bf3047ab6b4af550bb6..9c0c758e9af50f624414decbaae43c04e8d8e3f9:/Server/src/transmitter.cpp diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index a195f6f..9d0e24d 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -41,37 +41,55 @@ namespace Server { Transmitter::~Transmitter(void) { #ifdef DEBUG - cerr << __FILE__ << ": destructor." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": destructor." << endl; #endif // DEBUG } -Transmitter::Transmitter(const string& _host, const Connection::Port& _port): - Connection(sockbuf::sock_dgram) { +Transmitter::Transmitter(const string& _host, const Connection::Port& _port) + throw(sockerr): Connection(sockbuf::sock_dgram, _host, _port) { #ifdef DEBUG - cerr << __FILE__ << ": host = " << _host - << " | port = " << _port << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": _host = " << _host + << " | _port = " << _port << endl; #endif // DEBUG - socket->connect(_host.c_str(), _port); + 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 } -/// \todo debría dar una excepción (?) -void Transmitter::real_run(void) { +void Transmitter::real_run(void) throw() { #ifdef DEBUG - cerr << __FILE__ << ": real_run()." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": real_run()." << endl; #endif // DEBUG // No hace nada, porque solo actua cuando se manda algo con send(). - while (!stop) { - Glib::usleep(1000); + while (!stop()) { + Glib::usleep(500000); // 1/2 segundo } } void Transmitter::send(const string& data) { #ifdef DEBUG - cerr << __FILE__ << ": send(data = " << data << ")." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": send()." << endl; +// << ": send(data = " << data << ")." << endl; #endif // DEBUG - socket << data << flush; + if (stop()) { + return; + } + try { + socket << data << flush; + } catch (const sockerr& e) { + signal_error().emit(e.serrno(), e.errstr()); + stop(true); + } } } // namespace Server