bool SocketInputStream2::gets(BaseString& str) { if (get_buffered_line(str)) return true; char buf[16]; do { ssize_t read_res = read_socket(buf, sizeof(buf)); if (read_res == -1) return false; if (!add_buffer(buf, read_res)) return false; if (get_buffered_line(str)) return true; } while(true); abort(); // Should never come here return false; };
/* * Called by the libc stdio fread fucntions * * Implements a buffered read with line editing. */ int _read(int fd, char *ptr, int len) { int my_len; if (fd > 2) { return -1; } get_buffered_line(); my_len = 0; while ((buf_len > 0) && (len > 0)) { *ptr++ = buf[start_ndx]; start_ndx = inc_ndx(start_ndx); my_len++; len--; } return my_len; /* return the length we got */ }