X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/32f33ac62101f37de1133688b45c8eb837d5b8d8..91fb3ca6b56328c626dabb35e2de9a5ae525b1b1:/practicas/pipi/src/devtcp.cpp?ds=sidebyside diff --git a/practicas/pipi/src/devtcp.cpp b/practicas/pipi/src/devtcp.cpp index e8828f4..6bc709c 100644 --- a/practicas/pipi/src/devtcp.cpp +++ b/practicas/pipi/src/devtcp.cpp @@ -26,12 +26,15 @@ DevTCP::DevTCP(mac_type mac, uint16_t port, size_t mtu) void DevTCP::transmit(const std::string& data, const mac_type& mac) throw (std::runtime_error, std::logic_error) { +#ifdef DEBUG_TRACE + std::cout << "DevTCP[" << port << "]::transmit()\n"; +#endif if (data.size() > mtu) throw std::logic_error("Tamaño de datos mayor al MTU"); if (tx_pool.find(mac) == tx_pool.end()) // No existe la conexión { std::string addr = IPAddr(mac); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevTCP::transmit: conectando a " << addr << ":" << port << "\n"; #endif tx_pool[mac] = libtcp_open_activo(addr.c_str(), port); @@ -43,7 +46,7 @@ void DevTCP::transmit(const std::string& data, const mac_type& mac) throw std::runtime_error("Error al enviar por el socket"); if ((unsigned)libtcp_send(tx_pool[mac], data.data(), data.size()) != data.size()) throw std::runtime_error("Error al enviar por el socket"); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevTCP::transmit(mac = " << mac << ", size = " << data.size() << ")\n"; #endif @@ -51,10 +54,13 @@ void DevTCP::transmit(const std::string& data, const mac_type& mac) std::string DevTCP::receive() throw (std::runtime_error) { +#ifdef DEBUG_TRACE + std::cout << "DevTCP[" << port << "]::receive()\n"; +#endif // Nos fijamos en todos los file descriptors si hay algo para nosotros. while (true) { - int res = poll(pfds, pfds_size, 5000); + int res = poll(pfds, pfds_size, -1); if (res == -1) throw std::runtime_error("Error al hacer poll"); if (!res) @@ -89,7 +95,7 @@ std::string DevTCP::receive() throw (std::runtime_error) continue; std::string ret(buf, size); free(buf); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevTCP::receive(msgtype/mac = " << mac << ", size = " << ret.size() << ")\n"; #endif