Socket write out Epipe error

Source: Internet
Author: User

Recently got a program to use the UNIX socket for interprocess communication, found that sometimes when the client calls the Write function, the return value is -1,errno as Epipe. It was found that the connection had been closed.

But my client is clearly the first connection, also did not complain, and then write, why will the connection closed.

After testing, is the service side, and then the client write, if this time correct, then the service side, client write, inevitable error, and then restart the server, the client write must be correct, so correct and wrong intersection. It seems that the problem is here.

Then check the client code, found in order to reduce the server load, the client each write, there is no close connection, the next time with the same connection to send messages, and not every time to connect to the servers:

if ( -1 = re_conn)
{
Re_conn = Connect_unix_socket (Ip_unix_socket_path,sock_stream);
}

The connection is judged.

Therefore, the service side, will inevitably lead to a connection aborted, but the next client does not necessarily go to reconnect, because Re_conn is probably not-1, so write would fail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.