private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
@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; } }
/** * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress) */ @Override synchronized public DatagramChannel connect(SocketAddress address) throws IOException { // must open checkOpen(); // status must be un-connected. if (connected) { throw new IllegalStateException(); } // check the address InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address); try { begin(); IoBridge.connect(fd, inetSocketAddress.getAddress(), inetSocketAddress.getPort()); } catch (ConnectException e) { // ConnectException means connect fail, not exception } finally { end(true); } // set the connected address. connectAddress = inetSocketAddress; connected = true; isBound = true; return this; }
@Override public SocketAddress receive(ByteBuffer target) throws IOException { target.checkWritable(); checkOpen(); if (!isBound) { return null; } SocketAddress retAddr = null; try { begin(); // receive real data packet, (not peek) synchronized (readLock) { boolean loop = isBlocking(); if (!target.isDirect()) { retAddr = receiveImpl(target, loop); } else { retAddr = receiveDirectImpl(target, loop); } } } catch (InterruptedIOException e) { // this line used in Linux return null; } finally { end(retAddr != null); } return retAddr; }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
private void checkOpenConnected() throws IOException { checkOpen(); if (!isConnected()) { throw new NotYetConnectedException(); } }
@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; } }
@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; } }
@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; } }
@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; } }
/** * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress) */ @Override synchronized public DatagramChannel connect(SocketAddress address) throws IOException { // must open checkOpen(); // status must be un-connected. if (connected) { throw new IllegalStateException(); } // check the address InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address); try { begin(); IoBridge.connect(fd, inetSocketAddress.getAddress(), inetSocketAddress.getPort()); } catch (ConnectException e) { // ConnectException means connect fail, not exception } finally { end(true); } // set the connected address. connectAddress = inetSocketAddress; connected = true; isBound = true; return this; }
/** * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress) */ @Override synchronized public DatagramChannel connect(SocketAddress address) throws IOException { // must open checkOpen(); // status must be un-connected. if (connected) { throw new IllegalStateException(); } // check the address InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address); try { begin(); IoBridge.connect(fd, inetSocketAddress.getAddress(), inetSocketAddress.getPort()); } catch (ConnectException e) { // ConnectException means connect fail, not exception } finally { end(true); } // set the connected address. connectAddress = inetSocketAddress; connected = true; isBound = true; return this; }
/** * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress) */ @Override synchronized public DatagramChannel connect(SocketAddress address) throws IOException { // must open checkOpen(); // status must be un-connected. if (connected) { throw new IllegalStateException(); } // check the address InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address); try { begin(); IoBridge.connect(fd, inetSocketAddress.getAddress(), inetSocketAddress.getPort()); } catch (ConnectException e) { // ConnectException means connect fail, not exception } finally { end(true); } // set the connected address. connectAddress = inetSocketAddress; connected = true; isBound = true; return this; }
@Override public SocketAddress receive(ByteBuffer target) throws IOException { target.checkWritable(); checkOpen(); if (!isBound) { return null; } SocketAddress retAddr = null; try { begin(); // receive real data packet, (not peek) synchronized (readLock) { boolean loop = isBlocking(); if (!target.isDirect()) { retAddr = receiveImpl(target, loop); } else { retAddr = receiveDirectImpl(target, loop); } } } catch (InterruptedIOException e) { // this line used in Linux return null; } finally { end(retAddr != null); } return retAddr; }
@Override public SocketAddress receive(ByteBuffer target) throws IOException { target.checkWritable(); checkOpen(); if (!isBound) { return null; } SocketAddress retAddr = null; try { begin(); // receive real data packet, (not peek) synchronized (readLock) { boolean loop = isBlocking(); if (!target.isDirect()) { retAddr = receiveImpl(target, loop); } else { retAddr = receiveDirectImpl(target, loop); } } } catch (InterruptedIOException e) { // this line used in Linux return null; } finally { end(retAddr != null); } return retAddr; }
@Override public SocketAddress receive(ByteBuffer target) throws IOException { target.checkWritable(); checkOpen(); if (!isBound) { return null; } SocketAddress retAddr = null; try { begin(); // receive real data packet, (not peek) synchronized (readLock) { boolean loop = isBlocking(); if (!target.isDirect()) { retAddr = receiveImpl(target, loop); } else { retAddr = receiveDirectImpl(target, loop); } } } catch (InterruptedIOException e) { // this line used in Linux return null; } finally { end(retAddr != null); } return retAddr; }