[OpenWrt-Devel] [PATCH uclient] http: wait for socket to be ready before using it
Rafał Miłecki
zajec5 at gmail.com
Thu Jan 15 06:50:20 EST 2015
This is required as we use USOCK_NONBLOCK.
Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
---
uclient-http.c | 5 +++++
uclient.h | 2 ++
2 files changed, 7 insertions(+)
diff --git a/uclient-http.c b/uclient-http.c
index c25e52f..82bef8a 100644
--- a/uclient-http.c
+++ b/uclient-http.c
@@ -108,6 +108,7 @@ static int uclient_do_connect(struct uclient_http *uh, const char *port)
{
socklen_t sl;
int fd;
+ int err;
if (uh->uc.url->port)
port = uh->uc.url->port;
@@ -116,6 +117,10 @@ static int uclient_do_connect(struct uclient_http *uh, const char *port)
if (fd < 0)
return -1;
+ err = usock_wait_ready(fd, UCLIENT_DEFAULT_CONNECTION_TIMEOUT_MS);
+ if (err)
+ return err;
+
ustream_fd_init(&uh->ufd, fd);
memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr));
diff --git a/uclient.h b/uclient.h
index d5a0d5b..d90b00a 100644
--- a/uclient.h
+++ b/uclient.h
@@ -24,6 +24,8 @@
#include <libubox/ustream.h>
#include <libubox/ustream-ssl.h>
+#define UCLIENT_DEFAULT_CONNECTION_TIMEOUT_MS 30000
+
struct uclient_cb;
struct uclient_backend;
--
1.8.4.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list