Reusing socket descriptor on connection failure

后端 未结 5 602
逝去的感伤
逝去的感伤 2020-12-19 00:38

In my client code, I am following these steps to connect to a socket:

  1. Creating a socket

    sockDesc = socket(PF_INET, SOCK_STREAM, IPPROTO_TC         
    
    
            
5条回答
  •  时光说笑
    2020-12-19 01:22

    Sockets corresponding to broken connection is in unstable state. normally you will not be allowed to connect to again unless the operating system release the socket.

    I think it will be better to close() and connect again.. you don't have to create another socket.

    Anyway, make sure to set LINGER of your socket to ensure that no data is lost in transmision.

    See http://www.gnu.org/s/libc/manual/html_node/Socket_002dLevel-Options.html#Socket_002dLevel-Options

提交回复
热议问题