This means the API can stay the same as for single-part messages by simply passing the head message around. Unrefing
the head of the linked list unrefs the whole list.
size_t *rta_offset_tb[RTNL_CONTAINER_DEPTH];
unsigned short rta_tb_size[RTNL_CONTAINER_DEPTH];
bool sealed:1;
size_t *rta_offset_tb[RTNL_CONTAINER_DEPTH];
unsigned short rta_tb_size[RTNL_CONTAINER_DEPTH];
bool sealed:1;
+
+ sd_rtnl_message *next; /* next in a chain of multi-part messages */
};
int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type);
};
int message_new(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t type);
for (i = 0; i <= m->n_containers; i++)
free(m->rta_offset_tb[i]);
for (i = 0; i <= m->n_containers; i++)
free(m->rta_offset_tb[i]);
+ sd_rtnl_message_unref(m->next);
+
* On failure, a negative error code is returned.
*/
int socket_read_message(sd_rtnl *rtnl) {
* On failure, a negative error code is returned.
*/
int socket_read_message(sd_rtnl *rtnl) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *first = NULL;
+ sd_rtnl_message *previous = NULL;
_cleanup_free_ void *buffer = NULL;
uint8_t cred_buffer[CMSG_SPACE(sizeof(struct ucred))];
struct iovec iov = {};
_cleanup_free_ void *buffer = NULL;
uint8_t cred_buffer[CMSG_SPACE(sizeof(struct ucred))];
struct iovec iov = {};
if (new_msg->nlmsg_type == NLMSG_NOOP)
continue;
if (new_msg->nlmsg_type == NLMSG_NOOP)
continue;
+ /* finished reading multi-part message */
+ if (new_msg->nlmsg_type == NLMSG_DONE)
+ break;
+
/* check that we support this message type */
r = type_system_get_type(NULL, &nl_type, new_msg->nlmsg_type);
if (r < 0) {
/* check that we support this message type */
r = type_system_get_type(NULL, &nl_type, new_msg->nlmsg_type);
if (r < 0) {
- r = rtnl_rqueue_make_room(rtnl);
- if (r < 0)
- return r;
+ if (!first)
+ first = m;
+ else {
+ assert(previous);
- rtnl->rqueue[rtnl->rqueue_size ++] = m;
+ previous->next = m;
+ }
+ previous = m;
ret += new_msg->nlmsg_len;
ret += new_msg->nlmsg_len;
- /* reached end of multi-part message, or not a multi-part
- message at all */
- if (new_msg->nlmsg_type == NLMSG_DONE ||
- !(new_msg->nlmsg_flags & NLM_F_MULTI))
+ /* not a multi-part message, so stop reading*/
+ if (!(new_msg->nlmsg_flags & NLM_F_MULTI))
+ r = rtnl_rqueue_make_room(rtnl);
+ if (r < 0)
+ return r;
+
+ rtnl->rqueue[rtnl->rqueue_size ++] = first;
+ first = NULL;
+
+
+sd_rtnl_message *sd_rtnl_message_next(sd_rtnl_message *m) {
+ assert_return(m, NULL);
+
+ return m->next;
+}
int sd_rtnl_message_rewind(sd_rtnl_message *m);
int sd_rtnl_message_rewind(sd_rtnl_message *m);
+sd_rtnl_message *sd_rtnl_message_next(sd_rtnl_message *m);
+
_SD_END_DECLARATIONS;
#endif
_SD_END_DECLARATIONS;
#endif