Example #1
0
// An external process can send interrupts to the emulator by writing to a
// named pipe. Poll the pipe to determine if any messages are pending. If
// so, call into the core to dispatch.
void checkInterruptPipe(Core *core)
{
    int result;
    char interruptId;

    if (recvInterruptFd < 0)
        return;

    result = canReadFileDescriptor(recvInterruptFd);
    if (result == 0)
        return;

    if (result < 0)
    {
        perror("checkInterruptPipe: select failed");
        exit(1);
    }

    if (read(recvInterruptFd, &interruptId, 1) < 1)
    {
        perror("checkInterruptPipe: read failed");
        exit(1);
    }

    if (interruptId > 16)
    {
        fprintf(stderr, "Received invalidate interrupt ID %d\n", interruptId);
        return; // Ignore invalid interrupt IDs
    }

    raiseInterrupt(core, 0, (uint32_t) interruptId);
}
// An external process can send interrupts to the emulator by writing to a
// named pipe. Poll the pipe to determine if any messages are pending. If
// so, call into the core to dispatch.
void checkInterruptPipe(Core *core)
{
    fd_set readFds;
    int result;
    struct timeval timeout;
    char interruptId;

    if (recvInterruptFd < 0)
        return;

    FD_ZERO(&readFds);

    do
    {
        FD_SET(recvInterruptFd, &readFds);
        timeout.tv_sec = 0;
        timeout.tv_usec = 0;
        result = select(recvInterruptFd + 1, &readFds, NULL, NULL, &timeout);
    }
    while (result < 0 && errno == EINTR);

    if (result == 0)
        return;

    if (result < 0)
    {
        perror("checkInterruptPipe: select failed");
        exit(1);
    }

    if (read(recvInterruptFd, &interruptId, 1) < 1)
    {
        perror("checkInterruptPipe: read failed");
        exit(1);
    }

    if (interruptId > 16)
    {
        fprintf(stderr, "Received invalidate interrupt ID %d\n", interruptId);
        return; // Ignore invalid interrupt IDs
    }

    raiseInterrupt(core, 0, (uint32_t) interruptId);
}