Mark,

On 3/11/15 1:02 PM, Christopher Schultz wrote:
> Mark,
> 
> On 3/10/15 4:44 PM, ma...@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?

Do I misunderstand the way that NIO buffers are used?

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.

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)?

Thanks,
-chris

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to