if (send(fd, msg, msg_len, 0) == -1)
err("Failed to send the data.\n");
- int ret = 0, nb, p;
+ int ret = 0, nb;
while ((nb = recv(fd, rsp, sizeof(rsp)-1, 0)) > 0) {
- int peek = recv(fd, &p, 1, MSG_PEEK);
if (nb == 1 && rsp[0] < MSG_LENGTH) {
ret = rsp[0];
if (ret == MSG_UNKNOWN) {
warn("Invalid syntax.\n");
}
} else {
- rsp[nb--] = '\0';
- if (peek > 0) {
- printf("%s", rsp);
- } else {
- while (nb >= 0 && isspace(rsp[nb])) {
- rsp[nb--] = '\0';
- }
- printf("%s\n", rsp);
- }
+ rsp[nb] = '\0';
+ printf("%s", rsp);
fflush(stdout);
}
}