X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/0f45342a680ac4a02816e71b8550dbc3610391c0..91fb3ca6b56328c626dabb35e2de9a5ae525b1b1:/practicas/pipi/src/devtcp.cpp?ds=inline diff --git a/practicas/pipi/src/devtcp.cpp b/practicas/pipi/src/devtcp.cpp index 828e0e6..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); @@ -41,9 +44,9 @@ void DevTCP::transmit(const std::string& data, const mac_type& mac) size_t size = data.size(); if (libtcp_send(tx_pool[mac], &size, sizeof(size_t)) != sizeof(size_t)) throw std::runtime_error("Error al enviar por el socket"); - if ((unsigned)libtcp_send(tx_pool[mac], data.c_str(), data.size()) != data.size()) + 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