You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2016/08/27 12:00:09 UTC
svn commit: r1758000 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
AprEndpoint.java Nio2Endpoint.java NioEndpoint.java
Author: violetagg
Date: Sat Aug 27 12:00:08 2016
New Revision: 1758000
URL: http://svn.apache.org/viewvc?rev=1758000&view=rev
Log:
Introduce fillReadBuffer(boolean, ByteBuffer)
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1758000&r1=1757999&r2=1758000&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Sat Aug 27 12:00:08 2016
@@ -2307,13 +2307,16 @@ public class AprEndpoint extends Abstrac
private int fillReadBuffer(boolean block) throws IOException {
+ socketBufferHandler.configureReadBufferForWrite();
+ return fillReadBuffer(block, socketBufferHandler.getReadBuffer());
+ }
+
+
+ private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException {
if (closed) {
throw new IOException(sm.getString("socket.apr.closed", getSocket()));
}
- socketBufferHandler.configureReadBufferForWrite();
- ByteBuffer socketReadBuffer = socketBufferHandler.getReadBuffer();
-
Lock readLock = getBlockingStatusReadLock();
WriteLock writeLock = getBlockingStatusWriteLock();
@@ -2325,8 +2328,8 @@ public class AprEndpoint extends Abstrac
if (block) {
Socket.timeoutSet(getSocket().longValue(), getReadTimeout() * 1000);
}
- result = Socket.recvb(getSocket().longValue(),
- socketReadBuffer, socketReadBuffer.position(), socketReadBuffer.remaining());
+ result = Socket.recvb(getSocket().longValue(), to, to.position(),
+ to.remaining());
readDone = true;
}
} finally {
@@ -2347,8 +2350,8 @@ public class AprEndpoint extends Abstrac
readLock.lock();
try {
writeLock.unlock();
- result = Socket.recvb(getSocket().longValue(),
- socketReadBuffer, socketReadBuffer.position(), socketReadBuffer.remaining());
+ result = Socket.recvb(getSocket().longValue(), to, to.position(),
+ to.remaining());
} finally {
readLock.unlock();
}
@@ -2362,7 +2365,7 @@ public class AprEndpoint extends Abstrac
}
if (result > 0) {
- socketReadBuffer.position(socketReadBuffer.position() + result);
+ to.position(to.position() + result);
return result;
} else if (result == 0 || -result == Status.EAGAIN) {
return 0;
@@ -2376,8 +2379,7 @@ public class AprEndpoint extends Abstrac
return 0;
} else if ((-result) == Status.ETIMEDOUT || (-result) == Status.TIMEUP) {
if (block) {
- throw new SocketTimeoutException(
- sm.getString("iib.readtimeout"));
+ throw new SocketTimeoutException(sm.getString("iib.readtimeout"));
} else {
// Attempting to read from the socket when the poller
// has not signalled that there is data to read appears
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1758000&r1=1757999&r2=1758000&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Sat Aug 27 12:00:08 2016
@@ -1081,11 +1081,15 @@ public class Nio2Endpoint extends Abstra
*/
private int fillReadBuffer(boolean block) throws IOException {
socketBufferHandler.configureReadBufferForWrite();
+ return fillReadBuffer(block, socketBufferHandler.getReadBuffer());
+ }
+
+ private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException {
int nRead = 0;
Future<Integer> integer = null;
if (block) {
try {
- integer = getSocket().read(socketBufferHandler.getReadBuffer());
+ integer = getSocket().read(to);
nRead = integer.get(getNio2ReadTimeout(), TimeUnit.MILLISECONDS).intValue();
} catch (ExecutionException e) {
if (e.getCause() instanceof IOException) {
@@ -1105,11 +1109,11 @@ public class Nio2Endpoint extends Abstra
}
} else {
Nio2Endpoint.startInline();
- getSocket().read(socketBufferHandler.getReadBuffer(), getNio2ReadTimeout(),
- TimeUnit.MILLISECONDS, this, readCompletionHandler);
+ getSocket().read(to, getNio2ReadTimeout(), TimeUnit.MILLISECONDS, this,
+ readCompletionHandler);
Nio2Endpoint.endInline();
if (readPending.availablePermits() == 1) {
- nRead = socketBufferHandler.getReadBuffer().position();
+ nRead = to.position();
}
}
return nRead;
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1758000&r1=1757999&r2=1758000&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Sat Aug 27 12:00:08 2016
@@ -1174,31 +1174,35 @@ public class NioEndpoint extends Abstrac
private int fillReadBuffer(boolean block) throws IOException {
+ socketBufferHandler.configureReadBufferForWrite();
+ return fillReadBuffer(block, socketBufferHandler.getReadBuffer());
+ }
+
+
+ private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException {
int nRead;
NioChannel channel = getSocket();
- socketBufferHandler.configureReadBufferForWrite();
if (block) {
Selector selector = null;
try {
selector = pool.get();
- } catch ( IOException x ) {
+ } catch (IOException x) {
// Ignore
}
try {
- NioEndpoint.NioSocketWrapper att =
- (NioEndpoint.NioSocketWrapper) channel.getAttachment();
+ NioEndpoint.NioSocketWrapper att = (NioEndpoint.NioSocketWrapper) channel
+ .getAttachment();
if (att == null) {
throw new IOException("Key must be cancelled.");
}
- nRead = pool.read(socketBufferHandler.getReadBuffer(),
- channel, selector, att.getReadTimeout());
+ nRead = pool.read(to, channel, selector, att.getReadTimeout());
} finally {
if (selector != null) {
pool.put(selector);
}
}
} else {
- nRead = channel.read(socketBufferHandler.getReadBuffer());
+ nRead = channel.read(to);
if (nRead == -1) {
throw new EOFException();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org