* Buffer small reads for better performance...
*/
+ ssize_t buflen; /* Length of read for buffer */
+
if (!http->blocking)
{
while (!httpWait(http, http->wait_value))
}
if (http->data_remaining > sizeof(http->buffer))
- bytes = sizeof(http->buffer);
+ buflen = sizeof(http->buffer);
else
- bytes = http->data_remaining;
+ buflen = http->data_remaining;
- DEBUG_printf(("2httpRead2: Reading %d bytes into buffer.", (int)bytes));
+ DEBUG_printf(("2httpRead2: Reading %d bytes into buffer.", (int)buflen));
+ do
+ {
#ifdef HAVE_SSL
- if (http->tls)
- bytes = http_read_ssl(http, http->buffer, bytes);
- else
+ if (http->tls)
+ bytes = http_read_ssl(http, http->buffer, buflen);
+ else
#endif /* HAVE_SSL */
- bytes = recv(http->fd, http->buffer, bytes, 0);
+ bytes = recv(http->fd, http->buffer, buflen, 0);
- DEBUG_printf(("2httpRead2: Read %d bytes into buffer.", (int)bytes));
-
- if (bytes > 0)
- http->used = bytes;
- else if (bytes < 0)
- {
-#ifdef WIN32
- if (WSAGetLastError() != WSAEINTR)
- {
- http->error = WSAGetLastError();
- return (-1);
- }
- else if (WSAGetLastError() == WSAEWOULDBLOCK)
+ if (bytes < 0)
{
- if (!http->timeout_cb || !(*http->timeout_cb)(http, http->timeout_data))
+#ifdef WIN32
+ if (WSAGetLastError() != WSAEINTR)
{
- http->error = WSAEWOULDBLOCK;
+ http->error = WSAGetLastError();
return (-1);
}
- }
+ else if (WSAGetLastError() == WSAEWOULDBLOCK)
+ {
+ if (!http->timeout_cb ||
+ !(*http->timeout_cb)(http, http->timeout_data))
+ {
+ http->error = WSAEWOULDBLOCK;
+ return (-1);
+ }
+ }
#else
- if (errno == EWOULDBLOCK || errno == EAGAIN)
- {
- if (http->timeout_cb && !(*http->timeout_cb)(http, http->timeout_data))
+ if (errno == EWOULDBLOCK || errno == EAGAIN)
{
- http->error = errno;
- return (-1);
+ if (http->timeout_cb && !(*http->timeout_cb)(http, http->timeout_data))
+ {
+ http->error = errno;
+ return (-1);
+ }
+ else if (!http->timeout_cb && errno != EAGAIN)
+ {
+ http->error = errno;
+ return (-1);
+ }
}
- else if (!http->timeout_cb && errno != EAGAIN)
+ else if (errno != EINTR)
{
http->error = errno;
return (-1);
}
- }
- else if (errno != EINTR)
- {
- http->error = errno;
- return (-1);
- }
#endif /* WIN32 */
+ }
}
- else
- {
- http->error = EPIPE;
- return (0);
- }
+ while (bytes < 0);
+
+ DEBUG_printf(("2httpRead2: Read %d bytes into buffer.", (int)bytes));
+
+ http->used = bytes;
}
if (http->used > 0)
}
}
- bytes = (ssize_t)http_read_ssl(http, buffer, (int)length);
+ while ((bytes = (ssize_t)http_read_ssl(http, buffer, (int)length)) < 0)
+ {
+#ifdef WIN32
+ if (WSAGetLastError() == WSAEWOULDBLOCK)
+ {
+ if (!http->timeout_cb || !(*http->timeout_cb)(http, http->timeout_data))
+ break;
+ }
+ else if (WSAGetLastError() != WSAEINTR)
+ break;
+#else
+ if (errno == EWOULDBLOCK || errno == EAGAIN)
+ {
+ if (http->timeout_cb && !(*http->timeout_cb)(http, http->timeout_data))
+ break;
+ else if (!http->timeout_cb && errno != EAGAIN)
+ break;
+ }
+ else if (errno != EINTR)
+ break;
+#endif /* WIN32 */
+ }
}
#endif /* HAVE_SSL */
else