AIX 特定套接字编程查询

发布于 2024-09-01 09:28:48 字数 898 浏览 14 评论 0原文

问题 1

从 SUSE 手册页中,我获得了套接字连接选项的以下详细信息

如果发起套接字是连接模式,则 connect() 将尝试建立与地址参数指定的地址的连接。如果无法立即建立连接并且未为套接字的文件描述符设置 O_NONBLOCK,则 connect() 将阻塞长达未指定的超时间隔,直到建立连接。如果在建立连接之前超时间隔到期,则 connect() 将失败并且连接尝试将被中止。如果 connect() 被阻塞等待建立连接时捕获的信号中断,则 connect() 将失败并将 errno 设置为 [EINTR],但连接请求不得中止,并且连接将异步建立。

问题:上述内容对 AIX 操作系统有效吗(特别是连接超时、定时等待等)?因为我在 AIX 手册页(5.1 和 5.3)中没有看到它 问题

2

我有一个客户端套接字,其属性为
一个。 SO_RCVTIMEO ,SO_SNDTIMEO 设置为 5 秒。
b. AF_INET 和 SOCK_STREAM。
c. SO_LINGER 开启延迟,时间为 5 秒。
d. SO_REUSEADDR 已设置。
请注意,客户端套接字不是 O_NONBLOCK。

问题:现在既然O_NONBLOCK没有设置,而SO_RCVTIMEO和SO_SNDTIMEO设置为5秒,这是否意味着

a.以非阻塞或阻塞方式连接?
b.如果阻塞,是定时阻塞还是“无限”时间阻塞?
c.如果它是无限的,我如何建立一个“连接”系统调用,它是 O_BLOCKING,超时为 t 秒。

抱歉,如果问题非常幼稚。
预先感谢您的意见。

Question 1

From SUSE man pages, I get the below details for socket connect options

If the initiating socket is connection-mode, then connect() shall attempt to establish a connection to the address specified by the address argument. If the connection cannot be established immediately and O_NONBLOCK is not set for the file descriptor for the socket, connect() shall block for up to an unspecified timeout interval until the connection is established. If the timeout interval expires before the connection is established, connect() shall fail and the connection attempt shall be aborted. If connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() shall fail and set errno to [EINTR], but the connection request shall not be aborted, and the connection shall be established asynchronously.

Question : Is the above contents valid for AIX OS (especially the connection time-out, timed wait ...etc)?Because I do not see it in AIX man pages (5.1 and 5.3)

Question 2

I have a client socket whose attributes are
a. SO_RCVTIMEO ,SO_SNDTIMEO are set for 5 seconds.
b. AF_INET and SOCK_STREAM.
c. SO_LINGER with linger on and time is 5 seconds.
d. SO_REUSEADDR is set.
Note that the client socket is not O_NONBLOCK.

Question : Now since O_NONBLOCK is not set and SO_RCVTIMEO and SO_SNDTIMEO is set for 5 seconds, does it mean

a. connect in NON Blocking or Blocking?
b. If blocking, is it timed blocking or "infinite" time blocking?
c. If it is infinite, How do I establish a "connect" system call which is O_BLOCKING with timeout to t secs.

Sorry if the questions are be very naive.
Thanks in advance for your input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

榕城若虚 2024-09-08 09:28:49

问题 1:我看到的所有内容似乎都适用于 AIX。未指定超时的原因是因为它是特定于协议的。在 IBM 文档(下面的链接)中搜索“connect”。第二个打击是可能感兴趣的一般性讨论。

一般来说,AIX 使用 BSD 模型。我不确定 Linux 使用什么。我相信它非常接近传统的 BSD 模型,但我也知道它在一些细微之处有所不同。

问题 2:我会访问 IBM 5.3 文档做一些搜索。例如,它说没有使用SO_RCVTIMEO。可以肯定的是,我需要做一些实验,但我预计连接会被阻止。我看不出有什么可以阻止它。它会永远阻塞。第 2c 部分我会采用两种方法之一。最简单的方法是设置一个计时器,当计时器弹出时,系统调用将返回 EINTR。另一种选择是将其设置为 O_NONBLOCK,然后使用带有计时器参数的 select 来等待,直到它连接或未连接。同样,为了准确起见,我必须对代码进行实验和调试。

Question 1: Everything I see there seems valid for AIX. The reason the time out is not specified is because it is protocol specific. Search for "connect" in the IBM documentation (link below). The second hit is a general discussion that may be of interest.

Generally, AIX uses the BSD model. I am not sure what Linux uses. I believe it is very close to the traditional BSD model but I also know that it differs in some subtleties.

Question 2: I would go to the IBM 5.3 Documentation the do some searches. For example, it says that SO_RCVTIMEO is not used. To be sure and positive, I would need to do a few experiments but I would be expect the connect to block. I see nothing that would prevent it. It would block forever. Part 2c I would do one of two ways. The easy way is to set a timer and when it pops, the system call will return with EINTR. The other choice is to set it to O_NONBLOCK and then use select with a timer argument to wait until it either connects or does not. Again, I'd have to experiment and debug the code to be precise.

无声情话 2024-09-08 09:28:49

a.以非阻塞或阻塞方式连接?

问题包含答案:您的套接字处于阻塞模式。

b.如果阻塞,是定时阻塞还是“无限”时间阻塞?

您可以使用选项 tcp_keepinit 使用实用程序 no 更改(全局)超时。默认值为 150 个单位,其中单位为 0.5 秒(即 75 秒)。

c.如果它是无限的,我如何建立一个“connect”系统调用,它是O_BLOCKING,超时为t秒。

不是无限的,但时间限制不能单独设置。灵活的解决方案是切换到非阻塞模式,并在connect返回EINPROGRESS时调用select/poll。如果套接字变得可写,则它已连接,否则选择/轮询超时。

a. connect in NON Blocking or Blocking?

The question contains the answer: your socket is in blocking mode.

b. If blocking, is it timed blocking or "infinite" time blocking?

You can change (globally) the timeout with utility program no using option tcp_keepinit. Default is 150 units, where unit is 0.5 sec (that is 75 sec).

c. If it is infinite, How do I establish a "connect" system call which is O_BLOCKING with timeout to t secs.

Not infinite, but the time-limit cannot be individually set. The flexible solution is switching to nonblocking mode, and call select/poll when connect returns EINPROGRESS. If the socket becomes writable, then it is connected, otherwise selct/poll timeouts.

绾颜 2024-09-08 09:28:48

全部,
经过一番搜索和扫描,终于找到了我的问题的答案。
我发布它是为了帮助其他可能面临同样问题的人。

问题:上述内容对 AIX 操作系统有效吗(特别是连接超时、定时等待等)?因为我在 AIX 手册页(5.1 和 5.3)中没有看到它

答案

来自大量搜索和一些帮助AIX 支持工程师发现手册页符合 POSIX 标准,并且对 AIX 和 SUSE 操作系统都有效。

由此证明,在极少数情况下,连接系统 API (O_BLOCK) 可以在未指定超时间隔的情况下阻塞

阻塞 以非阻塞或阻塞方式连接?
b.如果阻塞,是定时阻塞还是“无限”时间阻塞?
c.如果它是无限的,我如何建立一个“连接”系统调用,它是 O_BLOCKING,超时为 t 秒。

回答

a.如果为SO_RCVTIMEO 和/或SO_SNDTIMEO 指定了O_NONBLOCK,则它仅适用于这些API,即分别recv 和send API。

b.如果 connect API 用于阻塞调用,那么是的,connect 可以阻塞未指定的时间间隔。

事实证明,下面的链接是了解套接字编程内部结构的绝佳指南。

"http://www.ibm.com/ developerworks/aix/library/au-tcpsystemcalls/index.html"

感谢大家花时间回答我的问题。

All,
Was able to finally find the answers to my questions after a through search and scan.
I am posting it so that it helps others who may face the same problem.

Question : Is the above contents valid for AIX OS (especially the connection time-out, timed wait ...etc)?Because I do not see it in AIX man pages (5.1 and 5.3)

Answer

From lots of search and some help from AIX support engineer found out that the man pages confirm with POSIX standard and should be valid for both AIX and SUSE OS.

Thus it proves that connect system API (O_BLOCK) can block in case of rare scenarios for unspecified time-out interval

Question : Now since O_NONBLOCK is not set and SO_RCVTIMEO and SO_SNDTIMEO is set for 5 seconds, does it mean

a. connect in NON Blocking or Blocking?
b. If blocking, is it timed blocking or "infinite" time blocking?
c. If it is infinite, How do I establish a "connect" system call which is O_BLOCKING with timeout to t secs.

Answer

a.If O_NONBLOCK is specified for SO_RCVTIMEO and/or SO_SNDTIMEO, then it is applicable for only those API's, i.e recv and send API's respectively.

b. If connect API is used for blocking call, then yes, connect can block for unspecified amount of interval.

Below link proved to be an excellent guide to understanding socket programming internals.

"http://www.ibm.com/developerworks/aix/library/au-tcpsystemcalls/index.html"

Thanks all for chipping in some time for my question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文