开发者

AIX specific socket programming query

开发者 https://www.devze.com 2022-12-30 04:04 出处:网络
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

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.

开发者_StackOverflow 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号