Author: fhanik
Date: Fri Jun 8 03:18:21 2007
New Revision: 545469
URL: http://svn.apache.org/viewvc?view=rev&rev=545469
Log:
straightened out buffer handling
Modified:
tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
Modified:
tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java?view=diff&rev=545469&r1=545468&r2=545469
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java Fri
Jun 8 03:18:21 2007
@@ -406,7 +406,7 @@
if (!committed) {
//Socket.send(socket, Constants.ACK_BYTES, 0,
Constants.ACK_BYTES.length) < 0
ByteBuffer buf =
ByteBuffer.wrap(Constants.ACK_BYTES,0,Constants.ACK_BYTES.length);
- writeToSocket(buf,false,true);
+ writeToSocket(buf,true);
}
}
@@ -419,9 +419,12 @@
* @throws IOException
* @todo Fix non blocking write properly
*/
- private synchronized int writeToSocket(ByteBuffer bytebuffer, boolean
flip, boolean block) throws IOException {
- //int limit = bytebuffer.position();
- if ( flip ) bytebuffer.flip();
+ private synchronized int writeToSocket(ByteBuffer bytebuffer, boolean
block) throws IOException {
+ if (socket.getBufHandler().getWriteBuffer() != bytebuffer) {
+ socket.getBufHandler().getWriteBuffer().put(bytebuffer);
+ bytebuffer = socket.getBufHandler().getWriteBuffer();
+ }
+
int written = 0;
NioEndpoint.KeyAttachment att =
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
if ( att == null ) throw new IOException("Key must be cancelled");
@@ -441,7 +444,7 @@
}finally {
if ( selector != null ) getSelectorPool().put(selector);
}
- if ( block ) socket.getBufHandler().getWriteBuffer().clear(); //only
clear
+ if ( block ) bytebuffer.clear(); //only clear
this.total = 0;
return written;
}
@@ -762,7 +765,8 @@
//write to the socket, if there is anything to write
if (socket.getBufHandler().getWriteBuffer().position() > 0) {
- writeToSocket(socket.getBufHandler().getWriteBuffer(),true,true);
+ socket.getBufHandler().getWriteBuffer().flip();
+ writeToSocket(socket.getBufHandler().getWriteBuffer(),true);
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java?view=diff&rev=545469&r1=545468&r2=545469
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java Fri
Jun 8 03:18:21 2007
@@ -206,7 +206,11 @@
public void add(final KeyAttachment key, final int ops) {
Runnable r = new Runnable() {
public void run() {
- SocketChannel ch = key.getChannel().getIOChannel();
+ if ( key == null ) return;
+ NioChannel nch = key.getChannel();
+ if ( nch == null ) return;
+ SocketChannel ch = nch.getIOChannel();
+ if ( ch == null ) return;
SelectionKey sk = ch.keyFor(selector);
try {
if (sk == null) {
@@ -230,7 +234,11 @@
public void remove(final KeyAttachment key, final int ops) {
Runnable r = new Runnable() {
public void run() {
- SocketChannel ch = key.getChannel().getIOChannel();
+ if ( key == null ) return;
+ NioChannel nch = key.getChannel();
+ if ( nch == null ) return;
+ SocketChannel ch = nch.getIOChannel();
+ if ( ch == null ) return;
SelectionKey sk = ch.keyFor(selector);
try {
if (sk == null) {
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java?view=diff&rev=545469&r1=545468&r2=545469
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java Fri Jun
8 03:18:21 2007
@@ -152,10 +152,6 @@
public int write(ByteBuffer buf, NioChannel socket, Selector selector,
long writeTimeout, boolean block,MutableInteger
lastWrite) throws IOException {
- if (socket.getBufHandler().getWriteBuffer() != buf) {
- socket.getBufHandler().getWriteBuffer().put(buf);
- buf = socket.getBufHandler().getWriteBuffer();
- }
if ( SHARED && block ) {
return blockingSelector.write(buf,socket,writeTimeout,lastWrite);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]