(SocketChannel source, SocketChannel destination)
| 232 | } |
| 233 | |
| 234 | private void forward(SocketChannel source, SocketChannel destination) { |
| 235 | ByteBuffer buffer = ByteBuffer.allocate(8192); |
| 236 | try { |
| 237 | while (source.isOpen() && destination.isOpen()) { |
| 238 | buffer.clear(); |
| 239 | int read = source.read(buffer); |
| 240 | if (read == -1) { |
| 241 | break; |
| 242 | } |
| 243 | buffer.flip(); |
| 244 | writeFully(destination, buffer); |
| 245 | } |
| 246 | } catch (IOException e) { |
| 247 | // 连接已断开,关闭通道 |
| 248 | closeQuietly(source); |
| 249 | closeQuietly(destination); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | private void sendResponse(SocketChannel channel, byte status) throws IOException { |
| 254 | ByteBuffer response = ByteBuffer.allocate(10); |
no test coverage detected