(byte [] data)
| 39 | } |
| 40 | |
| 41 | void |
| 42 | send(byte [] data) throws IOException { |
| 43 | SocketChannel channel = (SocketChannel) key.channel(); |
| 44 | verboseLog("TCP write", channel.socket().getLocalSocketAddress(), |
| 45 | channel.socket().getRemoteSocketAddress(), data); |
| 46 | byte [] lengthArray = new byte[2]; |
| 47 | lengthArray[0] = (byte)(data.length >>> 8); |
| 48 | lengthArray[1] = (byte)(data.length & 0xFF); |
| 49 | ByteBuffer [] buffers = new ByteBuffer[2]; |
| 50 | buffers[0] = ByteBuffer.wrap(lengthArray); |
| 51 | buffers[1] = ByteBuffer.wrap(data); |
| 52 | int nsent = 0; |
| 53 | key.interestOps(SelectionKey.OP_WRITE); |
| 54 | try { |
| 55 | while (nsent < data.length + 2) { |
| 56 | if (key.isWritable()) { |
| 57 | long n = channel.write(buffers); |
| 58 | if (n < 0) |
| 59 | throw new EOFException(); |
| 60 | nsent += (int) n; |
| 61 | if (nsent < data.length + 2 && |
| 62 | System.currentTimeMillis() > endTime) |
| 63 | throw new SocketTimeoutException(); |
| 64 | } else |
| 65 | blockUntil(key, endTime); |
| 66 | } |
| 67 | } |
| 68 | finally { |
| 69 | if (key.isValid()) |
| 70 | key.interestOps(0); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | private byte [] |
| 75 | _recv(int length) throws IOException { |
no test coverage detected