Author: markt
Date: Wed Mar 13 20:59:17 2013
New Revision: 1456125
URL: http://svn.apache.org/r1456125
Log:
Check this in before I start to work on the APR/native SSL issue
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java?rev=1456125&r1=1456124&r2=1456125&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java
(original)
+++
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java
Wed Mar 13 20:59:17 2013
@@ -47,62 +47,75 @@ public class AprServletOutputStream exte
Lock readLock = wrapper.getBlockingStatusReadLock();
WriteLock writeLock = wrapper.getBlockingStatusWriteLock();
- boolean writeDone = false;
- int result = 0;
try {
readLock.lock();
if (wrapper.getBlockingStatus() == block) {
if (closed) {
throw new IOException(sm.getString("apr.closed"));
}
- result = Socket.send(socket, b, off, len);
- writeDone = true;
+ return doWriteInternal(b, off, len);
}
} finally {
readLock.unlock();
}
- if (!writeDone) {
+ try {
+ writeLock.lock();
+ // Set the current settings for this socket
+ wrapper.setBlockingStatus(block);
+ if (block) {
+ Socket.timeoutSet(socket, endpoint.getSoTimeout() * 1000);
+ } else {
+ Socket.timeoutSet(socket, 0);
+ }
+
+ // Downgrade the lock
try {
- writeLock.lock();
- wrapper.setBlockingStatus(block);
- // Set the current settings for this socket
- Socket.optSet(socket, Socket.APR_SO_NONBLOCK, (block ? -1 :
0));
- // Downgrade the lock
- try {
- readLock.lock();
- writeLock.unlock();
- if (closed) {
- throw new IOException(sm.getString("apr.closed"));
- }
- result = Socket.send(socket, b, off, len);
- } finally {
- readLock.unlock();
+ readLock.lock();
+ writeLock.unlock();
+ if (closed) {
+ throw new IOException(sm.getString("apr.closed"));
}
+ return doWriteInternal(b, off, len);
} finally {
- // Should have been released above but may not have been on
some
- // exception paths
- if (writeLock.isHeldByCurrentThread()) {
- writeLock.unlock();
- }
+ readLock.unlock();
+ }
+ } finally {
+ // Should have been released above but may not have been on some
+ // exception paths
+ if (writeLock.isHeldByCurrentThread()) {
+ writeLock.unlock();
}
}
+ }
+
- if (result >= 0) {
- if (result < len) {
+ private int doWriteInternal(byte[] b, int off, int len) throws IOException
{
+
+ int start = off;
+ int left = len;
+ int written;
+
+ do {
+ written = Socket.send(socket, b, start, left);
+ if (Status.APR_STATUS_IS_EAGAIN(-written)) {
endpoint.getPoller().add(socket, -1, false, true);
+ written = 0;
+ } else if (written < 0) {
+ throw new IOException(sm.getString("apr.write.error",
+ Integer.valueOf(-written)));
}
- return result;
- } else if (-result == Status.EAGAIN) {
+ start += written;
+ left -= written;
+ } while (written > 0 && left > 0);
+
+ if (left > 0) {
endpoint.getPoller().add(socket, -1, false, true);
- return 0;
}
-
- throw new IOException(sm.getString("apr.write.error",
- Integer.valueOf(-result)));
-
+ return len - left;
}
+
@Override
protected void doFlush() throws IOException {
// TODO Auto-generated method stub
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]