From: Leandro Lucarella Date: Wed, 21 Jun 2006 18:42:42 +0000 (+0000) Subject: Bugfix. ResolvProtoResponse::recv() enviaba en vez de recibir. Además se mejora X-Git-Tag: svn_import~36 X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/commitdiff_plain/42fc2662c7673df1b18e79c6bb622287fe3bf2ca?hp=037c7a6a269f053f09e3ebab3c28e4453b576d18 Bugfix. ResolvProtoResponse::recv() enviaba en vez de recibir. Además se mejora la salida. --- 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 :