今天用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