int das_tmr_read_msg( resmgr_context_t *ctp, RESMGR_OCB_T *pocb, int num_entries) { static das_msg_t msg; /// don't allocate on stack static int pdata[QMM10XT_N_TIMERS]; unsigned int count; if ( ( count = qmm10xt_tmr_get_scan( pmain_board, pdata, num_entries ) ) != num_entries ) { fprintf(stderr, "TMR_READ: count %d driver count %d\n", num_entries, count); } /* * Setup message reply header and data buffer. */ msg.n = count; /// tells client how many were read #undef DO_TEST #ifdef DO_TEST { int i; for (i = 0; i < num_entries; i++) pdata[i] = i * 1000; } #endif SETIOV(&ctp->iov[0], &msg, sizeof(msg)); SETIOV(&ctp->iov[1], pdata, count * sizeof(unsigned)); MsgReplyv(ctp->rcvid, EOK, ctp->iov, 2); return (_RESMGR_NOREPLY); }
static int process_read_data(int rcvid, devi_attr_t *attr, devi_ocb_t *ocb, int nbytes) { int q_size; int num_req_packets; int num_pkts_xfer; int num_pkts_end; iov_t iov[3]; int parts = 1; char *ptr = NULL; event_bus_line_t *line = attr->line; if (line->head > ocb->read_ptr) q_size = line->head - ocb->read_ptr; else q_size = RESMGR_Q_SIZE - ocb->read_ptr + line->head; num_req_packets = nbytes / line->elem_size; if (num_req_packets == 0) MsgReply(rcvid, EOK, NULL, 0); if (q_size < num_req_packets) { return (-1); } num_pkts_xfer = min(num_req_packets, q_size); num_pkts_end = RESMGR_Q_SIZE - ocb->read_ptr; switch(line->type) { case DEVI_CLASS_KBD: ptr = (char *) line->u.kq; break; case DEVI_CLASS_REL: ptr = (char *) line->u.mq; break; case DEVI_CLASS_ABS: ptr = (char *) line->u.tq; break; } if (num_pkts_end >= num_pkts_xfer) SETIOV(&iov[0], ptr + line->elem_size * ocb->read_ptr, num_pkts_xfer * line->elem_size); else { SETIOV(&iov[0], ptr + line->elem_size * ocb->read_ptr, num_pkts_end * line->elem_size); num_pkts_xfer -= num_pkts_end; SETIOV(&iov[1], ptr, num_pkts_xfer * line->elem_size); parts = 2; } MsgReplyv(rcvid, num_pkts_xfer * line->elem_size, iov, parts); ocb->read_ptr = (ocb->read_ptr + num_pkts_xfer) % RESMGR_Q_SIZE; return (EOK); }
/* * Actually do the reply to the client described by the blocked pointer, and * then afterward we have replied free the blocked strucuture. */ static void _iofunc_lock_unblock(iofunc_lock_list_t *list, struct _iofunc_lock_blocked *blocked) { struct _msg_info info; struct _io_lock_reply reply; struct iovec iov[2]; //Some initial sanity checking ... if (MsgInfo(blocked->rcvid, &info) == EOK && blocked->pflock && blocked->pflock->l_sysid == info.scoid) { SETIOV(&iov[0], &reply, sizeof(reply)); SETIOV(&iov[1], blocked->pflock, sizeof(*blocked->pflock)); (void)MsgReplyv(blocked->rcvid, EOK, iov, 2); } _iofunc_blocked_free(blocked); }