本文整理了Java中android.system.Os.poll()
方法的一些代码示例,展示了Os.poll()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Os.poll()
方法的具体详情如下:
包路径:android.system.Os
类名称:Os
方法名:poll
暂无
代码示例来源:origin: julian-klode/dns66
/**
* Wrapper around {@link Os#poll(StructPollfd[], int)} that automatically restarts on EINTR
* While post-Lollipop devices handle that themselves, we need to do this for Lollipop.
*
* @param fds Descriptors and events to wait on
* @param timeout Timeout. Should be -1 for infinite, as we do not lower the timeout when
* retrying due to an interrupt
* @return The number of fds that have events
* @throws ErrnoException See {@link Os#poll(StructPollfd[], int)}
*/
public static int poll(StructPollfd[] fds, int timeout) throws ErrnoException, InterruptedException {
while (true) {
if (Thread.interrupted())
throw new InterruptedException();
try {
return Os.poll(fds, timeout);
} catch (ErrnoException e) {
if (e.errno == OsConstants.EINTR)
continue;
throw e;
}
}
}
代码示例来源:origin: iTXTech/Daedalus
polls[0] = deviceFd;
polls[1] = blockFd;
Os.poll(polls, 100);
if (blockFd.revents != 0) {
Log.i(TAG, "Told to stop VPN");
代码示例来源:origin: iTXTech/Daedalus
Os.poll(polls, -1);
if (blockFd.revents != 0) {
Log.i(TAG, "Told to stop VPN");
代码示例来源:origin: iTXTech/Daedalus
Os.poll(polls, -1);
if (blockFd.revents != 0) {
Log.i(TAG, "Told to stop VPN");
代码示例来源:origin: julian-klode/dns66
@Test
@PrepareForTest({Log.class, Os.class})
public void testPoll_success() throws Exception {
mockStatic(Log.class);
mockStatic(Os.class);
when(Os.poll(any(StructPollfd[].class), anyInt())).then(new CountingAnswer(42));
assertEquals(42, FileHelper.poll(null, 0));
assertEquals(1, testResult);
}
代码示例来源:origin: julian-klode/dns66
@Test
@PrepareForTest({Log.class, Os.class})
public void testPoll_retryInterrupt() throws Exception {
mockStatic(Log.class);
mockStatic(Os.class);
when(Os.poll(any(StructPollfd[].class), anyInt())).then(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
// First try fails with EINTR, seconds returns success.
if (testResult++ == 0) {
// Android actually sets all OsConstants to 0 when running the
// unit tests, so this works, but another constant would have
// exactly the same result.
throw new ErrnoException("poll", OsConstants.EINTR);
}
return 0;
}
});
// poll() will be interrupted first time, so called a second time.
assertEquals(0, FileHelper.poll(null, 0));
assertEquals(2, testResult);
}
代码示例来源:origin: julian-klode/dns66
@Test
@PrepareForTest({Log.class, Os.class})
public void testPoll_fault() throws Exception {
mockStatic(Log.class);
mockStatic(Os.class);
// Eww, Android is playing dirty and setting all errno values to 0.
// Hack around it so we can test that aborting the loop works.
final ErrnoException e = new ErrnoException("foo", 42);
e.getClass().getDeclaredField("errno").setInt(e, 42);
when(Os.poll(any(StructPollfd[].class), anyInt())).then(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
testResult++;
throw e;
}
});
try {
FileHelper.poll(null, 0);
fail("Did not throw");
} catch (ErrnoException e1) {
assertEquals(42, e1.errno);
assertSame(e, e1);
}
assertEquals(1, testResult);
}
内容来源于网络,如有侵权,请联系作者删除!