Socket listen doesn't unbind in C++ under linux

后端 未结 3 834
自闭症患者
自闭症患者 2021-01-11 17:12

I have a socket that listens on some port. I send the SIGSTOP signal to the thread that waits on the port (using accept) and terminate it. then I close the fd of the socket

3条回答
  •  旧巷少年郎
    2021-01-11 17:47

    Did you know that sockets are typically kept in a kind of limbo for a minute or two after you've finished listening on them to prevent communications intended for the previous process coming to yours? It's called the 'TIME_WAIT' state.

    If you want to override that behaviour use setsockopt to set the SO_REUSEADDR flag against the socket before listening on it.

提交回复
热议问题