]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
httpc: Add EINPROGRESS workaround for OSX
authorJaroslav Kysela <perex@perex.cz>
Tue, 10 Jun 2014 13:02:34 +0000 (15:02 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 10 Jun 2014 13:02:34 +0000 (15:02 +0200)
src/http.h
src/httpc.c

index 39131204321af4e9971e4150974070446b6f8834..b67cb9a530fb3d10ea4b75c66ccbbfcecdaaf2fd 100644 (file)
@@ -255,6 +255,7 @@ struct http_client {
   int          hc_result;
   int          hc_shutdown:1;
   int          hc_sending:1;
+  int          hc_einprogress:1;
   int          hc_reconnected:1;
   int          hc_keepalive:1;
   int          hc_in_data:1;
index 63a986fb35b2ddc999a81ca2bd5cd58d96a43820..d6b6129a29e04f1ed708d286651dea3bb0d52aa1 100644 (file)
@@ -467,12 +467,24 @@ http_client_send_partial( http_client_t *hc )
   while (wcmd != NULL) {
     hc->hc_cmd   = wcmd->wcmd;
     hc->hc_rcseq = wcmd->wcseq;
+    if (hc->hc_einprogress) {
+      /* this seems like OSX specific issue */
+      /* send() in the EINPROGRESS state closes the file-descriptor */
+      int err;
+      socklen_t errlen = sizeof(err);
+      r = 0;
+      getsockopt(hc->hc_fd, SOL_SOCKET, SO_ERROR, (void *)&err, &errlen);
+      if (err == EINPROGRESS)
+        goto skip;
+      hc->hc_einprogress = 0;
+    }
     if (hc->hc_ssl)
       r = http_client_ssl_send(hc, wcmd->wbuf + wcmd->wpos,
                                wcmd->wsize - wcmd->wpos);
     else
       r = send(hc->hc_fd, wcmd->wbuf + wcmd->wpos,
                wcmd->wsize - wcmd->wpos, MSG_DONTWAIT);
+skip:
     if (r < 0) {
       if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK ||
           errno == EINPROGRESS) {
@@ -1198,6 +1210,7 @@ http_client_reconnect
     tvhlog(LOG_ERR, "httpc", "Unable to connect to %s:%i - %s", host, port, errbuf);
     return -EINVAL;
   }
+  hc->hc_einprogress = 1;
   tvhtrace("httpc", "Connected to %s:%i", host, port);
   http_client_ssl_free(hc);
   if (strcasecmp(scheme, "https") == 0 || strcasecmp(scheme, "rtsps") == 0) {