Skip to content

Best approach for handling struct / class #140

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

Open
Petingo opened this issue Mar 14, 2025 · 1 comment
Open

Best approach for handling struct / class #140

Petingo opened this issue Mar 14, 2025 · 1 comment

Comments

@Petingo
Copy link

Petingo commented Mar 14, 2025

您好,

最近有個專案需要高效能的 IPC 於是嘗試了一下這個庫,感覺相當不錯!
但目前有個問題,就是他經常會報錯 fail: send, there is no receiver on this connection.,但我看起來資料是有正確被接收到的,想請問有什麼原因可能造成這個問題?

另外想請問一下,傳送 struct / class 最好的方式是什麼?目前是用以下的 code,但我的理解是這樣其實是需要一次 copy 的?是否有辦法做到 zero copy?

// sender
while(1) {
    // generate values...

    Message msg(value1, value2);
    outputRoute.wait_for_recv(1);
    outputRoute.send(ipc::buff_t(&msg, sizeof(msg)));
}
// receiver
while(1) {
    auto buf = m_inputRoute.recv();
    auto newMsg = static_cast<Message*>(buf.data());
    if (newMsg == nullptr) continue;

    // process data ...
}

非常感謝!

P.S. 測試平台是 windows 11

@Petingo Petingo changed the title fail: send, there is no receiver on this connection. Got fail: send, there is no receiver on this connection., but sent successfully Mar 14, 2025
@Petingo Petingo changed the title Got fail: send, there is no receiver on this connection., but sent successfully Best approach for handling struct / class Mar 14, 2025
@mutouyun
Copy link
Owner

嗯。。现在这个库由于维护了一个粗糙的连接概念,所以对意外退出很不友好。。必须在退出之前保证清理操作。
fail: send, there is no receiver on this connection. 的报错一般是由于某次意外退出导致的。

当前库内的共享内存池并没有提供给外部当作逻辑数据结构使用的接口,而仅作为传递过程来使用,因此确实一定会有一次拷贝。

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