• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java StructPollfd类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中android.system.StructPollfd的典型用法代码示例。如果您正苦于以下问题:Java StructPollfd类的具体用法?Java StructPollfd怎么用?Java StructPollfd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

StructPollfd类属于android.system包,在下文中一共展示了StructPollfd类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testPoll_retryInterrupt

点赞 3

import android.system.StructPollfd; //导入依赖的package包/类
@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);
}
 

开发者ID:julian-klode,
项目名称:dns66,
代码行数:24,
代码来源:FileHelperTest.java

示例2: poll

点赞 2

import android.system.StructPollfd; //导入依赖的package包/类
/**
 * 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;
        }
    }
}
 

开发者ID:julian-klode,
项目名称:dns66,
代码行数:24,
代码来源:FileHelper.java

示例3: testPoll_fault

点赞 2

import android.system.StructPollfd; //导入依赖的package包/类
@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);
}
 

开发者ID:julian-klode,
项目名称:dns66,
代码行数:28,
代码来源:FileHelperTest.java

示例4: testPoll_success

点赞 2

import android.system.StructPollfd; //导入依赖的package包/类
@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);
}
 

开发者ID:julian-klode,
项目名称:dns66,
代码行数:10,
代码来源:FileHelperTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)