- while (msg_len) {
- len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf)));
- if (len == 0)
- fatal("Connection closed");
- else if (len == -1)
- fatal("Couldn't read packet: %s", strerror(errno));
-
- msg_len -= len;
- buffer_append(m, buf, len);
- }
+ buffer_append_space(m, msg_len);
+ len = atomicio(read, fd, buffer_ptr(m), msg_len);
+ if (len == 0)
+ fatal("Connection closed");
+ else if (len == -1)
+ fatal("Read packet: %s", strerror(errno));