Author: rhuijben
Date: Thu Nov  5 14:36:59 2015
New Revision: 1712786

URL: http://svn.apache.org/viewvc?rev=1712786&view=rev
Log:
Following up on r1712776, reduce the strict dependency on polling for
cleanup of finished request by also explicitly setting the writing
status to DONE via a hold_open callback.

A specific hold open bucket would be useful :).

* outgoing.c
  (request_writing_finished): New function.
  (write_to_connection): Setup callback when a request is done.

Modified:
    serf/trunk/outgoing.c

Modified: serf/trunk/outgoing.c
URL: 
http://svn.apache.org/viewvc/serf/trunk/outgoing.c?rev=1712786&r1=1712785&r2=1712786&view=diff
==============================================================================
--- serf/trunk/outgoing.c (original)
+++ serf/trunk/outgoing.c Thu Nov  5 14:36:59 2015
@@ -896,6 +896,19 @@ apr_status_t serf__connection_flush(serf
     return status ? status : read_status;
 }
 
+/* Implements serf_bucket_aggregate_eof_t to mark that the request that is
+   already DONE writing has actually FINISHED writing. */
+static apr_status_t request_writing_finished(void *baton,
+                                             serf_bucket_t *aggregate_bucket)
+{
+    serf_request_t *request = baton;
+
+    if (request->writing == SERF_WRITING_DONE)
+    request->writing = SERF_WRITING_FINISHED;
+
+    return APR_EOF;
+}
+
 /* write data out to the connection */
 static apr_status_t write_to_connection(serf_connection_t *conn)
 {
@@ -992,6 +1005,7 @@ static apr_status_t write_to_connection(
             return status;
 
         if (request && conn->hit_eof && conn->vec_len == 0) {
+            serf_bucket_t *trk_bkt;
             /* If we hit the end of the request bucket and all of its data has
              * been written, then clear it out to signify that we're done
              * sending the request. On the next iteration through this loop:
@@ -1002,6 +1016,15 @@ static apr_status_t write_to_connection(
              */
             request->writing = SERF_WRITING_DONE;
 
+            /* We don't know when the request writing is finished, but we know
+               how to track that... Let's introduce a callback that is called
+               when we write again */
+            /* ### More efficient to use other bucket type? */
+            trk_bkt = serf_bucket_aggregate_create(conn->allocator);
+            serf_bucket_aggregate_hold_open(trk_bkt, request_writing_finished,
+                                            request);
+            serf_bucket_aggregate_prepend(ostreamt, trk_bkt);
+
             /* Move the request to the written queue */
             serf__link_requests(&conn->written_reqs, &conn->written_reqs_tail,
                                 request);


Reply via email to