mirror of
https://github.com/open62541/open62541.git
synced 2025-06-03 04:00:21 +00:00
fix(core): Fix a busy-loop when timeouts are less than 1ms (fixes #7102)
This commit is contained in:
parent
c5f59df0a1
commit
041d6a2173
@ -68,12 +68,20 @@ UA_StatusCode
|
||||
UA_EventLoopPOSIX_pollFDs(UA_EventLoopPOSIX *el, UA_DateTime listenTimeout) {
|
||||
UA_assert(listenTimeout >= 0);
|
||||
|
||||
/* If there is a positive timeout, wait at least one millisecond, the
|
||||
* minimum for blocking epoll_wait. This prevents a busy-loop, as the
|
||||
* open62541 library allows even smaller timeouts, which can result in a
|
||||
* zero timeout due to rounding to an integer here. */
|
||||
int timeout = (int)(listenTimeout / UA_DATETIME_MSEC);
|
||||
if(timeout == 0 && listenTimeout > 0)
|
||||
timeout = 1;
|
||||
|
||||
/* Poll the registered sockets */
|
||||
struct epoll_event epoll_events[64];
|
||||
int epollfd = el->epollfd;
|
||||
UA_UNLOCK(&el->elMutex);
|
||||
int events = epoll_wait(epollfd, epoll_events, 64,
|
||||
(int)(listenTimeout / UA_DATETIME_MSEC));
|
||||
int events = epoll_wait(el->epollfd, epoll_events, 64, timeout);
|
||||
UA_LOCK(&el->elMutex);
|
||||
|
||||
/* TODO: Replace with pwait2 for higher-precision timeouts once this is
|
||||
* available in the standard library.
|
||||
*
|
||||
@ -83,7 +91,6 @@ UA_EventLoopPOSIX_pollFDs(UA_EventLoopPOSIX *el, UA_DateTime listenTimeout) {
|
||||
* };
|
||||
* int events = epoll_pwait2(epollfd, epoll_events, 64,
|
||||
* precisionTimeout, NULL); */
|
||||
UA_LOCK(&el->elMutex);
|
||||
|
||||
/* Handle error conditions */
|
||||
if(events == -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user