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/10 12:38:31 UTC
svn commit: r1755731 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
AprEndpoint.java Nio2Endpoint.java NioEndpoint.java
Author: violetagg
Date: Wed Aug 10 12:38:31 2016
New Revision: 1755731
URL: http://svn.apache.org/viewvc?rev=1755731&view=rev
Log:
Remove duplications.
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=1755731&r1=1755730&r2=1755731&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed Aug 10 12:38:31 2016
@@ -2287,13 +2287,9 @@ public class AprEndpoint extends Abstrac
int remaining = readBuffer.remaining();
// Is there enough data in the read buffer to satisfy this request?
- if (remaining >= len) {
- readBuffer.get(b, off, len);
- return len;
- }
-
// Copy what data there is in the read buffer to the byte array
if (remaining > 0) {
+ remaining = Math.min(remaining, len);
readBuffer.get(b, off, remaining);
return remaining;
/*
@@ -2312,16 +2308,10 @@ public class AprEndpoint extends Abstrac
// data that was just read
if (nRead > 0) {
socketBufferHandler.configureReadBufferForRead();
- if (nRead > len) {
- readBuffer.get(b, off, len);
- return len;
- } else {
- readBuffer.get(b, off, nRead);
- return nRead;
- }
- } else {
- return nRead;
+ nRead = Math.min(nRead, len);
+ readBuffer.get(b, off, nRead);
}
+ return nRead;
}
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=1755731&r1=1755730&r2=1755731&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Wed Aug 10 12:38:31 2016
@@ -838,23 +838,17 @@ public class Nio2Endpoint extends Abstra
throw new IOException(sm.getString("socket.closed"));
}
socketBufferHandler.configureReadBufferForRead();
-
- int remaining = socketBufferHandler.getReadBuffer().remaining();
+ ByteBuffer readBuffer = socketBufferHandler.getReadBuffer();
+ int remaining = readBuffer.remaining();
// Is there enough data in the read buffer to satisfy this request?
- if (remaining >= len) {
- socketBufferHandler.getReadBuffer().get(b, off, len);
- if (log.isDebugEnabled()) {
- log.debug("Socket: [" + this + "], Read from buffer: [" + len + "]");
- }
- // No read is going to take place so release here.
- readPending.release();
- return len;
- }
-
// Copy what data there is in the read buffer to the byte array
if (remaining > 0) {
- socketBufferHandler.getReadBuffer().get(b, off, remaining);
+ remaining = Math.min(remaining, len);
+ readBuffer.get(b, off, remaining);
+ if (log.isDebugEnabled()) {
+ log.debug("Socket: [" + this + "], Read from buffer: [" + remaining + "]");
+ }
// This may be sufficient to complete the request and we
// don't want to trigger another read since if there is no
// more data to read and this request takes a while to
@@ -871,21 +865,16 @@ public class Nio2Endpoint extends Abstra
// data that was just read
if (nRead > 0) {
socketBufferHandler.configureReadBufferForRead();
- if (nRead > len) {
- socketBufferHandler.getReadBuffer().get(b, off, len);
- } else {
- socketBufferHandler.getReadBuffer().get(b, off, nRead);
- }
+ nRead = Math.min(nRead, len);
+ readBuffer.get(b, off, nRead);
} else if (nRead == 0 && !block) {
readInterest = true;
- } else if (nRead == -1) {
- return -1;
}
if (log.isDebugEnabled()) {
log.debug("Socket: [" + this + "], Read: [" + nRead + "]");
}
- return (nRead > len) ? len : nRead;
+ 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=1755731&r1=1755730&r2=1755731&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Aug 10 12:38:31 2016
@@ -1141,13 +1141,9 @@ public class NioEndpoint extends Abstrac
int remaining = readBuffer.remaining();
// Is there enough data in the read buffer to satisfy this request?
- if (remaining >= len) {
- readBuffer.get(b, off, len);
- return len;
- }
-
// Copy what data there is in the read buffer to the byte array
if (remaining > 0) {
+ remaining = Math.min(remaining, len);
readBuffer.get(b, off, remaining);
return remaining;
/*
@@ -1167,16 +1163,10 @@ public class NioEndpoint extends Abstrac
// data that was just read
if (nRead > 0) {
socketBufferHandler.configureReadBufferForRead();
- if (nRead > len) {
- readBuffer.get(b, off, len);
- return len;
- } else {
- readBuffer.get(b, off, nRead);
- return nRead;
- }
- } else {
- return nRead;
+ nRead = Math.min(nRead, len);
+ readBuffer.get(b, off, nRead);
}
+ return nRead;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org