Linux Socket: How to detect disconnected network in a client program?

后端 未结 4 1354
盖世英雄少女心
盖世英雄少女心 2020-12-24 03:29

I am debugging a c based linux socket program. As all the examples available in websites, I applied the following structure:

sockfd= socket(AF_INET, SOCK_STR         


        
4条回答
  •  悲&欢浪女
    2020-12-24 04:03

    Check the return value, and see if it's equal to this value:

    EPIPE
    This socket was connected but the connection is now broken. In this case, send generates a SIGPIPE signal first; if that signal is ignored or blocked, or if its handler returns, then send fails with EPIPE.

    Also add a check for the SIGPIPE signal in your handler, to make it be more controllable.

提交回复
热议问题