Java Code Examples for org.apache.tomcat.jni.Status#TIMEUP
The following examples show how to use
org.apache.tomcat.jni.Status#TIMEUP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AjpAprProcessor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Read at least the specified amount of bytes, and place them * in the input buffer. */ protected boolean readt(int n, boolean useAvailableData) throws IOException { if (useAvailableData && inputBuffer.remaining() == 0) { return false; } if (inputBuffer.capacity() - inputBuffer.limit() <= n - inputBuffer.remaining()) { inputBuffer.compact(); inputBuffer.limit(inputBuffer.position()); inputBuffer.position(0); } int nRead; while (inputBuffer.remaining() < n) { nRead = Socket.recvbb (socketWrapper.getSocket().longValue(), inputBuffer.limit(), inputBuffer.capacity() - inputBuffer.limit()); if (nRead > 0) { inputBuffer.limit(inputBuffer.limit() + nRead); } else { if ((-nRead) == Status.ETIMEDOUT || (-nRead) == Status.TIMEUP) { return false; } else { throw new IOException(sm.getString("ajpprocessor.failedread")); } } } return true; }
Example 2
Source File: AjpAprProcessor.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Read at least the specified amount of bytes, and place them * in the input buffer. */ protected boolean readt(int n, boolean useAvailableData) throws IOException { if (useAvailableData && inputBuffer.remaining() == 0) { return false; } if (inputBuffer.capacity() - inputBuffer.limit() <= n - inputBuffer.remaining()) { inputBuffer.compact(); inputBuffer.limit(inputBuffer.position()); inputBuffer.position(0); } int nRead; while (inputBuffer.remaining() < n) { nRead = Socket.recvbb (socketWrapper.getSocket().longValue(), inputBuffer.limit(), inputBuffer.capacity() - inputBuffer.limit()); if (nRead > 0) { inputBuffer.limit(inputBuffer.limit() + nRead); } else { if ((-nRead) == Status.ETIMEDOUT || (-nRead) == Status.TIMEUP) { return false; } else { throw new IOException(sm.getString("ajpprocessor.failedread")); } } } return true; }
Example 3
Source File: AprEndpoint.java From Tomcat8-Source-Read with MIT License | 4 votes |
private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException { if (closed) { throw new IOException(sm.getString("socket.apr.closed", getSocket())); } Lock readLock = getBlockingStatusReadLock(); WriteLock writeLock = getBlockingStatusWriteLock(); boolean readDone = false; int result = 0; readLock.lock(); try { if (getBlockingStatus() == block) { if (block) { Socket.timeoutSet(getSocket().longValue(), getReadTimeout() * 1000); } result = Socket.recvb(getSocket().longValue(), to, to.position(), to.remaining()); readDone = true; } } finally { readLock.unlock(); } if (!readDone) { writeLock.lock(); try { // Set the current settings for this socket setBlockingStatus(block); if (block) { Socket.timeoutSet(getSocket().longValue(), getReadTimeout() * 1000); } else { Socket.timeoutSet(getSocket().longValue(), 0); } // Downgrade the lock readLock.lock(); try { writeLock.unlock(); result = Socket.recvb(getSocket().longValue(), to, to.position(), to.remaining()); } finally { 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) { to.position(to.position() + result); return result; } else if (result == 0 || -result == Status.EAGAIN) { return 0; } else if ((-result) == Status.ETIMEDOUT || (-result) == Status.TIMEUP) { if (block) { 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 // to behave like a blocking read with a short timeout // on OSX rather than like a non-blocking read. If no // data is read, treat the resulting timeout like a // non-blocking read that returned no data. return 0; } } else if (-result == Status.APR_EOF) { return -1; } else if ((OS.IS_WIN32 || OS.IS_WIN64) && (-result == Status.APR_OS_START_SYSERR + 10053)) { // 10053 on Windows is connection aborted throw new EOFException(sm.getString("socket.apr.clientAbort")); } else { throw new IOException(sm.getString("socket.apr.read.error", Integer.valueOf(-result), getSocket(), this)); } }
Example 4
Source File: InternalAprInputBuffer.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
/** * Fill the internal buffer using data from the underlying input stream. * * @return false if at end of stream */ protected boolean fill() throws IOException { int nRead = 0; if (parsingHeader) { if (lastValid == buf.length) { throw new IllegalArgumentException (sm.getString("iib.requestheadertoolarge.error")); } bbuf.clear(); nRead = Socket.recvbb(socket, 0, buf.length - lastValid); if (nRead > 0) { bbuf.limit(nRead); bbuf.get(buf, pos, nRead); lastValid = pos + nRead; } else { if ((-nRead) == Status.EAGAIN) { return false; } else { throw new IOException(sm.getString("iib.failedread")); } } } else { if (buf.length - end < 4500) { // In this case, the request header was really large, so we allocate a // brand new one; the old one will get GCed when subsequent requests // clear all references buf = new byte[buf.length]; end = 0; } pos = end; lastValid = pos; bbuf.clear(); nRead = Socket.recvbb(socket, 0, buf.length - lastValid); if (nRead > 0) { bbuf.limit(nRead); bbuf.get(buf, pos, nRead); lastValid = pos + nRead; } else { if ((-nRead) == Status.ETIMEDOUT || (-nRead) == Status.TIMEUP) { throw new SocketTimeoutException(sm.getString("iib.failedread")); } else if (nRead == 0) { // APR_STATUS_IS_EOF, since native 1.1.22 return false; } else if (-nRead == Status.APR_EGENERAL && wrapper.isSecure()) { // Not entirely sure why this is necessary. Testing to date has not // identified any issues with this but log it so it can be tracked // if it is suspected of causing issues in the future. if (log.isDebugEnabled()) { log.debug(sm.getString("iib.apr.sslGeneralError", Long.valueOf(socket), wrapper)); } } else { throw new IOException(sm.getString("iib.failedread")); } } } return (nRead > 0); }
Example 5
Source File: InternalAprInputBuffer.java From tomcatsrc with Apache License 2.0 | 4 votes |
/** * Fill the internal buffer using data from the underlying input stream. * * @return false if at end of stream */ protected boolean fill() throws IOException { int nRead = 0; if (parsingHeader) { if (lastValid == buf.length) { throw new IllegalArgumentException (sm.getString("iib.requestheadertoolarge.error")); } bbuf.clear(); nRead = Socket.recvbb(socket, 0, buf.length - lastValid); if (nRead > 0) { bbuf.limit(nRead); bbuf.get(buf, pos, nRead); lastValid = pos + nRead; } else { if ((-nRead) == Status.EAGAIN) { return false; } else { throw new IOException(sm.getString("iib.failedread")); } } } else { if (buf.length - end < 4500) { // In this case, the request header was really large, so we allocate a // brand new one; the old one will get GCed when subsequent requests // clear all references buf = new byte[buf.length]; end = 0; } pos = end; lastValid = pos; bbuf.clear(); nRead = Socket.recvbb(socket, 0, buf.length - lastValid); if (nRead > 0) { bbuf.limit(nRead); bbuf.get(buf, pos, nRead); lastValid = pos + nRead; } else { if ((-nRead) == Status.ETIMEDOUT || (-nRead) == Status.TIMEUP) { throw new SocketTimeoutException(sm.getString("iib.failedread")); } else if (nRead == 0) { // APR_STATUS_IS_EOF, since native 1.1.22 return false; } else if (-nRead == Status.APR_EGENERAL && wrapper.isSecure()) { // Not entirely sure why this is necessary. Testing to date has not // identified any issues with this but log it so it can be tracked // if it is suspected of causing issues in the future. if (log.isDebugEnabled()) { log.debug(sm.getString("iib.apr.sslGeneralError", Long.valueOf(socket), wrapper)); } } else { throw new IOException(sm.getString("iib.failedread")); } } } return (nRead > 0); }