被套接字选项继承跨接受()从监听套接字? [英] Are socket options inherited across accept() from the listening socket?

查看:159
本文介绍了被套接字选项继承跨接受()从监听套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设传递给监听套接字接受上有设定的setsockopt 非默认选项。由产生的文件描述符接受的连接继承了这些选项(部分或全部的?)?

Suppose the listening socket passed to accept has non-default options set on it with setsockopt. Are these options (some or all of them?) inherited by the resulting file descriptors for accepted connections?

推荐答案

若干的套接字选项被下级系统的处理。虽然大多数的套接字选项可以使用setsockopt来设置。参考:男人的setsockopt 键,因为你在任何Linux只提及POSIX,在一般情况下,作为你的范围。在接受()(参考:人接受)确实对应该继承什么套接字选项一定的自由裁量权并从聆听FD拒绝的选项。

Several of the socket options are handled at lower levels of the system. While most of the socket options could be set using the setsockopt. Reference:man setsockopt And since you are mentioning only POSIX on any Linux, in general, as your scope. The accept() (Reference: man accept) does have a certain amount of discretion on what socket options should be inherited and what options to reject from the listening fd.

接受()不修改传递给它作为参数原始套接字。通过接受返回新的socket()不继承文件状态标志,如O_NONBLOCK,O_ASYNC从监听套接字。

accept() does not modify the original socket passed to it as argument. The new socket returned by accept() does not inherit file status flags such as O_NONBLOCK,O_ASYNC from the listening socket.

所以,不是依靠继承或监听套接字属性的非继承(这势必会在不同的实现和许可证而异),接受套接字应明确与所需的套接字选项设置。(最佳实践)

So, instead of relying on the inheritance or non-inheritance of the listening socket properties(which is bound to vary across implementations and licenses), the accepted socket should be explicitly set with the desired socket options.(Best practice)

man页面,并在您的机器执行codeS将是最相关的规范接受()behavior.There现有跨Linux的多个变体没有统一的标准或规范。

man pages and the implementation codes in your machine would be the most relevant specification for the accept() behavior.There's no common or standard specification existing across multiple variants of Linux.

这篇关于被套接字选项继承跨接受()从监听套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆