static inline void add_poll(int h, int fd, int type, int flags, uint32_t user_id) { asrt(fd != -1); int i; int empty = -1; poll_slot_t* ps = ts[h].ps; for(i = 0; i < MAX_POLL; i++) { if(ps[i].pfd.fd == fd) { asrt(ts[h].poll_count < MAX_POLL); set_poll(&ps[i], fd, type, flags | ps[i].flags, user_id); return; } else if(empty < 0 && ps[i].pfd.fd == -1) empty = i; } if(empty >= 0) { asrt(ts[h].poll_count < MAX_POLL); set_poll(&ps[empty], fd, type, flags, user_id); ++ts[h].poll_count; return; } APPL_TRACE_ERROR1("exceeded max poll slot:%d!", MAX_POLL); }
bool update(const char * field, std::vector<uint8_t> data) { if (!strcmp(field, "dlpkt")) { return delete_packet(data); } else if (!strcmp(field, "dlcha")) { return delete_channel(data); } else if (!strcmp(field, "pnum")) { return set_pnumber(data); } else if (!strcmp(field, "chan")) { return set_channel(data); } else if (!strcmp(field, "pol")) { set_poll(data); } else if (!strcmp(field, "dir")) { const char * dirStr = byteVec2cstr(data); if (!strcmp(dirStr, "pos")) set_direction(DIR_POS); else if (!strcmp(dirStr, "neg")) set_direction(DIR_NEG); else return false; } else if (!strcmp(field, "data")) { return set_current(data); } else if (!strcmp(field, "wait")) { set_delay(data); } else if (!strcmp(field, "send")) { flag_return = true; send_packets(); } else if (!strcmp(field, "reset")) { send_global_reset(); } else if (!strcmp(field, "glob")) { set_global(); } else if (!strcmp(field, "conn")) { flag_return = true; return connect_serial(); } else if (!strcmp(field, "exit")) { return exit(); } else if (!strcmp(field, "clrpks")) { clear_packets(); } else if (!strcmp(field, "prev")) { if (debug_) preview_packets(); preview_packet_bytes(); flag_return = true; } else { return false; } return true; }