Lack of documentation
Opened this issue · 3 comments
Why is this project so advanced yet so poorly documented?
I usually have little time to write open source library, the current documentation only one or two simple demo.In fact, I plan to complete the documentation after the code refactoring in the past two years.
I usually have little time to write open source library, the current documentation only one or two simple demo.In fact, I plan to complete the documentation after the code refactoring in the past two years.
can you atleast make some example of how to handle lost connections and reconnections
Side 1
ipc::channel rt{ "TestIPC" , ipc::sender | ipc::receiver };
rt.wait_for_recv(2);
while (true)
{
std::vector<unsigned char> packet = queue.dequeue();
if (!rt.try_send(packet.data(), packet.size(),50))
{
queue.clear();
rt.disconnect();
printf("send fail disconnect\n");
system("pause");
rt = ipc::channel{ "TestIPC" , ipc::sender | ipc::receiver };
rt.wait_for_recv(2);
printf("reconnected??\n");
if (!rt.try_send(packet.data(), packet.size(), 50))
{
printf("another send fail after reconnect\n");
}
}
else {
printf("send success?\n");
}
auto ack = rt.recv(50);
auto str = static_cast<char*>(ack.data());
if (str == nullptr)
{
printf("no ACK\n");
queue.clear();
rt.disconnect();
rt = ipc::channel{ "TestIPC" , ipc::sender | ipc::receiver };
rt.wait_for_recv(2);
connected = true;
}
else if(str[0] == 'a')
{
printf("Received ack\n");
}
else
{
printf("ack invalid val\n");
queue.clear();
rt.disconnect();
rt = ipc::channel{ "TestIPC" , ipc::sender | ipc::receiver };
rt.wait_for_recv(2);
connected = true;
}
printf("sent\n");
}
Side 2
ipc::channel cc;
int cleanIPC()
{
LogInstance.WriteLog("_onexit clean IPC");
cc.disconnect();
return 0;
}
DWORD IPCThread(void* p)
{
_onexit(cleanIPC);
cc = ipc::channel{ "TestIPC", ipc::receiver | ipc::sender };
cc.wait_for_recv(2);
while (true)
{
auto buf = cc.recv(); //gets stuck forever when program opened again after closing
cc.send(ipc::buff_t('a'));
std::vector<unsigned char> packetIPC = buf.to_vector();
dataReceived(packetIPC);
}
}
this code works until the other side disconnects, then when it connects again it stays in read forever and this code stays in send fail disconnect, reconnected??, no ACK loop
The current code implementation has defects for disconnection and reconnection, the reason is to ensure that the data will be delivered in broadcast mode (exactly once). If we did not need this feature, we would no longer need to connect and disconnect. I am currently planning a new version that will reduce QoS in broadcast mode, which will cause untimely messages to be overwritten, thus losing some messages, but the connection and disconnection will no longer be important.