UDP“阻塞套接字”是什么意思?当谈到通过它接收数据时?
如果套接字是非阻塞的,则读取操作的返回值为 0;如果套接字被标记为阻塞,则读取的实际字节数。虽然无法理解为什么......
这是在嵌入式操作系统上,但应该是 Berkely 套接字
I get the return value of the read operation as 0 if the sockets is non blocking, and the real number of bytes read if the socket is marked as blocking. cant understand why though ...
this is on an embedded OS, but supposed to be Berkely sockets
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阻塞读取将等待,直到有数据可供读取。非阻塞读取将始终立即返回(无论是否有 0 字节可用或更多)。
a blocking read will wait until there's data available to read. a non-blocking read will always return immediately (whether 0 bytes were available or more).
阻塞设置意味着当您从套接字读取数据时,它将停留在那里,直到发生两件事:1)您获取数据或 2)您收到信号。
非阻塞设置意味着当您尝试读取时,如果数据可用,它将返回它们。如果没有任何内容,它会立即返回而不是等待。如果您不想永远等待数据,并且同时想要做其他事情,例如进行计算、GUI 重绘或服务其他请求,那么这非常有用。
A blocking setup means that when you read data from the socket, it will stay stuck there until two things happen: 1) you get data or 2) you get a signal.
A non-blocking setup means that when you try to read, if data are available it will return them. If there is nothing it returns immediately instead of waiting. This is useful if you don't want to wait forever for data, and in the meantime you want to do something else, like doing computation, GUI redraw, or serve other requests.