(DatagramSocket socket, DatagramChannel channel, loopback_t loopback, boolean fromClient)
| 116 | } |
| 117 | |
| 118 | public static NetworkPacket receiveNetworkPacket(DatagramSocket socket, DatagramChannel channel, loopback_t loopback, boolean fromClient) { |
| 119 | NetworkPacket result = receiveNetworkPacketLoopback(loopback, fromClient); |
| 120 | |
| 121 | if (result != null) { |
| 122 | return result; |
| 123 | } |
| 124 | |
| 125 | if (socket == null) // why? |
| 126 | return null; |
| 127 | |
| 128 | try { |
| 129 | byte[] bytes = new byte[MAX_MSGLEN]; |
| 130 | ByteBuffer receiveBuffer = ByteBuffer.wrap(bytes); |
| 131 | |
| 132 | InetSocketAddress srcSocket = (InetSocketAddress) channel.receive(receiveBuffer); |
| 133 | if (srcSocket == null) |
| 134 | return null; |
| 135 | |
| 136 | if (receiveBuffer.position() > MAX_MSGLEN) // how it is possible? |
| 137 | return null; |
| 138 | |
| 139 | return NetworkPacket.fromSocket(fromClient, bytes, receiveBuffer.position(), srcSocket.getAddress().getAddress(), srcSocket.getPort()); |
| 140 | |
| 141 | } catch (Exception e) { |
| 142 | return null; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | |
| 147 | /** |
no test coverage detected