- cfd = sendreq(plex, req);
-
- /*
- * Find and decode the response header:
- */
- outbuf.d = 0;
- headoff = readhead(cfd, &outbuf);
- hd = memcpy(smalloc(headoff + 1), outbuf.b, headoff);
- hd[headoff] = 0;
- if((resp = parserawresp(hd)) == NULL)
- goto out;
-
- /*
- * Pass the actual output:
- */
- sizebuf(outbuf, 65536);
- sent = passdata(cfd, fd, &outbuf, -1);
- sent -= headoff;
+
+ if(block(plex, EV_WRITE, 60) <= 0)
+ break;
+ if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds))
+ break;
+ if(sendreq(plex, req, pfds[0]))
+ break;
+ close(pfds[0]);
+ out = mtstdopen(pfds[1], 1, 600, "r+");
+
+ if((hd = getheader(req, "content-length")) != NULL) {
+ dlen = atoo(hd);
+ if(dlen > 0) {
+ if(passdata(in, out, dlen) != dlen)
+ break;
+ }
+ }
+ if(fflush(out))
+ break;
+ /* Make sure to send EOF */
+ shutdown(pfds[1], SHUT_WR);