开发者

Does the VxWorks sockLib support the SO_RCVTIMEO option that can be used by setsockopt to set the timeout of a recv call like in winsock?

开发者 https://www.devze.com 2023-03-16 05:11 出处:网络
Does the VxWorks sockLib suppor开发者_如何学运维t the SO_RCVTIMEO option that can be used by setsockopt to set the timeout of a recv call like in winsock?

Does the VxWorks sockLib suppor开发者_如何学运维t the SO_RCVTIMEO option that can be used by setsockopt to set the timeout of a recv call like in winsock?

Here is an example of the call in Windows:

int timeout = 30000; // 30 seconds
status = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(int));

The confusing thing about this is that the status returned by setsockopt does not indicate an error from an unknown option and SO_RCVTIMEO is defined in sockets.h. The call still does not produce the desired action though and I can't find any documentation saying that it is supported.

If it is not supported, any suggestions for an equivalent approach?

I am using VxWorks 5.4. I would be interested to know if it works in a later version.


I cannot answer this question directly, but I can say that to solve these types of "blocking receive" style problems, use the select() function to specify a timeout while waiting on incoming socket data. Then you can avoid the blocking recv() call entirely until you know there is data available in the socket.

I recommend this solution for VxWorks (#include "selectLib.h") as well as for Linux and Windows socket libraries. SO_RCVTIMEO is useful, but select() is even more useful, across all operating systems.

0

精彩评论

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