uclient-fetch: add support for setting output directory
[project/uclient.git] / uclient-http.c
index 3ffb88c..fa66f78 100644 (file)
@@ -19,6 +19,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <stdint.h>
+#include <fcntl.h>
 
 #include <libubox/ustream.h>
 #include <libubox/ustream-ssl.h>
@@ -117,10 +118,11 @@ static int uclient_do_connect(struct uclient_http *uh, const char *port)
 
        memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
 
-       fd = usock_inet(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port, &uh->uc.remote_addr);
+       fd = usock_inet(USOCK_TCP, uh->uc.url->host, port, &uh->uc.remote_addr);
        if (fd < 0)
                return -1;
 
+       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
        ustream_fd_init(&uh->ufd, fd);
 
        sl = sizeof(uh->uc.local_addr);
@@ -736,6 +738,10 @@ static void uclient_notify_state(struct ustream *us)
 {
        struct uclient_http *uh = container_of(us, struct uclient_http, ufd.stream);
 
+       if (uh->ufd.stream.write_error) {
+               uclient_http_error(uh, UCLIENT_ERROR_CONNECT);
+               return;
+       }
        uclient_notify_eof(uh);
 }