public DatagramChannelImpl(SelectorProvider sp, FileDescriptor fd) throws IOException { super(sp); this.family = Net.isIPv6Available() ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; this.fd = fd; this.fdVal = IOUtil.fdVal(fd); this.state = ST_UNCONNECTED; this.localAddress = Net.localAddress(fd); }
static void load() { synchronized (Util.class) { if (loaded) return; loaded = true; java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("net")); java.security.AccessController.doPrivileged(new sun.security.action.LoadLibraryAction("nio")); // IOUtil must be initialized; Its native methods are called from // other places in native nio code so they must be set up. IOUtil.initIDs(); } }
public DatagramChannelImpl(SelectorProvider sp) throws IOException { super(sp); ResourceManager.beforeUdpCreate(); try { this.family = Net.isIPv6Available() ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; this.fd = Net.socket(family, false); this.fdVal = IOUtil.fdVal(fd); this.state = ST_UNCONNECTED; } catch (IOException ioe) { ResourceManager.afterUdpClose(); throw ioe; } }
public DatagramChannelImpl(SelectorProvider sp, ProtocolFamily family) throws IOException { super(sp); if ((family != StandardProtocolFamily.INET) && (family != StandardProtocolFamily.INET6)) { if (family == null) throw new NullPointerException("'family' is null"); else throw new UnsupportedOperationException("Protocol family not supported"); } if (family == StandardProtocolFamily.INET6) { if (!Net.isIPv6Available()) { throw new UnsupportedOperationException("IPv6 not available"); } } this.family = family; this.fd = Net.socket(family, false); this.fdVal = IOUtil.fdVal(fd); this.state = ST_UNCONNECTED; }
public long read(ByteBuffer[] dsts) throws IOException { if (dsts == null) throw new NullPointerException(); ensureOpen(); synchronized (lock) { long n = 0; try { begin(); if (!isOpen()) return 0; thread = NativeThread.current(); do { n = IOUtil.read(fd, dsts, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { thread = 0; end((n > 0) || (n == IOStatus.UNAVAILABLE)); assert IOStatus.check(n); } } }
public int write(ByteBuffer buf) throws IOException { if (buf == null) throw new NullPointerException(); synchronized (writeLock) { synchronized (stateLock) { ensureOpen(); if (!isConnected()) throw new NotYetConnectedException(); } int n = 0; try { begin(); if (!isOpen()) return 0; writerThread = NativeThread.current(); do { n = IOUtil.write(fd, buf, -1, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { writerThread = 0; end((n > 0) || (n == IOStatus.UNAVAILABLE)); assert IOStatus.check(n); } } }
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { if ((offset < 0) || (length < 0) || (offset > srcs.length - length)) throw new IndexOutOfBoundsException(); synchronized (writeLock) { synchronized (stateLock) { ensureOpen(); if (!isConnected()) throw new NotYetConnectedException(); } long n = 0; try { begin(); if (!isOpen()) return 0; writerThread = NativeThread.current(); do { n = IOUtil.write(fd, srcs, offset, length, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { writerThread = 0; end((n > 0) || (n == IOStatus.UNAVAILABLE)); assert IOStatus.check(n); } } }
protected void implConfigureBlocking(boolean block) throws IOException { IOUtil.configureBlocking(fd, block); }
SourceChannelImpl(SelectorProvider sp, FileDescriptor fd) { super(sp); this.fd = fd; this.fdVal = IOUtil.fdVal(fd); this.state = ST_INUSE; }
static { IOUtil.load(); initIDs(); }