Added a simple patplex.
[ashd.git] / src / htparser.c
index 5d7a932..001c6c1 100644 (file)
@@ -365,8 +365,10 @@ static void serve(struct muth *muth, va_list args)
         */
        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);
@@ -386,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;
        
        /*
@@ -450,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;
@@ -475,6 +500,7 @@ int main(int argc, char **argv)
     } else {
        mustart(listenloop, fd);
     }
+    mustart(plexwatch, plex);
     ioloop();
     return(0);
 }