Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of documentation #124

Open
pituluk opened this issue Aug 4, 2024 · 3 comments
Open

Lack of documentation #124

pituluk opened this issue Aug 4, 2024 · 3 comments

Comments

@pituluk
Copy link

pituluk commented Aug 4, 2024

Why is this project so advanced yet so poorly documented?

@mutouyun
Copy link
Owner

mutouyun commented Aug 5, 2024

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.

@pituluk
Copy link
Author

pituluk commented Aug 5, 2024

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

@mutouyun
Copy link
Owner

mutouyun commented Aug 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants