Skip to content

Commit

Permalink
[build] Fix build for Linux GLIBC-2.8 and earlier. (#2103)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsantiago0 authored Aug 27, 2021
1 parent da70624 commit fb09875
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions srtcore/epoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,31 @@ int CEPoll::create(CEPollDesc** pout)
int localid = 0;

#ifdef LINUX
int flags = 0;
#if ENABLE_SOCK_CLOEXEC
flags |= EPOLL_CLOEXEC;
#endif
localid = epoll_create1(flags);

// NOTE: epoll_create1() and EPOLL_CLOEXEC were introduced in GLIBC-2.9.
// So earlier versions of GLIBC, must use epoll_create() and set
// FD_CLOEXEC on the file descriptor returned by it after the fact.
#if defined(EPOLL_CLOEXEC)
int flags = 0;
#if ENABLE_SOCK_CLOEXEC
flags |= EPOLL_CLOEXEC;
#endif
localid = epoll_create1(flags);
#else
localid = epoll_create(1);
#if ENABLE_SOCK_CLOEXEC
if (localid != -1)
{
int fdFlags = fcntl(localid, F_GETFD);
if (fdFlags != -1)
{
fdFlags |= FD_CLOEXEC;
fcntl(localid, F_SETFD, fdFlags);
}
}
#endif
#endif

/* Possible reasons of -1 error:
EMFILE: The per-user limit on the number of epoll instances imposed by /proc/sys/fs/epoll/max_user_instances was encountered.
ENFILE: The system limit on the total number of open files has been reached.
Expand Down

0 comments on commit fb09875

Please sign in to comment.