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_processEvents(lua_State *L) { le_result_t res = LE_WOULD_BLOCK; L_eventloop = L; do { LE_DEBUG("=> serviceLoop"); res = le_event_ServiceLoop(); LE_DEBUG("<= serviceLoop, res = %d", res); } while(res == LE_OK); lua_pushstring(L, "ok"); return 1; }