英文:
will socket error be detected across threads?
问题
The socket is non-blocking and uses epoll. When write encounters error, it will close the socket. My question is, at this point will the read thread return from the epoll wait with error?
英文:
I have two threads working on the same socket, one for read and the other for write. The socket is non-blocking and uses epoll. When write encounters error, it will close the socket. My question is, at this point will the read thread return from the epoll wait with error?
答案1
得分: 2
这种行为是特定于平台的,所以要持怀疑态度。
通常情况下,答案通常是肯定的,但也可能是否定的。
关闭套接字会阻止进一步的读写操作,因此如果写线程决定关闭套接字,读线程就无法从同一个套接字读取。
这通常会导致读取错误。然而,我已经被告知有一些情况下这并不总是成立。所以,最好不要依赖这种行为,如果可以的话。
英文:
This behavior is platform-specific, so take this with a grain of salt.
Generally, the answer is usually yes, but it may be no, too.
Closing a socket prevents any further reading and writing on it, so if the writing thread decides to close the socket, the reading thread can't read from the same socket anymore.
This will usually cause a read error. However, I have been informed of cases here and there where this is not always true. So, best not to rely on this behavior, if you can help it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论