简体   繁体   English

为什么在poll()函数中使用POLLRDHUP事件标志之前需要定义_GNU_SOURCE宏?

[英]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. 我在我的程序中使用了poll()函数,我读了这个链接 ,要使用POLLRDHUP标志,你必须在包含所有头文件之前定义_GNU_SOURCE 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). 顺便说一句,我正在编写一个可以同时处理多个客户端的'echo'服务器的C程序,我在OpenSuse Linux Enterprise Server 10.3(x86_64)上使用GCC 4.1.2。

POLLRDHUP is a non-standard extension (it is missing from POSIX ). POLLRDHUP是一个非标准的扩展(它从POSIX中丢失 )。 To prevent polluting the namespace, non-standard extensions are not visible unless you explicitly request them by defining _GNU_SOURCE . 为防止污染命名空间,除非您通过定义_GNU_SOURCE显式请求,否则不会显示非标准扩展。

More details on _GNU_SOURCE can be found in previous StackOverflow answers such as this one . 有关_GNU_SOURCE更多详细信息可以在之前的StackOverflow答案中找到, 例如此答案。

_GNU_SOURCE是一个功能测试宏,通过防止暴露非标准定义,可用于创建可移植应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM