Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using poll() function in my program, I read this link that to use POLLRDHUP flag you have to define _GNU_SOURCE before all header file inclusion. I needed this flag so that polling the socket can tell me whether the client has hung up or not, so that I can terminate the corresponding thread.

By the way I am writing a C program for an 'echo' server which can handle multiple clients concurrently, and I am using GCC 4.1.2 on OpenSuse Linux Enterprise Server 10.3 (x86_64).

like image 789
Don't You Worry Child Avatar asked Aug 13 '13 11:08

Don't You Worry Child


People also ask

What is #define _gnu_source?

If you define _GNU_SOURCE , you will get: access to lots of nonstandard GNU/Linux extension functions. access to traditional functions which were omitted from the POSIX standard (often for good reason, such as being replaced with better alternatives, or being tied to particular legacy implementations)

What do you understand by the term feature test macros?

Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled. NOTE: In order to be effective, a feature test macro must be defined before including any header files.


1 Answers

POLLRDHUP is a non-standard extension (it is missing from POSIX). To prevent polluting the namespace, non-standard extensions are not visible unless you explicitly request them by defining _GNU_SOURCE.

More details on _GNU_SOURCE can be found in previous StackOverflow answers such as this one.

like image 55
user4815162342 Avatar answered Sep 28 '22 06:09

user4815162342