Skip to content

Best approach for handling struct / class #140

Open
@Petingo

Description

@Petingo

您好,

最近有個專案需要高效能的 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions