EAGAIN 错误:使用 Berkeley Socket API [英] EAGAIN Error: Using Berkeley Socket API

查看:32
本文介绍了EAGAIN 错误:使用 Berkeley Socket API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时当我尝试连续发送一些数据包时(我正在使用 send() API),我会收到此错误.现在我不知道我应该怎么做.我有这些问题:1)我可以重新发送吗?如果是,那么在多长时间后我应该再试一次.有什么特别的策略要遵循

Sometimes when I try to send some packets continuously( I am using the send() API ) I receive this error. Now I am not sure what should I do than. I have these questions: 1) Can I re-send again ? If yes then after how much time should I try again. Is there any particular strategy to be followed

2) 缓冲区大小是否超过其限制是唯一的原因?

2) Is buffer size has exceeded its limits is the only reason ?

3)有人可以给我一个更好的想法/代码,如何处理这种情况.

3) Can someone please give me a better idea/code, how to handle such scenario.

谢谢.桑比特.

推荐答案

来自 send(): "EAGAIN -- 套接字被标记为非阻塞,请求的操作将阻塞."还有

From send(): "EAGAIN -- The socket is marked non-blocking and the requested operation would block." and also

当消息不适合套接字的发送缓冲区时,正常发送会阻塞,除非套接字已置于非阻塞 I/O 模式.在非阻塞模式下,它会在这种情况下返回 EAGAIN.select(2) 调用可用于确定何时可以发送更多数据.
When the message does not fit into the send buffer of the socket, send normally blocks, unless the socket has been placed in non-blocking I/O mode. In non-blocking mode it would return EAGAIN in this case. The select(2) call may be used to determine when it is possible to send more data.

这个话题使用 select() 处理 EAGAIN 的简单示例,然后是关于隐藏在表面之下的惊喜类型的重要讨论.

This thread has a simple example of using select() to deal with EAGAIN, and is followed by significant discussion about what sorts of surprises lurk beneath the surface.

这篇关于EAGAIN 错误:使用 Berkeley Socket API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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