(boolean block)
| 1032 | } |
| 1033 | |
| 1034 | final boolean flush(boolean block) throws IOException { |
| 1035 | writeLock.lock(); |
| 1036 | try { |
| 1037 | /* |
| 1038 | * Need to ensure that there is exactly one call to flush even when there is no data to write. Too few |
| 1039 | * calls (i.e. zero) and the end of stream message is not sent for a completed asynchronous write. Too |
| 1040 | * many calls and the end of stream message is sent too soon and trailer headers are not sent. |
| 1041 | */ |
| 1042 | boolean dataInBuffer = buffer.position() > 0; |
| 1043 | boolean flushed = false; |
| 1044 | |
| 1045 | if (dataInBuffer) { |
| 1046 | dataInBuffer = flush(false, block); |
| 1047 | flushed = true; |
| 1048 | } |
| 1049 | |
| 1050 | if (dataInBuffer) { |
| 1051 | dataLeft = true; |
| 1052 | } else { |
| 1053 | if (writeBuffer.isEmpty()) { |
| 1054 | // Both buffer and writeBuffer are empty. |
| 1055 | if (flushed) { |
| 1056 | dataLeft = false; |
| 1057 | } else { |
| 1058 | dataLeft = flush(false, block); |
| 1059 | } |
| 1060 | } else { |
| 1061 | dataLeft = writeBuffer.write(this, block); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | return dataLeft; |
| 1066 | } finally { |
| 1067 | writeLock.unlock(); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | private boolean flush(boolean writeInProgress, boolean block) throws IOException { |
| 1072 | writeLock.lock(); |
no test coverage detected