return read(targets, 0, targets.length);
public InetSocketAddress readFromAddress () throws IOException { DatagramChannel datagramChannel = this.datagramChannel; if (datagramChannel == null) throw new SocketException("Connection is closed."); lastCommunicationTime = System.currentTimeMillis(); if(!datagramChannel.isConnected()) return (InetSocketAddress)datagramChannel.receive(readBuffer); // always null on Android >= 5.0 datagramChannel.read(readBuffer); return connectedAddress; }
private void handshake(DatagramChannel tunnel) throws Exception { // To build a secured tunnel, we should perform mutual authentication // and exchange session keys for encryption. To keep things simple in // this demo, we just send the shared secret in plaintext and wait // for the server to send the parameters. // Allocate the buffer for handshaking. ByteBuffer packet = ByteBuffer.allocate(1024); // Control messages always start with zero. packet.put((byte) 0).put(mSharedSecret).flip(); // Send the secret several times in case of packet loss. for (int i = 0; i < 3; ++i) { packet.position(0); tunnel.write(packet); } packet.clear(); // Wait for the parameters within a limited time. for (int i = 0; i < 50; ++i) { Thread.sleep(100); // Normally we should not receive random packets. int length = tunnel.read(packet); if (length > 0 && packet.get(0) == 0) { configure(new String(packet.array(), 1, length - 1).trim()); return; } } throw new IllegalStateException("Timed out"); }
length = tunnel.read(packet); if (length > 0) {
/** * Reads a datagram into the supplied buffer. * * @return the number of bytes read. */ protected int readDatagram (ByteBuffer buf) throws IOException { return _datagramChannel.read(buf); }
@Override public int read(ByteBuffer dst) throws IOException { return channel.read(dst); }
@Override protected int channelRead(ByteBuffer buffer) throws IOException { return mDatagramChannel.read(buffer); }
@Override public int read(final byte[] byteArray, final int offset, final int length) throws IOException { return this.dc.read(ByteBuffer.wrap(byteArray, offset, length)); }
@Override public int receive(byte[] buf, int off, int len, int waitMillis) throws IOException { // MEDIA-48: DTLS handshake thread does not terminate // https://telestax.atlassian.net/browse/MEDIA-48 if (this.hasTimeout()) { throw new IllegalStateException("Handshake is taking too long! (>" + MAX_DELAY + "ms"); } ByteBuffer buffer = ByteBuffer.wrap(buf, off, len); return this.channel.read(buffer); }
@Override public int receive(byte[] buf, int off, int len, int waitMillis) throws IOException { // MEDIA-48: DTLS handshake thread does not terminate // https://telestax.atlassian.net/browse/MEDIA-48 if (this.hasTimeout()) { throw new IllegalStateException("Handshake is taking too long! (>" + MAX_DELAY + "ms"); } ByteBuffer buffer = ByteBuffer.wrap(buf, off, len); return this.channel.read(buffer); }
public Integer call() throws IOException { try { return channel.read(dst); } catch (ClosedChannelException e) { throw Util.initCause( new AsynchronousCloseException(), e); } } }); }
public Integer call() throws IOException { try { return channel.read(dst); } catch (ClosedChannelException e) { throw Util.initCause( new AsynchronousCloseException(), e); } } }); }
public Integer call() throws IOException { try { return channel.read(dst); } catch (ClosedChannelException e) { throw Util.initCause( new AsynchronousCloseException(), e); } } }); }
public int read(ByteBuffer dst) throws IOException { final Object context = IoTraceHandler.datagramReadBegin(); final int bytes = delegate.read(dst); if(bytes>0) { IoTraceHandler.datagramReadEnd(context, getRemoteAddress(), bytes); } return bytes; }
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { final Object context = IoTraceHandler.datagramReadBegin(); final long bytes = delegate.read(dsts, offset, length); if(bytes>0) { IoTraceHandler.datagramReadEnd(context, getRemoteAddress(), bytes); } return bytes; }
@Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); try { return socketChannel.read(buf); } catch (IOException ioe) { throw Py.IOError(ioe); } }
@Test(expected = NetworkReactiveAuditException.class) public void read_b() throws IOException { Assume.assumeTrue(IOTestTools.isNetworkConnected()); ByteBuffer buf = ByteBuffer.allocate(10); try (DatagramChannel w = channel.get()) { TestTools.strict.commit(); w.read(buf); } }
@Test(expected = NetworkReactiveAuditException.class) public void write_b() throws IOException { Assume.assumeTrue(IOTestTools.isNetworkConnected()); ByteBuffer buf = ByteBuffer.allocate(10); try (DatagramChannel w = channel.get()) { TestTools.strict.commit(); w.read(buf); } }
@Test(expected = java.nio.channels.NotYetConnectedException.class) public void read_nb() throws IOException { Assume.assumeTrue(IOTestTools.isNetworkConnected()); ByteBuffer buf = ByteBuffer.allocate(10); try (DatagramChannel w = channel.get()) { w.configureBlocking(false); TestTools.strict.commit(); w.read(buf); } }
@Test(expected = java.nio.channels.NotYetConnectedException.class) public void write_nb() throws IOException { Assume.assumeTrue(IOTestTools.isNetworkConnected()); ByteBuffer buf = ByteBuffer.allocate(10); try (DatagramChannel w = channel.get()) { w.configureBlocking(false); TestTools.strict.commit(); w.read(buf); } } }