int __conman_send_resp(struct conman_s *conman, uint8_t id, enum conman_resp_value respval, void *data, size_t datalen) { struct conman_resp_hdr hdr; int ret; hdr.head.id = id; hdr.head.len = datalen; hdr.respval = respval; ret = __conman_util_block_write(conman->servingsd, &hdr, sizeof(hdr)); if (ret < 0) { return ERROR; } ret = __conman_util_block_write(conman->servingsd, data, hdr.head.len); if (ret < 0) { return ERROR; } return OK; }
void __conman_send_boardcast_event(struct conman_s *conman, enum conman_msgs_ids type, const void *payload, size_t payloadlen) { struct conman_sd_entry_s *client; struct conman_resp_hdr hdr = {}; int send_count = 0; int ret; hdr.head.id = type; hdr.head.len = payloadlen; hdr.respval = CONMAN_RESP_EVENT; for (client = (struct conman_sd_entry_s *)sq_peek(&conman->server.sds); client != NULL; client = (struct conman_sd_entry_s *)sq_next(&client->entry)) { if (!client->events_enabled) { continue; } ret = __conman_util_block_write(client->sd, &hdr, sizeof(hdr)); if (ret < 0) { continue; } ret = __conman_util_block_write(client->sd, payload, hdr.head.len); if (ret < 0) { continue; } send_count++; } conman_dbg("send boardcast event (type=%d) to %d clients.\n", type, send_count); }
static int conman_send_reqv(int fd, uint8_t id, const struct iovec *bufs, size_t iovcnt) { struct conman_hdr hdr; size_t len = 0; size_t i; int ret; for (i = 0; i < iovcnt; i++) { len += bufs[i].iov_len; } hdr.id = id; hdr.len = len; ret = __conman_util_block_write(fd, &hdr, sizeof(hdr)); if (ret < 0) { return ERROR; } if (len > 0) { for (i = 0; i < iovcnt; i++) { ret = __conman_util_block_write(fd, bufs[i].iov_base, bufs[i].iov_len); if (ret < 0) { return ERROR; } } } return OK; }