(InetSocketAddress addr)
| 48 | } |
| 49 | |
| 50 | private void |
| 51 | bind_random(InetSocketAddress addr) throws IOException |
| 52 | { |
| 53 | if (prng_initializing) { |
| 54 | try { |
| 55 | Thread.sleep(2); |
| 56 | } |
| 57 | catch (InterruptedException e) { |
| 58 | } |
| 59 | if (prng_initializing) |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | DatagramChannel channel = (DatagramChannel) key.channel(); |
| 64 | InetSocketAddress temp; |
| 65 | |
| 66 | for (int i = 0; i < 1024; i++) { |
| 67 | try { |
| 68 | int port = prng.nextInt(EPHEMERAL_RANGE) + |
| 69 | EPHEMERAL_START; |
| 70 | if (addr != null) |
| 71 | temp = new InetSocketAddress(addr.getAddress(), |
| 72 | port); |
| 73 | else |
| 74 | temp = new InetSocketAddress(port); |
| 75 | channel.socket().bind(temp); |
| 76 | bound = true; |
| 77 | return; |
| 78 | } |
| 79 | catch (SocketException e) { |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | bind(SocketAddress addr) throws IOException { |
no test coverage detected