use of com.oracle.svm.core.posix.headers.Poll.pollfd in project graal by oracle.
the class JavavmExportJvm method timeout.
// 198 inline int os::timeout(int fd, long timeout) {
static int timeout(int fd, long timeoutArg) {
/*
* Local copy of argument because it is modified.
* Also, convert from long to int to pass to Poll.poll.
*/
int timeout = (int) timeoutArg;
// 199 julong prevtime,newtime;
/* Using System.currentTimeMillis() instead of gettimeofday(struct timeval*) */
long prevtime;
long newtime;
// 200 struct timeval t;
// 201
// 202 gettimeofday(&t, NULL);
// 203 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
prevtime = System.currentTimeMillis();
// 204
// 205 for(;;) {
// 206 struct pollfd pfd;
Poll.pollfd pfd = StackValue.get(2, SizeOf.get(Time.timeval.class));
for (; ; ) {
// 207
// 208 pfd.fd = fd;
pfd.set_fd(fd);
// 209 pfd.events = POLLIN | POLLERR;
pfd.set_events(Poll.POLLIN() | Poll.POLLERR());
// 210
// 211 int res = ::poll(&pfd, 1, timeout);
/* { FIXME: Limited timeout. */
int res;
final boolean limitedTimeout = false;
if (limitedTimeout) {
/* This is a compromise between frequent poll requests and promptness of interruption. */
final int limitedTimeoutMillis = 2_000;
res = Poll.poll(pfd, 1, limitedTimeoutMillis);
if (Thread.interrupted()) {
return VmRuntimeOS.OSReturn.OS_OK();
}
} else {
res = Poll.poll(pfd, 1, timeout);
}
// 213 if (res == OS_ERR && errno == EINTR) {
if (res == VmRuntimeOS.OSReturn.OS_ERR() && Errno.errno() == Errno.EINTR()) {
// 217 if(timeout >= 0) {
if (timeout >= 0) {
// 218 gettimeofday(&t, NULL);
// 219 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
newtime = System.currentTimeMillis();
// 220 timeout -= newtime - prevtime;
timeout -= newtime - prevtime;
// 221 if(timeout <= 0)
if (timeout <= 0) {
// 222 return OS_OK;
return VmRuntimeOS.OSReturn.OS_OK();
}
// 223 prevtime = newtime;
prevtime = newtime;
}
} else {
// 226 return res;
return res;
}
}
}
Aggregations