c++ linux accept() blocking after socket closed

后端 未结 5 1406
醉话见心
醉话见心 2020-12-09 13:32

I have a thread that listens for new connections

new_fd = accept(Listen_fd, (struct sockaddr *) & their_addr, &sin_size);

and anoth

5条回答
  •  孤城傲影
    2020-12-09 13:48

    Are you checking the return value of close? From linux manpages, (http://www.kernel.org/doc/man-pages/online/pages/man2/close.2.html) "It is probably unwise to close file descriptors while they may be in use by system calls in other threads in the same process. Since a file descriptor may be reused, there are some obscure race conditions that may cause unintended side effects". You can use a select instead of an accept and wait for some event from the other thead, then close the socket in the listener thread.

提交回复
热议问题