From 42fc2662c7673df1b18e79c6bb622287fe3bf2ca Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 21 Jun 2006 18:42:42 +0000 Subject: [PATCH] =?utf8?q?Bugfix.=20ResolvProtoResponse::recv()=20enviaba?= =?utf8?q?=20en=20vez=20de=20recibir.=20Adem=C3=A1s=20se=20mejora=20la=20s?= =?utf8?q?alida.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- practicas/pipi/src/resolvproto.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/practicas/pipi/src/resolvproto.cpp b/practicas/pipi/src/resolvproto.cpp index 92a5512..fe2f94a 100644 --- a/practicas/pipi/src/resolvproto.cpp +++ b/practicas/pipi/src/resolvproto.cpp @@ -89,14 +89,14 @@ void ResolvProtoResponse::recv(int sockfd) if (libtcp_receive_bin(sockfd, &ret, sizeof(uint8_t)) != sizeof(uint8_t)) throw std::runtime_error("Error al recibir ret por socket"); uint8_t count; - if (libtcp_send(sockfd, &count, sizeof(uint8_t)) != sizeof(uint8_t)) + if (libtcp_receive_bin(sockfd, &count, sizeof(uint8_t)) != sizeof(uint8_t)) throw std::runtime_error("Error al recibir count por socket"); ips.clear(); ips.reserve(count); for (uint8_t i = 0; i < count; ++i) { uint32_t ip; - if (libtcp_send(sockfd, &ip, sizeof(uint32_t)) != sizeof(uint32_t)) + if (libtcp_receive_bin(sockfd, &ip, sizeof(uint32_t)) != sizeof(uint32_t)) throw std::runtime_error("Error al recibir IPAddr por socket"); ips.push_back(ip); } @@ -105,10 +105,12 @@ void ResolvProtoResponse::recv(int sockfd) /// Impresión de response std::ostream& operator<< (std::ostream& os, const ResolvProtoResponse& rpr) { + if (rpr.ips.empty()) + return os; os << "ResolvProtoResponse(ret=" << unsigned(rpr.ret) << ", "; - std::copy(rpr.ips.begin(), rpr.ips.end(), + std::copy(rpr.ips.begin(), rpr.ips.end() - 1, std::ostream_iterator< IPAddr >(os, ", ")); - return os << ")"; + return os << rpr.ips.back() << ")"; } // vim: set et sw=4 sts=4 : -- 2.43.0