part = KDBUS_PART_NEXT(part))
#define RECEIVE_POOL_SIZE (10 * 1024LU * 1024LU)
#define MEMFD_SIZE_THRESHOLD (2 * 1024 * 1024LU) // over this memfd is used
+//todo add compilation-time check if MEMFD_SIZE_THERSHOLD is lower than max payload vector size defined in kdbus.h
#define KDBUS_MSG_DECODE_DEBUG 0
if(use_memfd == TRUE) // bulk data - memfd
msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_memfd));
- else {
- msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
- if(body_size)
- msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
- }
+ else
+ {
+ msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec)); //header is a must
+ while(body_size > KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE)
+ {
+ msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
+ body_size -= KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE;
+ }
+ if(body_size)
+ msg_size += KDBUS_ITEM_SIZE(sizeof(struct kdbus_vec));
+ }
if(fds_count)
msg_size += KDBUS_ITEM_SIZE(sizeof(int)*fds_count);
uint64_t ret_size = 0;
uint64_t body_size = 0;
uint64_t header_size = 0;
- dbus_bool_t use_memfd;
+ dbus_bool_t use_memfd = FALSE;
const int *unix_fds;
unsigned fds_count;
dbus_bool_t autostart;
body_size = _dbus_string_get_length(body);
ret_size = header_size + body_size;
- // check if message size is big enough to use memfd kdbus transport
- use_memfd = ret_size > MEMFD_SIZE_THRESHOLD ? TRUE : FALSE;
- if(use_memfd) kdbus_init_memfd(transport);
+ // check whether we can and should use memfd
+ if((dst_id != KDBUS_DST_ID_BROADCAST) && (ret_size > MEMFD_SIZE_THRESHOLD))
+ {
+ use_memfd = TRUE;
+ kdbus_init_memfd(transport);
+ }
_dbus_message_get_unix_fds(message, &unix_fds, &fds_count);
// build message contents
item = msg->items;
- // case 1 - bulk data transfer - memfd
if(use_memfd)
{
char *buf;
_dbus_verbose("sending normal vector data\n");
MSG_ITEM_BUILD_VEC(_dbus_string_get_const_data(header), header_size);
- if(body_size)
+ if(body_size)
{
- _dbus_verbose("body attaching\n");
- item = KDBUS_PART_NEXT(item);
- MSG_ITEM_BUILD_VEC(_dbus_string_get_const_data(body), body_size);
+ const char* body_data;
+
+ body_data = _dbus_string_get_const_data(body);
+ while(body_size > KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE)
+ {
+ _dbus_verbose("body attaching\n");
+ item = KDBUS_PART_NEXT(item);
+ MSG_ITEM_BUILD_VEC(body_data, KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE);
+ body_data += KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE;
+ body_size -= KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE;
+ }
+ if(body_size)
+ {
+ _dbus_verbose("body attaching\n");
+ item = KDBUS_PART_NEXT(item);
+ MSG_ITEM_BUILD_VEC(body_data, body_size);
+ }
}
}