/*
* 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 pollfd structs on Solaris:
*
* typedef struct pollfd {
* int fd;
* short events;
* short revents;
* } pollfd_t;
*
* @author Mike McCloskey
* @since 1.4
*/
class DevPollArrayWrapper {
// Event masks
// Miscellaneous constants
// Special value to indicate that an update should be ignored
// Maximum number of open file descriptors
// Number of pollfd structures to create.
// Initial size of arrays for fd registration changes
// maximum size of updatesLow
// The pollfd array for results from devpoll driver
// Base address of the native pollArray
private final long pollArrayAddress;
// The fd of the devpoll driver
private int wfd;
// 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
if (OPEN_MAX > MAX_UPDATE_ARRAY_SIZE)
eventsHigh = new HashMap<>();
}
}
}
int getEventOps(int i) {
}
int getReventOps(int i) {
}
int getDescriptor(int i) {
}
if (fd < MAX_UPDATE_ARRAY_SIZE) {
} else {
}
}
if (fd < MAX_UPDATE_ARRAY_SIZE) {
} else {
// result should never be null
}
}
synchronized (updateLock) {
// record the file descriptor and events, expanding the
// respective arrays first if necessary.
if (updateCount == oldCapacity) {
int[] newDescriptors = new int[newCapacity];
}
// events are stored as bytes for efficiency reasons
byte b = (byte)mask;
setUpdateEvents(fd, b);
}
}
synchronized (updateLock) {
// ignore any pending update for this file descriptor
}
}
}
}
for (int i=0; i<updated; i++) {
if (getDescriptor(i) == incomingInterruptFD) {
interruptedIndex = i;
interrupted = true;
break;
}
}
return updated;
}
synchronized (updateLock) {
// Populate pollfd array with updated masks
int j = 0;
int index = 0;
while (j < updateCount) {
int fd = updateDescriptors[j];
// events = 0 => POLLREMOVE or do-nothing
if (events == 0) {
if (wasRegistered) {
events = POLLREMOVE;
} else {
}
} else {
if (!wasRegistered) {
}
}
}
// populate pollfd array with updated event
// insert POLLREMOVE if changing events
index++;
}
index++;
index = 0;
}
// events for this fd now up to date
}
j++;
}
// write any remaining updates
if (index > 0)
updateCount = 0;
}
}
short event)
{
}
boolean interrupted = false;
public void interrupt() {
}
public int interruptedIndex() {
return interruptedIndex;
}
boolean interrupted() {
return interrupted;
}
void clearInterrupted() {
interrupted = false;
}
private native int init();
throws IOException;
int wfd);
}