int sock_read(int sockfd, char *buf, const size_t count) { size_t bytes_read = 0; int this_read; while (bytes_read < count) { do { this_read = read(sockfd, buf, count-bytes_read); } while (this_read < 0 && errno == EINTR); if (this_read < 0) { return this_read; } else if (this_read == 0) { return bytes_read; } bytes_read += this_read; buf += this_read; } return bytes_read; }