Why shutdown a socket can't let the select() return?

守給你的承諾、 提交于 2019-12-11 04:48:44

问题


In my program, there is a thread blocking on a listen socket, which waits for other connections, and the code likes this:

{
    ......
    FD_ZERO(&fd_sets);
    FD_SET(sock_fd, &fd_sets);

    ret_val = select(sock_fd + 1, &fd_sets, NULL, NULL, NULL);

    if (ret_val > 0)
    {
         accept(sock_fd, NULL, NULL);
         ......
    }
    else
    {
        ......
    }

Per my understandings, if in other thread, shutdown the socket, and the code likes this:

{
    ......
    shutdown(sock_fd, SHUT_RD);
    ......
}  

I think the select() in the previous thread should return. But after testing, I find the select() is still in blocking.

Why shutdown a socket can't let the select() return?

来源:https://stackoverflow.com/questions/18352039/why-shutdown-a-socket-cant-let-the-select-return

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!