Why do we need to define the _GNU_SOURCE macro before using the POLLRDHUP event flag in the poll () function?

I use the poll() function in my program, I read this link to use the POLLRDHUP flag, which you must define _GNU_SOURCE before including all the header files. I need this flag so that the socket polling can tell me whether the client is hanging or not, so that I can finish the corresponding thread.

By the way, I am writing a program on the echo server that can process several clients at the same time, and I use GCC 4.1.2 on OpenSuse Linux Enterprise Server 10.3 (x86_64).

+4
source share
2 answers

POLLRDHUP is a non-standard extension (this is not available on POSIX ). To prevent namespace pollution, custom extensions are not visible unless you explicitly request their _GNU_SOURCE definition .

More information about _GNU_SOURCE can be found in previous StackOverflow answers such as this .

+7
source

_GNU_SOURCE is a functional test macro that is useful for creating portable applications, preventing the display of non-standard definitions.

+2
source

Source: https://habr.com/ru/post/1496776/


All Articles