Java Code Examples for org.apache.tomcat.jni.Socket#recvbb()

The following examples show how to use org.apache.tomcat.jni.Socket#recvbb() . 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 6 votes vote down vote up
/**
 * Read at least the specified amount of bytes, and place them
 * in the input buffer.
 */
protected boolean read(int n)
    throws IOException {

    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 {
            throw new IOException(sm.getString("ajpprocessor.failedread"));
        }
    }

    return true;

}
 
Example 2
Source File: AjpAprProcessor.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Read at least the specified amount of bytes, and place them
 * in the input buffer.
 */
protected boolean read(int n)
    throws IOException {

    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 {
            throw new IOException(sm.getString("ajpprocessor.failedread"));
        }
    }

    return true;

}
 
Example 3
Source File: AjpAprProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: AjpAprProcessor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: InternalAprInputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * 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 6
Source File: InternalAprInputBuffer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}