Skip to content

Commit

Permalink
No need to return value from doWrite so remove it allowing slightly
Browse files Browse the repository at this point in the history
simpler code.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1651046 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jan 12, 2015
1 parent 73e158f commit 0b73ddc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
12 changes: 4 additions & 8 deletions java/org/apache/tomcat/util/net/AprEndpoint.java
Expand Up @@ -2509,7 +2509,7 @@ public void close() {




@Override @Override
protected int doWrite(boolean block) throws IOException { protected void doWrite(boolean block) throws IOException {
if (closed) { if (closed) {
throw new IOException(sm.getString("apr.closed", getSocket())); throw new IOException(sm.getString("apr.closed", getSocket()));
} }
Expand All @@ -2520,7 +2520,7 @@ protected int doWrite(boolean block) throws IOException {
readLock.lock(); readLock.lock();
try { try {
if (getBlockingStatus() == block) { if (getBlockingStatus() == block) {
return doWriteInternal(); doWriteInternal();
} }
} finally { } finally {
readLock.unlock(); readLock.unlock();
Expand All @@ -2540,7 +2540,7 @@ protected int doWrite(boolean block) throws IOException {
readLock.lock(); readLock.lock();
try { try {
writeLock.unlock(); writeLock.unlock();
return doWriteInternal(); doWriteInternal();
} finally { } finally {
readLock.unlock(); readLock.unlock();
} }
Expand All @@ -2554,13 +2554,12 @@ protected int doWrite(boolean block) throws IOException {
} }




private int doWriteInternal() throws IOException { private void doWriteInternal() throws IOException {
if (!writeBufferFlipped) { if (!writeBufferFlipped) {
socketWriteBuffer.flip(); socketWriteBuffer.flip();
writeBufferFlipped = true; writeBufferFlipped = true;
} }


int written = 0;
int thisTime; int thisTime;


do { do {
Expand Down Expand Up @@ -2599,7 +2598,6 @@ private int doWriteInternal() throws IOException {
throw new IOException(sm.getString("socket.apr.write.error", throw new IOException(sm.getString("socket.apr.write.error",
Integer.valueOf(-thisTime), getSocket(), this)); Integer.valueOf(-thisTime), getSocket(), this));
} }
written += thisTime;
socketWriteBuffer.position(socketWriteBuffer.position() + thisTime); socketWriteBuffer.position(socketWriteBuffer.position() + thisTime);
} while ((thisTime > 0 || getBlockingStatus()) && socketWriteBuffer.hasRemaining()); } while ((thisTime > 0 || getBlockingStatus()) && socketWriteBuffer.hasRemaining());


Expand All @@ -2611,8 +2609,6 @@ private int doWriteInternal() throws IOException {
// write further up the stack. This is to ensure the socket is only // write further up the stack. This is to ensure the socket is only
// registered for write once as both container and user code can trigger // registered for write once as both container and user code can trigger
// write registration. // write registration.

return written;
} }




Expand Down
5 changes: 1 addition & 4 deletions java/org/apache/tomcat/util/net/Nio2Endpoint.java
Expand Up @@ -1153,18 +1153,15 @@ protected void writeNonBlocking(byte[] buf, int off, int len) throws IOException
* blocking case * blocking case
*/ */
@Override @Override
protected int doWrite(boolean block) throws IOException { protected void doWrite(boolean block) throws IOException {
int result = -1;
try { try {
socketWriteBuffer.flip(); socketWriteBuffer.flip();
result = socketWriteBuffer.remaining();
while (socketWriteBuffer.hasRemaining()) { while (socketWriteBuffer.hasRemaining()) {
if (getSocket().write(socketWriteBuffer).get(getTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) { if (getSocket().write(socketWriteBuffer).get(getTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) {
throw new EOFException(sm.getString("iob.failedwrite")); throw new EOFException(sm.getString("iob.failedwrite"));
} }
} }
socketWriteBuffer.clear(); socketWriteBuffer.clear();
return result;
} catch (ExecutionException e) { } catch (ExecutionException e) {
if (e.getCause() instanceof IOException) { if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause(); throw (IOException) e.getCause();
Expand Down
8 changes: 2 additions & 6 deletions java/org/apache/tomcat/util/net/NioEndpoint.java
Expand Up @@ -1512,14 +1512,12 @@ private int fillReadBuffer(boolean block) throws IOException {




@Override @Override
protected synchronized int doWrite(boolean block) protected synchronized void doWrite(boolean block) throws IOException {
throws IOException {
if (!writeBufferFlipped) { if (!writeBufferFlipped) {
socketWriteBuffer.flip(); socketWriteBuffer.flip();
writeBufferFlipped = true; writeBufferFlipped = true;
} }


int written = 0;
long writeTimeout = getWriteTimeout(); long writeTimeout = getWriteTimeout();
Selector selector = null; Selector selector = null;
try { try {
Expand All @@ -1528,7 +1526,7 @@ protected synchronized int doWrite(boolean block)
// Ignore // Ignore
} }
try { try {
written = pool.write(socketWriteBuffer, getSocket(), selector, writeTimeout, block); pool.write(socketWriteBuffer, getSocket(), selector, writeTimeout, block);
// Make sure we are flushed // Make sure we are flushed
do { do {
if (getSocket().flush(true, selector, writeTimeout)) break; if (getSocket().flush(true, selector, writeTimeout)) break;
Expand All @@ -1546,8 +1544,6 @@ protected synchronized int doWrite(boolean block)
// write further up the stack. This is to ensure the socket is only // write further up the stack. This is to ensure the socket is only
// registered for write once as both container and user code can trigger // registered for write once as both container and user code can trigger
// write registration. // write registration.

return written;
} }




Expand Down
8 changes: 2 additions & 6 deletions java/org/apache/tomcat/util/net/SocketWrapperBase.java
Expand Up @@ -372,9 +372,7 @@ protected void writeNonBlocking(byte[] buf, int off, int len) throws IOException
len = len - thisTime; len = len - thisTime;
while (socketWriteBuffer.remaining() == 0) { while (socketWriteBuffer.remaining() == 0) {
off = off + thisTime; off = off + thisTime;
if (doWrite(false) == 0) { doWrite(false);
break;
}
if (writeBufferFlipped) { if (writeBufferFlipped) {
thisTime = 0; thisTime = 0;
} else { } else {
Expand Down Expand Up @@ -484,12 +482,10 @@ protected boolean flushNonBlocking() throws IOException {
* *
* @param block Should the write be blocking or not? * @param block Should the write be blocking or not?
* *
* @return The number of bytes written
*
* @throws IOException If an I/O error such as a timeout occurs during the * @throws IOException If an I/O error such as a timeout occurs during the
* write * write
*/ */
protected abstract int doWrite(boolean block) throws IOException; protected abstract void doWrite(boolean block) throws IOException;




protected void addToBuffers(byte[] buf, int offset, int length) { protected void addToBuffers(byte[] buf, int offset, int length) {
Expand Down

0 comments on commit 0b73ddc

Please sign in to comment.