Пример #1
0
int main(int argc, char** argv)
{
    struct pollfd pollControl;

    le_sms_ConnectService();

    // Register a callback function to be called when an SMS arrives.
    (void)le_sms_AddRxMessageHandler(SmsRxHandler, NULL);

    printf("Waiting for SMS messages to arrive...\n");

    // Get the Legato event loop "readyness" file descriptor and put it in a pollfd struct
    // configured to detect "ready to read".
    pollControl.fd = le_event_GetFd();
    pollControl.events = POLLIN;

    while (true)
    {
        // Block until the file descriptor is "ready to read".
        int result = poll(&pollControl, 1, -1);

        if (result > 0)
        {
            // The Legato event loop needs servicing. Keep servicing it until there's nothing left.
            while (le_event_ServiceLoop() == LE_OK)
            {
                /* le_event_ServiceLoop() has more to do.  Need to call it again. */
            }
        }
        else
        {
            LE_FATAL("poll() failed with errno %m.");
        }
    }
}
static int l_getEventloopFd(lua_State *L)
{
    lua_pushinteger(L, le_event_GetFd());
    return 1;
}