本文整理汇总了Java中sun.nio.ch.Net类的典型用法代码示例。如果您正苦于以下问题:Java Net类的具体用法?Java Net怎么用?Java Net使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Net类属于sun.nio.ch包,在下文中一共展示了Net类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sendFromNativeBuffer
import sun.nio.ch.Net; //导入依赖的package包/类
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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:SctpMultiChannelImpl.java
示例2: SctpChannelImpl
import sun.nio.ch.Net; //导入依赖的package包/类
/**
* 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);
}
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:SctpChannelImpl.java
示例3: bind
import sun.nio.ch.Net; //导入依赖的package包/类
/**
* 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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:SctpChannelImpl.java
示例4: sendFromNativeBuffer
import sun.nio.ch.Net; //导入依赖的package包/类
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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:SctpChannelImpl.java
示例5: bind
import sun.nio.ch.Net; //导入依赖的package包/类
@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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:SctpMultiChannelImpl.java
示例6: translateReadyOps
import sun.nio.ch.Net; //导入依赖的package包/类
/**
* Translates native poll revent ops into a ready operation ops
*/
private boolean translateReadyOps(int ops, int initialOps,
SelectionKeyImpl sk) {
int intOps = sk.nioInterestOps();
int oldOps = sk.nioReadyOps();
int newOps = initialOps;
if ((ops & Net.POLLNVAL) != 0) {
/* This should only happen if this channel is pre-closed while a
* selection operation is in progress
* ## Throw an error if this channel has not been pre-closed */
return false;
}
if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
newOps = intOps;
sk.nioReadyOps(newOps);
return (newOps & ~oldOps) != 0;
}
if (((ops & Net.POLLIN) != 0) &&
((intOps & SelectionKey.OP_READ) != 0))
newOps |= SelectionKey.OP_READ;
if (((ops & Net.POLLOUT) != 0) &&
((intOps & SelectionKey.OP_WRITE) != 0))
newOps |= SelectionKey.OP_WRITE;
sk.nioReadyOps(newOps);
return (newOps & ~oldOps) != 0;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:SctpMultiChannelImpl.java
示例7: translateAndSetInterestOps
import sun.nio.ch.Net; //导入依赖的package包/类
@Override
public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
int newOps = 0;
if ((ops & SelectionKey.OP_READ) != 0)
newOps |= Net.POLLIN;
if ((ops & SelectionKey.OP_WRITE) != 0)
newOps |= Net.POLLOUT;
sk.selector.putEventOps(sk, newOps);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:SctpMultiChannelImpl.java
示例8: bind
import sun.nio.ch.Net; //导入依赖的package包/类
@Override
public SctpServerChannel bind(SocketAddress local, int backlog)
throws IOException {
synchronized (lock) {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:SctpServerChannelImpl.java
注:本文中的sun.nio.ch.Net类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论