sun.nio.ch.Net Java Examples

The following examples show how to use sun.nio.ch.Net. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SctpChannelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #2
Source File: SctpMultiChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #3
Source File: SctpChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #4
Source File: SctpChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #5
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #6
Source File: SctpChannelImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #7
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #8
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #9
Source File: SctpMultiChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #10
Source File: SctpChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #11
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #12
Source File: SctpChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #13
Source File: SctpChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #14
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #15
Source File: SctpChannelImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #16
Source File: SctpMultiChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #17
Source File: SctpMultiChannelImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #18
Source File: SctpChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #19
Source File: SctpMultiChannelImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #20
Source File: SctpMultiChannelImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #21
Source File: SctpMultiChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #22
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #23
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #24
Source File: SctpChannelImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #25
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #26
Source File: SctpChannelImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #27
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for sockets obtained from branching
 */
public SctpChannelImpl(SelectorProvider provider,
                       FileDescriptor fd,
                       Association association)
        throws IOException {
    super(provider);
    this.fd = fd;
    this.fdVal = IOUtil.fdVal(fd);
    this.state = ChannelState.CONNECTED;
    port = (Net.localAddress(fd)).getPort();

    if (association != null) { /* branched */
        this.association = association;
    } else { /* obtained from server channel */
        /* Receive COMM_UP */
        ByteBuffer buf = Util.getTemporaryDirectBuffer(50);
        try {
            receive(buf, null, null, true);
        } finally {
            Util.releaseTemporaryDirectBuffer(buf);
        }
    }
}
 
Example #28
Source File: SctpMultiChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int assocId,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }
    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, assocId, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #29
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int sendFromNativeBuffer(int fd,
                                 ByteBuffer bb,
                                 SocketAddress target,
                                 int streamNumber,
                                 boolean unordered,
                                 int ppid)
        throws IOException {
    InetAddress addr = null;     // no preferred address
    int port = 0;
    if (target != null) {
        InetSocketAddress isa = Net.checkAddress(target);
        addr = isa.getAddress();
        port = isa.getPort();
    }

    int pos = bb.position();
    int lim = bb.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
                        port, -1 /*121*/, streamNumber, unordered, ppid);
    if (written > 0)
        bb.position(pos + written);
    return written;
}
 
Example #30
Source File: SctpMultiChannelImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SctpMultiChannel bind(SocketAddress local, int backlog)
        throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpen();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);

                SecurityManager sm = System.getSecurityManager();
                if (sm != null)
                    sm.checkListen(isa.getPort());
                Net.bind(fd, isa.getAddress(), isa.getPort());

                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;

                SctpNet.listen(fdVal, backlog < 1 ? 50 : backlog);
            }
        }
    }
    return this;
}