码迷,mamicode.com
首页 > 其他好文 > 详细

阻塞套接字返回EAGAIN

时间:2015-08-21 01:47:12      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

今天用NDK写了一个通信程序,发现阻塞SOKCET 读写的时候返回了EAGAIN。NDK下PERROR输出为Try Again.查了半天头文件

 

在网上找到了原因。在此纪录。网址为http://blog.csdn.net/cleanfield/article/details/41649985

 

2)socket设置SO_RCVTIMEO和SO_SNDTIMEO对read/write有什么影响?看man怎么说

 

 

SO_RCVTIMEO and SO_SNDTIMEO

Specify the receiving or sending timeouts until reporting an error. The argument is a struct timeval. If an input or output function blocks for this period of time, and data has been sent or received, the return value of that function will be the amount of data transferred; if no data has been transferred and the timeout has been reached then -1 is returned witherrno set to EAGAIN or EWOULDBLOCK, or EINPROGRESS (for connect(2)) just as if the socket was specified to be nonblocking. If the timeout is set to zero (the default) then the operation will never timeout. Timeouts only have effect for system calls that perform socket I/O (e.g., read(2), recvmsg(2), send(2), sendmsg(2)); timeouts have no effect for select(2), poll(2), epoll_wait(2), and so on.

 

终于清晰了:SO_RCVTIMEO和SO_SNDTIMEO会导致read/write函数返回EAGAIN


另外,在确定错误过程中,同事提到O_NODELAY会导致write接口返回EAGAIN,的确,如果设置了O_NODELAY而当前不可写,那么write接口会设置errno为EAGAIN,但是write接口会返回0而不是-1.在本案中,hiredis接口中并没有设置O_NODELAY

阻塞套接字返回EAGAIN

标签:

原文地址:http://www.cnblogs.com/javado/p/4746657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!