Problems with poll()/write() on non-blocking sockets
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Hello everyone, during stress testing of my network application I have found some strange behavior of Mac OS X sockets. I have a communication thread, that calls a poll() checking whether data can be written to a non-blocking socket. Upon exit from this function I check for POLLERR or POLLHUP and then perform a write() to the socket. If the write returns -1 and errno is set to EINTR or EAGAIN, I go back to poll. Otherwise I close the socket as there was an error. This works great most of the time, but during stress testing I found out a strange behavior (e.g. after 8 hours of video streaming). The poll() unblocks the socket and call to write() returns -1 with errno EAGAIN immediately. I go back to poll() and the same happens again leading to busy loop. I found one post telling that it is correct for poll() to unblock a socket and that the socket can become non-writable before I manage to call write(), but this is happing all the time for my socket and never recovers. Should I consider EAGAIN to be an error and close the connection? Wouldn't this cause another problems? I can't see another way out of this issue and I don't even understand why this is happening. I'm not asking for nor handling OUT-OF-BAND data flags in poll() but I don't think it could cause the problem. Another thing is, that Shark's System Trace keeps telling me that the syscall write returned 0x0 and not -1. Maybe a bug in C library? Can anyone please help me out of this or explain why is this happening? Thanks a lot, Jakub _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Jakub Bednar