开发者

Socket send () stuck in C

I'm trying to connect two machines, say machine A and B. I'm trying to send TCP message from A to B (One way). In normal scenario this works fine. When the communication is smooth, if the socket in B is closed, send() from A is stuck forever. And it puts process into Zombie state. I have socket in blocked mode in machine A. Below is the code that stuck forever.

           if (send (txSock,&txSockbuf,sizeof(sockstruct),0) == -1) {
                printf ("Error in sending the socket Data\n");
                            }
            else {
                printf ("The SENT String is %s \n",sock_buf);
            }

How do I开发者_如何转开发 find if the other side socket is closed?? What does send return if the destination socket is closed?? Would select be helpful.


A process in the "zombie" state means that it has already exited, but its parent has not yet read its return code. What's probably happening is that your process is receiving a SIGPIPE signal (this is what you'll get by default when you write to a closed socket), your program has already terminated, but the zombie state hasn't yet been resolved.

This related question gives more information about SIGPIPE and how to handle it: SIGPIPE, Broken pipe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜