diff --git a/aqhome/events2/eventloop_select.c b/aqhome/events2/eventloop_select.c index dd32b56..346314b 100644 --- a/aqhome/events2/eventloop_select.c +++ b/aqhome/events2/eventloop_select.c @@ -41,6 +41,7 @@ static void _signalReadyFdObjects(AQH_OBJECT_LIST2 *ol); void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs) { + static int selectErrorCount=0; fd_set fdRead; fd_set fdWrite; int highestFd=-1; @@ -61,6 +62,8 @@ void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs) rv=select(highestFd+1, &fdRead, &fdWrite, NULL, &tv); if (rv>0) { /* some fds became active */ + if (selectErrorCount) + selectErrorCount--; _markReadyFdObjects(eventLoop->fdObjectList, &fdRead, AQH_FDOBJECT_FDMODE_READ); _markReadyFdObjects(eventLoop->fdObjectList, &fdWrite, AQH_FDOBJECT_FDMODE_WRITE); _signalReadyFdObjects(eventLoop->fdObjectList); @@ -68,11 +71,24 @@ void AQH_EventLoop_Run(AQH_EVENT_LOOP *eventLoop, int timeoutInMillisecs) else if (rv<0) { if (errno!=EINTR) { /* error */ - DBG_ERROR(AQH_LOGDOMAIN, "Error on SELECT: %d (%s)", errno, strerror(errno)); + DBG_ERROR(AQH_LOGDOMAIN, "Error on SELECT: %d (%s)", errno, strerror(errno)); + selectErrorCount++; + /* TODO: walk through all sockets to find the bad one */ + if (selectErrorCount==90) { + /* increase log level */ + DBG_ERROR(AQH_LOGDOMAIN, "Increasing log level to INFO"); + GWEN_Logger_SetLevel(AQH_LOGDOMAIN, GWEN_LoggerLevel_Info); + } + else if (selectErrorCount==100) { + DBG_ERROR(AQH_LOGDOMAIN, "Aborting due to too many SELECT errors, will be restarted by systemd"); + abort(); + } } } else { /* no fd became active (TODO: maybe signal deep idle objects?) */ + if (selectErrorCount) + selectErrorCount--; } } }