+int out_sendmmsg(struct out_ctx *ctx, struct can_frame *cf)
+{
+ if (ctx->from_in == NOP)
+ return 0;
+
+ memcpy(ctx->bufs[ctx->current++], cf, sizeof(*cf));
+
+ if (ctx->from_in == SEND ||
+ ctx->current >= MMSG_MAX) {
+ int ret, i;
+ for (i = 0; i < ctx->current; i += ret)
+ ret = CHECK(sendmmsg(ctx->s, &ctx->msgs[i], ctx->current - i, 0));
+ ctx->current = 0;
+ }
+ return 0;
+}
+
+void init_sendmmsg(struct out_ctx *ctx)
+{
+ int i;
+
+ init_write(ctx);
+ ctx->out_fn = out_sendmmsg;
+ ctx->current = 0;
+ ctx->stored = 0;
+
+ memset(ctx->msgs, 0, sizeof(ctx->msgs));
+ memset(ctx->iovecs, 0, sizeof(ctx->iovecs));
+ for (i = 0; i < MMSG_MAX; i++) {
+ ctx->iovecs[i].iov_base = &ctx->bufs[i];
+ ctx->iovecs[i].iov_len = sizeof(struct can_frame);
+ ctx->msgs[i].msg_hdr.msg_iov = &ctx->iovecs[i];
+ ctx->msgs[i].msg_hdr.msg_iovlen = 1;
+ }
+}
+