diff options
Diffstat (limited to 'sockutil.c')
-rw-r--r-- | sockutil.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -207,10 +207,13 @@ recv_packet(int fd) { char buf[QARSH_MAX_PACKET_SIZE]; uint32_t packetsize; + int bufused = 0; int ret = 0; if ((ret = read(fd, &packetsize, sizeof packetsize)) < 0) { - fprintf(stderr, "Read error while reading packet size: %s\n", strerror(errno)); + if (errno != ECONNRESET) { + fprintf(stderr, "Read error while reading packet size: %s\n", strerror(errno)); + } return NULL; } else if (ret == 0) { return NULL; @@ -223,15 +226,14 @@ recv_packet(int fd) fprintf(stderr, "Packet size too large, %d > %d\n", packetsize, QARSH_MAX_PACKET_SIZE); return NULL; } - if ((ret = read(fd, buf, packetsize)) < 0) { - fprintf(stderr, "Read error while reading packet data: %s\n", strerror(errno)); - return NULL; - } - if (ret != packetsize) { - fprintf(stderr, "Read something other than packetsize bytes, %d != %d\n", - ret, packetsize); - return NULL; - } + /* Keep reading until we get the whole packet and nothing but the packet, so help me socket */ + do { + if ((ret = read(fd, buf+bufused, packetsize-bufused)) < 0) { + fprintf(stderr, "Read error while reading packet data: %s\n", strerror(errno)); + return NULL; + } + bufused += ret; + } while (bufused < packetsize); return parse_packet(buf, packetsize); } |