skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.82k stars 207 forks source link

ErrorCode EPIPE -4047 Broken Pipe #276

Closed killghost closed 1 year ago

killghost commented 1 year ago

Client Code Like this

void Run() { while (1) { auto loop = uvw::Loop::getDefault(); auto tcp = loop.resource();

    tcp->on<uvw::ErrorEvent>([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* handle errors */ });

    tcp->once<uvw::ConnectEvent>([](const uvw::ConnectEvent &, uvw::TCPHandle &tcp) {
    auto dataWrite = std::unique_ptr<char[]>(new char[2]{ 'b', 'c' });
    tcp.write(std::move(dataWrite), 2);
    tcp.close();
    });

    tcp->connect(std::string{"127.0.0.1"}, 4242);
    loop.run();
}

}

I run a client program. Then restart the server repeatedly. After many times, the client will have EPIPE Broken PIPE -4047. Then after I restart the client, I can still connect to the server code I started last time. My main idea is to solve the problem that I need to reconnect after the server is disconnected. Any suggestions here? Is there something wrong with my code?

Thanks

killghost commented 1 year ago

I tested the pipe connection with the above code

skypjack commented 1 year ago

Ehi, sorry for the late reply. I was out for a short vacation last week and also managed to get a flu in the meantime. 😅😭 As for your question, uvw doesn't really add anything on top of libuv. Therefore, your question is better directed to the underlying library repo here.