This is an automated email from the ASF dual-hosted git repository.

jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  5a6addd   TS-4954: Use TSIOBufferCopy in the passthru example 
plugin.
5a6addd is described below

commit 5a6adddc25fc72bdd62c71bc66c47f89398301aa
Author: James Peach <[email protected]>
AuthorDate: Tue Oct 11 11:15:29 2016 -0700

    TS-4954: Use TSIOBufferCopy in the passthru example plugin.
---
 example/passthru/passthru.cc | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/example/passthru/passthru.cc b/example/passthru/passthru.cc
index 0eae7be..4cd3cb7 100644
--- a/example/passthru/passthru.cc
+++ b/example/passthru/passthru.cc
@@ -97,29 +97,16 @@ struct PassthruIO {
     this->vio    = TSVConnWrite(vconn, contp, this->reader, INT64_MAX);
   }
 
-  // Transfer data from this IO object to the target IO object.
+  // Transfer data from this IO object to the target IO object. We use
+  // TSIOBufferCopy to move the data without actually duplicating it.
   int64_t
   transfer_to(PassthruIO &to)
   {
-    TSIOBufferBlock block;
     int64_t consumed = 0;
+    int64_t avail    = TSIOBufferReaderAvail(this->reader);
 
-    for (block = TSIOBufferReaderStart(this->reader); block; block = 
TSIOBufferBlockNext(block)) {
-      int64_t remain = 0;
-      const char *bytes;
-
-      bytes = TSIOBufferBlockReadStart(block, this->reader, &remain);
-      while (bytes && remain) {
-        int64_t nwritten;
-
-        nwritten = TSIOBufferWrite(to.iobuf, bytes, remain);
-        remain -= nwritten;
-        bytes += nwritten;
-        consumed += nwritten;
-      }
-    }
-
-    if (consumed) {
+    if (avail) {
+      consumed = TSIOBufferCopy(to.iobuf, this->reader, avail, 0 /* offset */);
       TSIOBufferReaderConsume(this->reader, consumed);
     }
 
@@ -268,6 +255,7 @@ PassthruSessionEvent(TSCont cont, TSEvent event, void 
*edata)
 
       if (TSIOBufferReaderAvail(sp->server.readio.reader) > 0) {
         sp->server.readio.transfer_to(sp->client.writeio);
+        TSVIOReenable(sp->client.writeio.vio);
       }
 
       TSVConnClose(sp->server.vconn);

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to