实时操作系统上的 UDP 非阻塞套接字:sendto() 和 recvfrom() 可以返回部分消息? [英] UDP non-blocking socket on a real-time OS: sendto() and recvfrom() can return with partial message?

查看:111
本文介绍了实时操作系统上的 UDP 非阻塞套接字:sendto() 和 recvfrom() 可以返回部分消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里的第一条消息.我正在实时操作系统(OnTime 和 VxWorks)上使用非阻塞 UDP 套接字.我已经阅读了文档和一些论坛,但我对 sendto() 和 recvfrom() 函数的原子性"有一些疑问:

This is my first message here. I'm working with a non-blocking UDP socket on a real-time OS (OnTime and VxWorks). I have read the documentation and some forums but I have some doubts about 'atomicity' of sendto() and recvfrom() functions:

  • sendto() 返回入队或错误的字节数.它是否可能小于输入缓冲区长度?也许输出缓冲区没有足够的可用空间,只有几个字节被排队......

  • sendto() returns the number of bytes enqueued or error. Is it possible that it's less then the input buffer length? Maybe the output buffer has not enough free space and just few bytes are enqueued...

recvfrom() 返回接收或错误的字节数.它是否可能小于源发送的消息大小?我的意思是部分消息阅读...

recvfrom() returns the number of byte received or error. Is it possible that it's less then the size of message the source has sent? I mean partial message reading...

我希望读写函数是原子的(完整消息或无消息读/写).

I hopes reading and writing functions are atomic (full message or no message read/write).

谢谢.伊曼纽尔.

我要求 OnTime 支持,他们告诉我如果输出缓冲区没有足够的可用空间,sendto() 可能会将部分消息排入队列.我不知道在某些情况下 recvfrom() 是否也可以返回部分消息.我想不同操作系统之间的套接字实现没有标准行为.

I asked to OnTime support and they told me that it's possible that sendto() will enqueue a partial message if the output buffer has not enough free space. I don't know if also recvfrom() could return a partial message in some cases. I suppose that there's no standard behavior on socket implementations among different OS.

推荐答案

我对这些系统并不是很熟悉,但如果它们破坏了正常的 UDP 套接字语义,我会感到非常惊讶,即总是将完整的数据报排入队列发送"并在接收"时将完整的单个数据报出列.

I'm not really familiar with these systems, but I would be very surprised if they break normal UDP socket semantics, which is always to enqueue a full datagram on "send" and to dequeue a full single datagram on a "receive".

这篇关于实时操作系统上的 UDP 非阻塞套接字:sendto() 和 recvfrom() 可以返回部分消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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