Only wake up one thread when use SO_REUSEADDR
caozhiyi opened this issue · comments
When I bind multi socket to the same port by SO_REUSEADDR, and one socket per thread. only wake up one thread.
Maybe it's the wrong way I use it? But I use wepoll same as epoll.
When I bind multi socket to the same port by SO_REUSEADDR, and one socket per thread.
Try binding multiple sockets to the same port using SO_REUSEADDR, and then do a blocking accept (using multiple threads). Does it work?
Instead of blocking accept. Each socket is individually bound to a wepoll handle, Then each thread blocks in epoll_wait function. When connections request comes, only one thread will wake up.
There is no problem when multiple threads use only one wepoll handle.
When I bind multi socket to the same port by SO_REUSEADDR, and one socket per thread
I don't think windows supports your scenario.
My suggestion would be to create 1 server socket and share it among the different threads. You can associate this socket with multiple wepoll handles, so it is still possible to use a separate wepoll handle for each thread.
Thank you. I'll have a try.