commit 72a79cfb304402954d7a7b2d6d173a5906140d1d from: Omar Polo date: Sat Mar 13 11:42:56 2021 UTC don't drop the start of the document The first tls_read may and up reading more than the response line, but we were using another buffer in copy_body so we loose up to the first 1K of every document. commit - cb8d5d9b314a3eb43a1bf0546da1ad9eb133f005 commit + 72a79cfb304402954d7a7b2d6d173a5906140d1d blob - 33a22ca28746f0fdf4d3aec2f779f5c33e30cf38 blob + 2aa38854e1fc49c79cfdb069ab33fc5086a0c448 --- gemini.c +++ gemini.c @@ -366,6 +366,7 @@ parse_reply(struct req *req) if (code != 20) close_conn(0, 0, req); + advance_buf(req, len+1); /* skip \n too */ return; @@ -377,29 +378,31 @@ static void copy_body(int fd, short ev, void *d) { struct req *req = d; - char buf[BUFSIZ]; ssize_t r; - for (;;) { - switch (r = tls_read(req->ctx, buf, sizeof(buf))) { + do { + if (req->off != 0) { + imsg_compose(ibuf, IMSG_BUF, req->id, 0, -1, + req->buf, req->off); + imsg_flush(ibuf); + } + + switch (r = tls_read(req->ctx, req->buf, sizeof(req->buf))) { case TLS_WANT_POLLIN: yield_r(req, copy_body, NULL); return; case TLS_WANT_POLLOUT: yield_w(req, copy_body, NULL); return; - case -1: case 0: imsg_compose(ibuf, IMSG_EOF, req->id, 0, -1, NULL, 0); imsg_flush(ibuf); close_conn(0, 0, req); return; default: - imsg_compose(ibuf, IMSG_BUF, req->id, 0, -1, buf, r); - imsg_flush(ibuf); - break; + req->off = r; } - } + } while(1); } static void