private static void validateSufficientSocketBufferLengths(final Context ctx) { try (final DatagramChannel probe = DatagramChannel.open()) { final int defaultSoSndBuf = probe.getOption(StandardSocketOptions.SO_SNDBUF); probe.setOption(StandardSocketOptions.SO_SNDBUF, Integer.MAX_VALUE); final int maxSoSndBuf = probe.getOption(StandardSocketOptions.SO_SNDBUF); if (maxSoSndBuf < Configuration.SOCKET_SNDBUF_LENGTH) { System.err.format( "WARNING: Could not get desired SO_SNDBUF: attempted=%d, actual=%d\n", Configuration.SOCKET_SNDBUF_LENGTH, maxSoSndBuf); } probe.setOption(StandardSocketOptions.SO_RCVBUF, Integer.MAX_VALUE); final int maxSoRcvBuf = probe.getOption(StandardSocketOptions.SO_RCVBUF); if (maxSoRcvBuf < Configuration.SOCKET_RCVBUF_LENGTH) { System.err.format( "WARNING: Could not get desired SO_RCVBUF: attempted=%d, actual=%d\n", Configuration.SOCKET_RCVBUF_LENGTH, maxSoRcvBuf); } final int soSndBuf = (0 == Configuration.SOCKET_SNDBUF_LENGTH) ? defaultSoSndBuf : Configuration.SOCKET_SNDBUF_LENGTH; if (ctx.mtuLength() > soSndBuf) { throw new ConfigurationException( String.format( "MTU greater than socket SO_SNDBUF: mtuLength=%d, SO_SNDBUF=%d", ctx.mtuLength(), soSndBuf)); } } catch (final IOException ex) { throw new RuntimeException(String.format("probe socket: %s", ex.toString()), ex); } }