/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Manipulates a native array of epoll_event structs on Linux:
*
* typedef union epoll_data {
* void *ptr;
* int fd;
* __uint32_t u32;
* __uint64_t u64;
* } epoll_data_t;
*
* struct epoll_event {
* __uint32_t events;
* epoll_data_t data;
* };
*
* The system call to wait for I/O events is epoll_wait(2). It populates an
* array of epoll_event structures that are passed to the call. The data
* member of the epoll_event structure contains the same data as was set
* when the file descriptor was registered to epoll via epoll_ctl(2). In
* this implementation we set data.fd to be the file descriptor that we
* register. That way, we have the file descriptor available when we
* process the events.
*/
class EPollArrayWrapper {
// EPOLL_EVENTS
// opcodes
// Miscellaneous constants
// Special value to indicate that an update should be ignored
// Initial size of arrays for fd registration changes
// maximum size of updatesLow
// The fd of the epoll driver
private final int epfd;
// The epoll_event array for results from epoll_wait
// Base address of the epoll_event array
private final long pollArrayAddress;
// The fd of the interrupt line going out
private int outgoingInterruptFD;
// The fd of the interrupt line coming in
private int incomingInterruptFD;
// The index of the interrupt FD
private int interruptedIndex;
// Number of updated pollfd entries
int updated;
// object to synchronize fd registration changes
// number of file descriptors with registration changes pending
private int updateCount;
// file descriptors with registration changes pending
// events for file descriptors with registration changes pending, indexed
// by file descriptor and stored as bytes for efficiency reasons. For
// file descriptors higher than MAX_UPDATE_ARRAY_SIZE (unlimited case at
// least) then the update is stored in a map.
// Used by release and updateRegistrations to track whether a file
// descriptor is registered with epoll.
// creates the epoll file descriptor
epfd = epollCreate();
// the epoll_event array passed to epoll_wait
// eventHigh needed when using file descriptors > 64k
if (OPEN_MAX > MAX_UPDATE_ARRAY_SIZE)
eventsHigh = new HashMap<>();
}
}
}
}
int getEventOps(int i) {
}
int getDescriptor(int i) {
}
/**
* Sets the pending update events for the given file descriptor. This
* method has no effect if the update events is already set to KILLED,
* unless {@code force} is {@code true}.
*/
if (fd < MAX_UPDATE_ARRAY_SIZE) {
}
} else {
}
}
}
/**
* Returns the pending update events for the given file descriptor.
*/
if (fd < MAX_UPDATE_ARRAY_SIZE) {
} else {
// result should never be null
}
}
/**
* Update the events for a given file descriptor
*/
synchronized (updateLock) {
// record the file descriptor and events
if (updateCount == oldCapacity) {
int[] newDescriptors = new int[newCapacity];
}
// events are stored as bytes for efficiency reasons
byte b = (byte)mask;
setUpdateEvents(fd, b, false);
}
}
/**
* Add a file descriptor
*/
// force the initial update events to 0 as it may be KILLED by a
// previous registration.
synchronized (updateLock) {
}
}
/**
* Remove a file descriptor
*/
synchronized (updateLock) {
// kill pending and future update for this file descriptor
// remove from epoll
}
}
}
/**
* Close epoll file descriptor and free poll array
*/
}
for (int i=0; i<updated; i++) {
if (getDescriptor(i) == incomingInterruptFD) {
interruptedIndex = i;
interrupted = true;
break;
}
}
return updated;
}
/**
* Update the pending registrations.
*/
private void updateRegistrations() {
synchronized (updateLock) {
int j = 0;
while (j < updateCount) {
int fd = updateDescriptors[j];
int opcode = 0;
if (isRegistered) {
} else {
}
if (opcode != 0) {
if (opcode == EPOLL_CTL_ADD) {
} else if (opcode == EPOLL_CTL_DEL) {
}
}
}
j++;
}
updateCount = 0;
}
}
// interrupt support
private boolean interrupted = false;
public void interrupt() {
}
public int interruptedIndex() {
return interruptedIndex;
}
boolean interrupted() {
return interrupted;
}
void clearInterrupted() {
interrupted = false;
}
static {
init();
}
private native int epollCreate();
int epfd) throws IOException;
private static native int sizeofEPollEvent();
private static native int offsetofData();
private static native void init();
}