/** * @see java.net.DatagramSocket#isConnected() */ @Override public boolean isConnected() { return channelImpl.isConnected(); }
private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop) throws IOException { SocketAddress retAddr = null; DatagramPacket receivePacket = new DatagramPacket(EmptyArray.BYTE, 0); int oldposition = target.position(); int received = 0; do { received = IoBridge.recvfrom(false, fd, target, 0, receivePacket, isConnected()); if (receivePacket != null && receivePacket.getAddress() != null) { // copy the data of received packet if (received > 0) { target.position(oldposition + received); } retAddr = receivePacket.getSocketAddress(); break; } } while (loop); return retAddr; }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
private SocketAddress receiveImpl(ByteBuffer target, boolean loop) throws IOException { SocketAddress retAddr = null; DatagramPacket receivePacket; int oldposition = target.position(); int received = 0; // TODO: disallow mapped buffers and lose this conditional? if (target.hasArray()) { receivePacket = new DatagramPacket(target.array(), target.position() + target.arrayOffset(), target.remaining()); } else { receivePacket = new DatagramPacket(new byte[target.remaining()], target.remaining()); } do { received = IoBridge.recvfrom(false, fd, receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(), 0, receivePacket, isConnected()); if (receivePacket != null && receivePacket.getAddress() != null) { if (received > 0) { if (target.hasArray()) { target.position(oldposition + received); } else { // copy the data of received packet target.put(receivePacket.getData(), 0, received); } } retAddr = receivePacket.getSocketAddress(); break; } } while (loop); return retAddr; }
@Override public int send(ByteBuffer source, SocketAddress socketAddress) throws IOException { checkNotNull(source); checkOpen(); InetSocketAddress isa = (InetSocketAddress) socketAddress; if (isa.getAddress() == null) { throw new IOException(); } if (isConnected() && !connectAddress.equals(isa)) { throw new IllegalArgumentException("Connected to " + connectAddress + ", not " + socketAddress); } synchronized (writeLock) { int sendCount = 0; try { begin(); int oldPosition = source.position(); sendCount = IoBridge.sendto(fd, source, 0, isa.getAddress(), isa.getPort()); if (sendCount > 0) { source.position(oldPosition + sendCount); } isBound = true; } finally { end(sendCount >= 0); } return sendCount; } }
private int readImpl(ByteBuffer dst) throws IOException { synchronized (readLock) { int readCount = 0; try { begin(); readCount = IoBridge.recvfrom(false, fd, dst, 0, null, isConnected()); } catch (InterruptedIOException e) { // InterruptedIOException will be thrown when timeout. return 0; } finally { end(readCount > 0); } return readCount; } }
/** * @see java.nio.channels.DatagramChannel#disconnect() */ @Override synchronized public DatagramChannel disconnect() throws IOException { if (!isConnected() || !isOpen()) { return this; } connected = false; connectAddress = null; try { Libcore.os.connect(fd, InetAddress.UNSPECIFIED, 0); } catch (ErrnoException errnoException) { throw errnoException.rethrowAsIOException(); } if (socket != null) { socket.disconnect(); } return this; }
/** * @see java.net.DatagramSocket#isConnected() */ @Override public boolean isConnected() { return channelImpl.isConnected(); }
/** * @see java.net.DatagramSocket#isConnected() */ @Override public boolean isConnected() { return channelImpl.isConnected(); }
/** * @see java.net.DatagramSocket#isConnected() */ @Override public boolean isConnected() { return channelImpl.isConnected(); }
/** * @see java.net.DatagramSocket#isConnected() */ @Override public boolean isConnected() { return channelImpl.isConnected(); }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }