X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fhtparser.c;h=001c6c1b13c8e71215dd24ca5ae10db49f9e96cf;hb=32e24c19cca5538c922542c7a6078efc53f5638b;hp=4924b981c01019c7a9c3f32d3629dff2ad3eb67c;hpb=46c3d4304f2846f05f1c44f39b67563f9f1f3acb;p=ashd.git diff --git a/src/htparser.c b/src/htparser.c index 4924b98..001c6c1 100644 --- a/src/htparser.c +++ b/src/htparser.c @@ -300,6 +300,7 @@ static void serve(struct muth *muth, va_list args) vavar(int, fd); vavar(struct sockaddr_storage, name); int cfd; + int pfds[2]; char old; char *hd, *p; struct charbuf inbuf, outbuf; @@ -352,16 +353,22 @@ static void serve(struct muth *muth, va_list args) } if(block(plex, EV_WRITE, 60) <= 0) goto out; - if((cfd = sendreq(plex, req)) < 0) + if(socketpair(PF_UNIX, SOCK_STREAM, 0, pfds)) goto out; + if(sendreq(plex, req, pfds[0])) + goto out; + close(pfds[0]); + cfd = pfds[1]; /* * If there is message data, pass it: */ if((hd = getheader(req, "content-length")) != NULL) { dlen = atoo(hd); - if(dlen > 0) - passdata(fd, cfd, &inbuf, dlen); + if(dlen > 0) { + if(passdata(fd, cfd, &inbuf, dlen) < 0) + goto out; + } } /* Make sure to send EOF */ shutdown(cfd, SHUT_WR); @@ -381,7 +388,8 @@ static void serve(struct muth *muth, va_list args) * Pass the actual output: */ sizebuf(outbuf, 65536); - sent = passdata(cfd, fd, &outbuf, -1); + if((sent = passdata(cfd, fd, &outbuf, -1)) < 0) + goto out; sent -= headoff; /* @@ -445,6 +453,28 @@ out: close(ss); } +static void plexwatch(struct muth *muth, va_list args) +{ + vavar(int, fd); + char *buf; + int ret; + + while(1) { + block(fd, EV_READ, 0); + buf = smalloc(65536); + ret = recv(fd, buf, 65536, 0); + if(ret < 0) { + flog(LOG_WARNING, "received error on rootplex read channel: %s", strerror(errno)); + exit(1); + } else if(ret == 0) { + exit(0); + } + /* Maybe I'd like to implement some protocol in this direction + * some day... */ + free(buf); + } +} + int main(int argc, char **argv) { int fd; @@ -470,6 +500,7 @@ int main(int argc, char **argv) } else { mustart(listenloop, fd); } + mustart(plexwatch, plex); ioloop(); return(0); }