+static void process_client_cmd(int sock, struct ustcomm_header *req_header,
+ char *recvbuf, struct libustd_instance *instance)
+{
+ int result;
+ struct ustcomm_header _res_header;
+ struct ustcomm_header *res_header = &_res_header;
+ struct ustcomm_buffer_info *buf_inf;
+
+ DBG("Processing client command");
+
+ switch (req_header->command) {
+ case CONSUME_BUFFER:
+
+ buf_inf = (struct ustcomm_buffer_info *)recvbuf;
+ result = ustcomm_unpack_buffer_info(buf_inf);
+ if (result < 0) {
+ ERR("Couldn't unpack buffer info");
+ return;
+ }
+
+ DBG("Going to consume buffer %s_%d in process %d",
+ buf_inf->channel, buf_inf->ch_cpu, buf_inf->pid);
+ result = start_consuming_buffer(instance, buf_inf->pid,
+ buf_inf->channel,
+ buf_inf->ch_cpu);
+ if (result < 0) {
+ ERR("error in add_buffer");
+ return;
+ }
+
+ res_header->result = 0;
+ break;
+ case EXIT:
+ res_header->result = 0;
+ /* Only there to force poll to return */
+ break;
+ default:
+ res_header->result = -EINVAL;
+ WARN("unknown command: %d", req_header->command);
+ }
+
+ if (ustcomm_send(sock, res_header, NULL) <= 0) {
+ ERR("couldn't send command response");
+ }
+}
+
+#define MAX_EVENTS 10