本文整理汇总了Java中org.apache.harmony.luni.platform.FileDescriptorHandler类的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptorHandler类的具体用法?Java FileDescriptorHandler怎么用?Java FileDescriptorHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileDescriptorHandler类属于org.apache.harmony.luni.platform包,在下文中一共展示了FileDescriptorHandler类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EpollSelectorImpl
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
public EpollSelectorImpl(SelectorProvider selectorProvider) {
super(selectorProvider);
try {
Pipe mockSelector = selectorProvider.openPipe();
sink = mockSelector.sink();
source = mockSelector.source();
sourcefd = ((FileDescriptorHandler) source).getFD();
source.configureBlocking(false);
fileDescriptorClass = sourcefd.getClass();
keyFDs = new int[1];
readyFDs = new int[1];
readyOps = new int[1];
// register sink channel
keyFDs[0] = resolveFD(fileDescriptorClass, sourcefd);
keys[0] = source.keyFor(this);
epollFD = prepare();
keysCount = 1;
quickMap.put(keyFDs[0], (EpollSelectionKeyImpl) keys[0]);
addFileDescriptor(epollFD, 1, keyFDs[0]);
} catch (IOException e) {
// do nothing
}
}
示例2: addKey
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
/**
* Adds the specified key to storage and updates the indexes accordingly
*
* @param sk
* key to add
* @return index in the storage
*/
private int addKey(SelectionKey sk) {
// make sure that enough space is available
ensureCapacity(keysCount);
// get channel params
int ops = sk.interestOps();
int fd = resolveFD(fileDescriptorClass, ((FileDescriptorHandler) sk
.channel()).getFD());
int eops = 0;
if (((SelectionKey.OP_READ | SelectionKey.OP_ACCEPT) & ops) != 0) {
eops = eops + READABLE;
}
;
if (((SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT) & ops) != 0) {
eops = eops + WRITABLE;
}
;
keys[keysCount] = sk;
keyFDs[keysCount] = fd;
quickMap.put(fd, (EpollSelectionKeyImpl) sk);
addFileDescriptor(epollFD, eops, fd);
return keysCount++;
}
示例3: SelectorImpl
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
public SelectorImpl(SelectorProvider selectorProvider) {
super(selectorProvider);
try {
Pipe mockSelector = selectorProvider.openPipe();
sink = mockSelector.sink();
source = mockSelector.source();
sourcefd = ((FileDescriptorHandler) source).getFD();
source.configureBlocking(false);
readableFDs = new FileDescriptor[1];
writableFDs = new FileDescriptor[0];
keysToReadableFDs = new int[1];
keysToWritableFDs = new int[0];
readableFDsToKeys = new int[1];
writableFDsToKeys = new int[0];
// register sink channel
readableFDs[0] = sourcefd;
keys[0] = (SelectionKeyImpl) source.keyFor(this);
// index it
keysToReadableFDs[0] = 0;
readableFDsToKeys[0] = 0;
lastKeyIndex = 0;
readableKeysCount = 1;
} catch (IOException e) {
// do nothing
}
}
示例4: SelectorImpl
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
public SelectorImpl(SelectorProvider selectorProvider) {
super(selectorProvider);
try {
Pipe mockSelector = selectorProvider.openPipe();
sink = mockSelector.sink();
source = mockSelector.source();
sourcefd = ((FileDescriptorHandler)source).getFD();
source.configureBlocking(false);
} catch (IOException e) {
// do nothing
}
}
示例5: prepareChannels
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
private void prepareChannels() {
readableFDs.add(sourcefd);
List<SelectionKey> readChannelList = new ArrayList<SelectionKey>();
readChannelList.add(source.keyFor(this));
List<SelectionKey> writeChannelList = new ArrayList<SelectionKey>();
synchronized (keysLock) {
for (Iterator<SelectionKey> i = keys.iterator(); i.hasNext();) {
SelectionKeyImpl key = (SelectionKeyImpl) i.next();
key.oldInterestOps = key.interestOps();
boolean isReadableChannel = ((SelectionKey.OP_ACCEPT | SelectionKey.OP_READ) & key.oldInterestOps) != 0;
boolean isWritableChannel = ((SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE) & key.oldInterestOps) != 0;
SelectableChannel channel = key.channel();
if (isReadableChannel) {
readChannelList.add(channel.keyFor(this));
readableFDs.add(((FileDescriptorHandler)channel).getFD());
}
if (isWritableChannel) {
writeChannelList.add(channel.keyFor(this));
writableFDs.add(((FileDescriptorHandler)channel).getFD());
}
}
}
readableChannels = readChannelList.toArray(new SelectionKey[0]);
writableChannels = writeChannelList.toArray(new SelectionKey[0]);
readable = readableFDs.toArray(new FileDescriptor[0]);
writable = writableFDs.toArray(new FileDescriptor[0]);
}
示例6: addKey
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
/**
* Adds the specified key to storage and updates the indexes accordingly
*
* @param sk
* key to add
* @return index in the storage
*/
private void addKey(SelectionKeyImpl sk) {
lastKeyIndex++;
int c = lastKeyIndex;
// make sure that enough space is available
ensureCommonCapacity(c);
// add to keys storage
keys[c] = sk;
// cache the fields
int ops = sk.interestOps();
FileDescriptor fd = ((FileDescriptorHandler) sk.channel()).getFD();
// presume that we have no FD associated
keysToReadableFDs[c] = -1;
keysToWritableFDs[c] = -1;
// if readable operations requested
if (((SelectionKey.OP_ACCEPT | SelectionKey.OP_READ) & ops) != 0) {
ensureReadCapacity(c);
// save as readable FD
readableFDs[readableKeysCount] = fd;
// create index
keysToReadableFDs[c] = readableKeysCount;
readableFDsToKeys[readableKeysCount] = c;
readableKeysCount++;
}
// if writable operations requested
if (((SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE) & ops) != 0) {
ensureWriteCapacity(c);
// save as writable FD
writableFDs[writableKeysCount] = fd;
// create index
keysToWritableFDs[c] = writableKeysCount;
writableFDsToKeys[writableKeysCount] = c;
writableKeysCount++;
}
sk.setIndex(c);
}
示例7: getChannelAddress
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
/**
* Gets the address of native resource held by the given channel, if it has
* any.
*
* For network related channel, including {@link SocketChannel},
* {@link ServerSocketChannel} and {@link DatagramChannel}, this method
* returns the Socket handle (long) in Linux, and returns a SOCKET
* (UINT_PTR) in windows.
*
* For {@link FileChannel}, this method returns the native file descriptor.
*
* For other channels, this method return 0, which means unsupported
* operation.
*
* @param channel
* the given channel which may holds a native resource address
* @return the address of native resource held by the given channel, if any,
* otherwise return 0
*/
public static long getChannelAddress(Channel channel) {
if (channel instanceof FileDescriptorHandler) {
return getFDAddress(((FileDescriptorHandler) channel).getFD());
} else if (channel instanceof FileChannelImpl) {
return ((FileChannelImpl) channel).getHandle();
}
return 0;
}
示例8: getChannelAddress
import org.apache.harmony.luni.platform.FileDescriptorHandler; //导入依赖的package包/类
/**
* Gets the address of native resource held by the given channel, if has
* any.
*
* For network related channel, including SocketChannel, ServerSocketChannel
* and DatagramChannel, this method returns a int of Socket handler in Linux
* while returns a SOCKET (UINT_PTR) in windows.
*
* For FileChannel, this method returns the native file descriptor.
*
* For other channels, this method return 0, which means unsupported
* operation.
*
* @param channel
* the given channel which may holds a native resource address
* @return the address of native resource held by the given channel, if any,
* otherwise return 0
*/
public static long getChannelAddress(Channel channel){
if(channel instanceof FileDescriptorHandler){
return getFDAddress(((FileDescriptorHandler) channel).getFD());
}else if(channel instanceof FileChannelImpl){
return ((FileChannelImpl) channel).getHandle();
}
return 0;
}