accept4和accept之间有什么区别

 谁的围脖搞笑排行榜 发布于 2023-01-12 14:39

我看到了accept4系统支持时使用的nginx源代码.
accept4在Linux 2.6.28之后谷歌支持它.
accept4和accept之间有什么区别?

1 个回答
  • accept4是一个非标准的Linux扩展.真正的区别在于第4个参数(flags),它不存在于accept:

    int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
    int accept4(int sockfd, struct sockaddr *addr,socklen_t *addrlen, int flags);
    

    来自:接受手册页

    如果flags为0,则accept4()与accept()相同.可以在标志中对以下值进行按位OR运算以获得不同的行为:

       SOCK_NONBLOCK   Set the O_NONBLOCK file status flag on the new open
                       file description.  Using this flag saves extra calls
                       to fcntl(2) to achieve the same result.
    
       SOCK_CLOEXEC    Set the close-on-exec (FD_CLOEXEC) flag on the new
                       file descriptor.  See the description of the
                       O_CLOEXEC flag in open(2) for reasons why this may be
                       useful.
    

    来自:打开手册页

    默认情况下,新文件描述符设置为在execve(2)上保持打开(即,最初禁用fcntl(2)中描述的FD_CLOEXEC文件描述符标志); 下面描述的O_CLOEXEC标志可用于更改此默认值.

    例如,通过使用此标志(SOCK_CLOEXEC),可以避免多线程程序中的竞争条件,其中可能导致open()返回的文件描述符被无意泄漏到由fork(2)创建的子进程执行的程序.

    2023-01-12 14:42 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有