Author: rhuijben
Date: Sun Oct 18 19:07:20 2015
New Revision: 1709298
URL: http://svn.apache.org/viewvc?rev=1709298&view=rev
Log:
Extract a bit of duplicated code in the connection handling to allow calling
it from a different location via a private api.
* serf-dev/dev/outgoing.c
(serf__connection_flush): New function. Extracted from...
(write_to_connection): ... two places in this function.
* serf-dev/dev/serf_private.h
(serf__connection_flush): New function.
Modified:
serf/trunk/outgoing.c
serf/trunk/serf_private.h
Modified: serf/trunk/outgoing.c
URL:
http://svn.apache.org/viewvc/serf/trunk/outgoing.c?rev=1709298&r1=1709297&r2=1709298&view=diff
==============================================================================
--- serf/trunk/outgoing.c (original)
+++ serf/trunk/outgoing.c Sun Oct 18 19:07:20 2015
@@ -806,6 +806,25 @@ static apr_status_t socket_writev(serf_c
return status;
}
+apr_status_t serf__connection_flush(serf_connection_t *conn)
+{
+ apr_status_t status = APR_SUCCESS;
+
+ while (conn->vec_len && !status) {
+ status = socket_writev(conn);
+
+ /* If the write would have blocked, then we're done. Don't try
+ * to write anything else to the socket.
+ */
+ if (APR_STATUS_IS_EPIPE(status)
+ || APR_STATUS_IS_ECONNRESET(status)
+ || APR_STATUS_IS_ECONNABORTED(status))
+ return no_more_writes(conn);
+
+ }
+ return status;
+}
+
static apr_status_t setup_request(serf_request_t *request)
{
serf_connection_t *conn = request->conn;
@@ -875,21 +894,12 @@ static apr_status_t write_to_connection(
}
/* If we have unwritten data, then write what we can. */
- while (conn->vec_len) {
- status = socket_writev(conn);
+ status = serf__connection_flush(conn);
+ if (APR_STATUS_IS_EAGAIN(status))
+ return APR_SUCCESS;
+ else if (status)
+ return status;
- /* If the write would have blocked, then we're done. Don't try
- * to write anything else to the socket.
- */
- if (APR_STATUS_IS_EAGAIN(status))
- return APR_SUCCESS;
- if (APR_STATUS_IS_EPIPE(status)
- || APR_STATUS_IS_ECONNRESET(status)
- || APR_STATUS_IS_ECONNABORTED(status))
- return no_more_writes(conn);
- if (status)
- return status;
- }
/* ### can we have a short write, yet no EAGAIN? a short write
### would imply unwritten_len > 0 ... */
/* assert: unwritten_len == 0. */
@@ -967,21 +977,11 @@ static apr_status_t write_to_connection(
/* If we got some data, then deliver it. */
/* ### what to do if we got no data?? is that a problem? */
- if (conn->vec_len > 0) {
- status = socket_writev(conn);
-
- /* If we can't write any more, or an error occurred, then
- * we're done here.
- */
- if (APR_STATUS_IS_EAGAIN(status))
- return APR_SUCCESS;
- if (APR_STATUS_IS_EPIPE(status)
- || APR_STATUS_IS_ECONNRESET(status)
- || APR_STATUS_IS_ECONNABORTED(status))
- return no_more_writes(conn);
- if (status)
- return status;
- }
+ status = serf__connection_flush(conn);
+ if (APR_STATUS_IS_EAGAIN(status))
+ return APR_SUCCESS;
+ else if (status)
+ return status;
if (read_status == SERF_ERROR_WAIT_CONN) {
stop_reading = 1;
Modified: serf/trunk/serf_private.h
URL:
http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1709298&r1=1709297&r2=1709298&view=diff
==============================================================================
--- serf/trunk/serf_private.h (original)
+++ serf/trunk/serf_private.h Sun Oct 18 19:07:20 2015
@@ -496,6 +496,7 @@ serf_request_t *serf__ssltunnel_request_
serf_request_setup_t setup,
void *setup_baton);
void serf__connection_set_pipelining(serf_connection_t *conn, int enabled);
+apr_status_t serf__connection_flush(serf_connection_t *conn);
apr_status_t serf__provide_credentials(serf_context_t *ctx,
char **username,