Attempts to read some data into the input buffer. @param block Should blocking IO be used when filling the input buffer @return true if more data was added to the input buffer otherwise false @throws IOException if an IO error occurs while filling the input buffer
(boolean block)
| 751 | * @throws IOException if an IO error occurs while filling the input buffer |
| 752 | */ |
| 753 | private boolean fill(boolean block) throws IOException { |
| 754 | |
| 755 | if (log.isTraceEnabled()) { |
| 756 | log.trace("Before fill(): parsingHeader: [" + parsingHeader + "], parsingRequestLine: [" + |
| 757 | parsingRequestLine + "], parsingRequestLinePhase: [" + parsingRequestLinePhase + |
| 758 | "], parsingRequestLineStart: [" + parsingRequestLineStart + "], byteBuffer.position(): [" + |
| 759 | byteBuffer.position() + "], byteBuffer.limit(): [" + byteBuffer.limit() + "], end: [" + end + "]"); |
| 760 | } |
| 761 | |
| 762 | if (parsingHeader) { |
| 763 | if (byteBuffer.limit() >= headerBufferSize) { |
| 764 | if (parsingRequestLine) { |
| 765 | // Avoid unknown protocol triggering an additional error |
| 766 | request.protocol().setString(Constants.HTTP_11); |
| 767 | } |
| 768 | throw new IllegalArgumentException(sm.getString("iib.requestheadertoolarge.error")); |
| 769 | } |
| 770 | } else { |
| 771 | byteBuffer.limit(end).position(end); |
| 772 | } |
| 773 | |
| 774 | int nRead; |
| 775 | int mark = byteBuffer.position(); |
| 776 | try { |
| 777 | if (byteBuffer.position() < byteBuffer.limit()) { |
| 778 | byteBuffer.position(byteBuffer.limit()); |
| 779 | } |
| 780 | byteBuffer.limit(byteBuffer.capacity()); |
| 781 | SocketWrapperBase<?> socketWrapper = this.wrapper; |
| 782 | if (socketWrapper != null) { |
| 783 | nRead = socketWrapper.read(block, byteBuffer); |
| 784 | } else { |
| 785 | throw new CloseNowException(sm.getString("iib.eof.error")); |
| 786 | } |
| 787 | } finally { |
| 788 | // Ensure that the buffer limit and position are returned to a |
| 789 | // consistent "ready for read" state if an error occurs during in |
| 790 | // the above code block. |
| 791 | // Some error conditions can result in the position being reset to |
| 792 | // zero which also invalidates the mark. |
| 793 | // https://bz.apache.org/bugzilla/show_bug.cgi?id=65677 |
| 794 | if (byteBuffer.position() >= mark) { |
| 795 | // // Position and mark are consistent. Assume a read (possibly |
| 796 | // of zero bytes) has occurred. |
| 797 | byteBuffer.limit(byteBuffer.position()); |
| 798 | byteBuffer.position(mark); |
| 799 | } else { |
| 800 | // Position and mark are inconsistent. Set position and limit to |
| 801 | // zero so effectively no data is reported as read. |
| 802 | byteBuffer.position(0); |
| 803 | byteBuffer.limit(0); |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | if (log.isTraceEnabled()) { |
| 808 | log.trace("Received [" + new String(byteBuffer.array(), byteBuffer.position(), byteBuffer.remaining(), |
| 809 | StandardCharsets.ISO_8859_1) + "]"); |
| 810 | } |