tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Thomas <ma...@apache.org>
Subject Re: svn commit: r1665682 - /tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
Date Wed, 11 Mar 2015 18:57:24 GMT
On 11/03/2015 18:09, Christopher Schultz wrote:
> Mark,
> 
> On 3/11/15 1:02 PM, Christopher Schultz wrote:
>> Mark,
>>
>> On 3/10/15 4:44 PM, markt@apache.org wrote:
>>> Author: markt
>>> Date: Tue Mar 10 20:44:56 2015
>>> New Revision: 1665682
>>>
>>> URL: http://svn.apache.org/r1665682
>>> Log:
>>> Follow-up to r1665297
>>> Correct output loop. Forgot to increment offset for subsequent writes.
>>>
>>> Modified:
>>>     tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
>>>
>>> Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
>>> URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java?rev=1665682&r1=1665681&r2=1665682&view=diff
>>> ==============================================================================
>>> --- tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java (original)
>>> +++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Tue
Mar 10 20:44:56 2015
>>> @@ -302,11 +302,11 @@ public class AjpNioProcessor extends Abs
>>>          ByteBuffer writeBuffer =
>>>                  socketWrapper.getSocket().getBufHandler().getWriteBuffer();
>>>  
>>> -        int left = length;
>>> +        int thisTime = 0;
>>>          int written = 0;
>>> -        while (left > 0) {
>>> -            int toWrite = Math.min(left, writeBuffer.remaining());
>>> -            writeBuffer.put(src, offset, toWrite);
>>> +        while (written < length) {
>>> +            int toWrite = Math.min(length - written, writeBuffer.remaining());
>>> +            writeBuffer.put(src, offset + written, toWrite);
>>>              
>>>              writeBuffer.flip();
>>>      
>>> @@ -318,13 +318,13 @@ public class AjpNioProcessor extends Abs
>>>                  //ignore
>>>              }
>>>              try {
>>> -                written = pool.write(writeBuffer, socketWrapper.getSocket(),
>>> +                thisTime = pool.write(writeBuffer, socketWrapper.getSocket(),
>>>                          selector, writeTimeout, true);
>>>              } finally { 
>>>                  writeBuffer.clear();
>>>                  if ( selector != null ) pool.put(selector);
>>>              }
>>> -            left -= written;
>>> +            written += thisTime;
>>>          }
>>>      }
>>
>> This patch fixes my latest problem. (yay!)
>>
>> I'm not sure how I didn't catch the failure to update "offset" in the
>> original patch.
> 
> Can you give me a quick explanation of what's going on with
> writeBuffer.put()? Why is the second argument "offset + written" instead
> of just zero?

Because it is the start point in src for the data you want to put into
the writeBuffer.

> Do I misunderstand the way that NIO buffers are used?

Take a look at the Javadoc for put. The args are all about the source,
not the destination.

> If I were using a byte[] to buffer data, I'd usually fill up that buffer
> starting at offset=0, then "send" the data wherever, then treat the
> buffer as empty and start the copy targeted again as offset=0.

That is what we are doing. I think you are confusing source and destination.

> Do NIO buffers also carry message-context information (such as exactly
> what the starting offset in the whole message the current contents of
> the buffer represent)?

Yes. Although the meaning varies depending on whether it has been
flipped or not (which is why I ended up writing the wrapper around the
I/O buffers to track it).

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message