eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.6k stars 373 forks source link

how to use userheader in the untyped request/response #1336

Open qclzdh opened 2 years ago

qclzdh commented 2 years ago

If i have a common IPC send function as following code, parameter msgPayload is untyped, it may changed according some other conditions, and paramter cnt is the number of msgPayload, so the total size i want to send is header + sizeof(msgPayload) * count

bool sendBroadcast(
    const msgHeader& header,
    const msgPayload* payload,
    const uint32_t& cnt)

it is very easy to wrap by using iox untyped_publisher funtions, since loan functions of untyped_publisher has "head" paramter.

loan(const uint32_t userPayloadSize,
         const uint32_t userPayloadAlignment = iox::CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT,
         const uint32_t userHeaderSize = iox::CHUNK_NO_USER_HEADER_SIZE,
         const uint32_t userHeaderAlignment = iox::CHUNK_NO_USER_HEADER_ALIGNMENT)

and i can easily wrap like this,

loan(sizeof(msgPayload) * cnt, alignof(msgPayload), sizeof(msgHeader), alignof(msgHeader));

but how do i use customer header and untyped payload in request/response, it looks like request/response header size is fixed

cxx::expected<void*, AllocationError> UntypedClientImpl<BaseClientT>::loan(const uint32_t payloadSize,
                                                                           const uint32_t payloadAlignment) noexcept

cxx::expected<void*, AllocationError> UntypedServerImpl<BaseServerT>::loan(const RequestHeader* const requestHeader,
                                                                           const uint32_t payloadSize,
                                                                           const uint32_t payloadAlignment) noexcept
elBoberido commented 2 years ago

@qclzdh request-response does not support a user-header since it already uses that portion of the chunk for it's own header. This means the segmentation must be done by the user on the user-payload portion of the chunk

qclzdh commented 2 years ago

@elBoberido Thanks, if there is no smart way, i will pack them together. It looks a little ugly, but should work well.

qclzdh commented 2 years ago

@elBoberido is there any limitation about payloadAlignment, for example payloadSize % payloadAlignment must equal to 0 ?

elBoberido commented 2 years ago

@qclzdh it's not the most convenient solution but should work. If there is a big demand for a user-header with request-response we can think of extending the API but it might become quite complex on the implementation side

elBoberido commented 2 years ago

@elBoberido is there any limitation about payloadAlignment, for example payloadSize % payloadAlignment must equal to 0 ?

@qclzdh yes, the assumption was that the payload will contain a struct and therefore the same restrictions apply

qclzdh commented 2 years ago

@qclzdh it's not the most convenient solution but should work. If there is a big demand for a user-header with request-response we can think of extending the API but it might become quite complex on the implementation side

Yes, userHeader is mandatory, please consider to extend the API.

mossmaurice commented 1 year ago

@qclzdh @elBoberido I've not come to a final conclusion, but my feeling is the custom user header could also be helpful for rmw_iceoryx, see here: https://github.com/ros2/rmw_iceoryx/pull/84

qclzdh commented 1 year ago

From a user point view, a custom user header would be much more helpful, it's better to support this kind of feature.