httpc: Add EINPROGRESS workaround for OSX

This commit is contained in:
Jaroslav Kysela 2014-06-10 15:02:34 +02:00
parent 96d2ee5a79
commit 900b2f0a80
2 changed files with 14 additions and 0 deletions

View 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;

View 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) {