uhttpd: terminate I/O loops if socket writes fail
[project/luci.git] / contrib / package / uhttpd / src / uhttpd-file.c
index c300f0e..f0379bc 100644 (file)
@@ -1,5 +1,23 @@
-#define _XOPEN_SOURCE 500      /* strptime() ... */
-#define _BSD_SOURCE                    /* scandir() ... */
+/*
+ * uhttpd - Tiny non-forking httpd - Static file handler
+ *
+ *   Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#define _XOPEN_SOURCE 500      /* strptime() */
+#define _BSD_SOURCE                    /* scandir(), timegm() */
 
 #include "uhttpd.h"
 #include "uhttpd-utils.h"
@@ -230,7 +248,7 @@ static int uh_file_scandir_filter_dir(const struct dirent *e)
        return strcmp(e->d_name, ".") ? 1 : 0;
 }
 
-static void uh_file_dirlist(struct client *cl, struct http_request *req, struct uh_path_info *pi)
+static void uh_file_dirlist(struct client *cl, struct http_request *req, struct path_info *pi)
 {
        int i, count;
        char filename[PATH_MAX];
@@ -296,7 +314,7 @@ static void uh_file_dirlist(struct client *cl, struct http_request *req, struct
 }
 
 
-void uh_file_request(struct client *cl, struct http_request *req, struct uh_path_info *pi)
+void uh_file_request(struct client *cl, struct http_request *req, struct path_info *pi)
 {
        int fd, rlen;
        char buf[UH_LIMIT_MSGHEAD];
@@ -331,7 +349,8 @@ void uh_file_request(struct client *cl, struct http_request *req, struct uh_path
                                /* pump file data */
                                while( (rlen = read(fd, buf, sizeof(buf))) > 0 )
                                {
-                                       uh_http_send(cl, req, buf, rlen);
+                                       if( uh_http_send(cl, req, buf, rlen) < 0 )
+                                               break;
                                }
 
                                /* send trailer in chunked mode */