void
httpFlush(http_t *http) /* I - Connection to server */
{
- char buffer[8192]; /* Junk buffer */
- int blocking; /* To block or not to block */
+ char buffer[8192]; /* Junk buffer */
+ int blocking; /* To block or not to block */
+ http_state_t oldstate; /* Old state */
DEBUG_printf(("httpFlush(http=%p), state=%s", http,
* Read any data we can...
*/
+ oldstate = http->state;
while (httpRead2(http, buffer, sizeof(buffer)) > 0);
/*
http->blocking = blocking;
- if (http->state != HTTP_WAITING && http->fd >= 0)
+ if (http->state == oldstate && http->fd >= 0)
{
/*
* Didn't get the data back, so close the current connection.
DEBUG_printf(("httpFlushWrite(http=%p)", http));
if (!http || !http->wused)
+ {
+ DEBUG_puts(http ? "1httpFlushWrite: Write buffer is empty." :
+ "1httpFlushWrite: No connection.");
return (0);
+ }
if (http->data_encoding == HTTP_ENCODE_CHUNKED)
bytes = http_write_chunk(http, http->wbuffer, http->wused);
http->wused = 0;
+ DEBUG_printf(("1httpFlushWrite: Returning %d.", bytes));
+
return (bytes);
}
DEBUG_printf(("4_httpWait(http=%p, msec=%d, usessl=%d)", http, msec, usessl));
if (http->fd < 0)
+ {
+ DEBUG_printf(("5_httpWait: Returning 0 since fd=%d", http->fd));
return (0);
+ }
/*
* Check the SSL/TLS buffers for data first...
{
# ifdef HAVE_LIBSSL
if (SSL_pending((SSL *)(http->tls)))
+ {
+ DEBUG_puts("5_httpWait: Return 1 since there is pending SSL data.");
return (1);
+ }
+
# elif defined(HAVE_GNUTLS)
if (gnutls_record_check_pending(((http_tls_t *)(http->tls))->session))
+ {
+ DEBUG_puts("5_httpWait: Return 1 since there is pending SSL data.");
return (1);
+ }
+
# elif defined(HAVE_CDSASSL)
size_t bytes; /* Bytes that are available */
if (!SSLGetBufferedReadSize(((http_tls_t *)(http->tls))->session, &bytes) &&
bytes > 0)
+ {
+ DEBUG_puts("5_httpWait: Return 1 since there is pending SSL data.");
return (1);
+ }
# endif /* HAVE_LIBSSL */
}
#endif /* HAVE_SSL */
# endif /* WIN32 */
#endif /* HAVE_POLL */
- DEBUG_printf(("5_httpWait: returning with nfds=%d...", nfds));
+ DEBUG_printf(("5_httpWait: returning with nfds=%d, errno=%d...", nfds,
+ errno));
return (nfds > 0);
}
bytes; /* Bytes sent */
+ DEBUG_printf(("2http_write(http=%p, buffer=%p, length=%d)", http, buffer,
+ length));
http->error = 0;
tbytes = 0;
}
#endif /* WIN32 */
- DEBUG_puts("8http_write: error writing data...");
+ DEBUG_printf(("3http_write: error writing data (%s).",
+ strerror(http->error)));
return (-1);
}
http_debug_hex("http_write", buffer - tbytes, tbytes);
#endif /* DEBUG */
+ DEBUG_printf(("3http_write: Returning %d.", tbytes));
+
return (tbytes);
}
const char *buf, /* I - Buffer holding data */
int len) /* I - Length of buffer */
{
+ ssize_t result; /* Return value */
+
+
+ DEBUG_printf(("2http_write_ssl(http=%p, buf=%p, len=%d)", http, buf, len));
+
# if defined(HAVE_LIBSSL)
- return (SSL_write((SSL *)(http->tls), buf, len));
+ result = SSL_write((SSL *)(http->tls), buf, len);
# elif defined(HAVE_GNUTLS)
- ssize_t result; /* Return value */
-
result = gnutls_record_send(((http_tls_t *)(http->tls))->session, buf, len);
if (result < 0 && !errno)
result = -1;
}
- return ((int)result);
-
# elif defined(HAVE_CDSASSL)
- int result; /* Return value */
OSStatus error; /* Error info */
size_t processed; /* Number of bytes processed */
result = -1;
break;
}
-
- return (result);
# endif /* HAVE_LIBSSL */
+
+ DEBUG_printf(("3http_write_ssl: Returning %d.", (int)result));
+
+ return ((int)result);
}
#endif /* HAVE_SSL */