/** * tipc_msg_bundle(): Append contents of a buffer to tail of an existing one * @list: the buffer chain of the existing buffer ("bundle") * @skb: buffer to be appended * @mtu: max allowable size for the bundle buffer * Consumes buffer if successful * Returns true if bundling could be performed, otherwise false */ bool tipc_msg_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu) { struct sk_buff *bskb = skb_peek_tail(list); struct tipc_msg *bmsg = buf_msg(bskb); struct tipc_msg *msg = buf_msg(skb); unsigned int bsz = msg_size(bmsg); unsigned int msz = msg_size(msg); u32 start = align(bsz); u32 max = mtu - INT_H_SIZE; u32 pad = start - bsz; if (likely(msg_user(msg) == MSG_FRAGMENTER)) return false; if (unlikely(msg_user(msg) == CHANGEOVER_PROTOCOL)) return false; if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) return false; if (likely(msg_user(bmsg) != MSG_BUNDLER)) return false; if (likely(!TIPC_SKB_CB(bskb)->bundling)) return false; if (unlikely(skb_tailroom(bskb) < (pad + msz))) return false; if (unlikely(max < (start + msz))) return false; skb_put(bskb, pad + msz); skb_copy_to_linear_data_offset(bskb, start, skb->data, msz); msg_set_size(bmsg, start + msz); msg_set_msgcnt(bmsg, msg_msgcnt(bmsg) + 1); kfree_skb(skb); return true; }
static void he_recv_message(nth_engine_t * he, tport_t * tport, msg_t *msg, void *arg, su_time_t now) { nth_client_t *hc, **hcp; tp_name_t const *tpn; for (hcp = hc_htable_hash(he->he_clients, (hash_value_t)(uintptr_t) tport); (hc = *hcp); hcp = hc_htable_next(he->he_clients, hcp)) { if (hc->hc_tport == tport) { if (hc_recv(hc, msg, http_object(msg)) < 0) msg_destroy(msg); return; } } /* Extra response? Framing error? */ tpn = tport_name(tport); if (msg_size(msg)) SU_DEBUG_3(("nth client: received extra data ("MOD_ZU" bytes) " "from %s/%s:%s\n", (size_t)msg_size(msg), tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port)); else SU_DEBUG_3(("nth client: received extra data from %s/%s:%s\n", tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port)); msg_destroy(msg); tport_shutdown(tport, 2); }
/** * tipc_msg_make_bundle(): Create bundle buf and append message to its tail * @list: the buffer chain * @skb: buffer to be appended and replaced * @mtu: max allowable size for the bundle buffer, inclusive header * @dnode: destination node for message. (Not always present in header) * Replaces buffer if successful * Returns true if success, otherwise false */ bool tipc_msg_make_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu, u32 dnode) { struct sk_buff *bskb; struct tipc_msg *bmsg; struct tipc_msg *msg = buf_msg(skb); u32 msz = msg_size(msg); u32 max = mtu - INT_H_SIZE; if (msg_user(msg) == MSG_FRAGMENTER) return false; if (msg_user(msg) == CHANGEOVER_PROTOCOL) return false; if (msg_user(msg) == BCAST_PROTOCOL) return false; if (msz > (max / 2)) return false; bskb = tipc_buf_acquire(max); if (!bskb) return false; skb_trim(bskb, INT_H_SIZE); bmsg = buf_msg(bskb); tipc_msg_init(bmsg, MSG_BUNDLER, 0, INT_H_SIZE, dnode); msg_set_seqno(bmsg, msg_seqno(msg)); msg_set_ack(bmsg, msg_ack(msg)); msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); TIPC_SKB_CB(bskb)->bundling = true; __skb_queue_tail(list, bskb); return tipc_msg_bundle(list, skb, mtu); }
/** * tipc_msg_reverse(): swap source and destination addresses and add error code * @buf: buffer containing message to be reversed * @dnode: return value: node where to send message after reversal * @err: error code to be set in message * Consumes buffer if failure * Returns true if success, otherwise false */ bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err) { struct tipc_msg *msg = buf_msg(buf); uint imp = msg_importance(msg); struct tipc_msg ohdr; uint rdsz = min_t(uint, msg_data_sz(msg), MAX_FORWARD_SIZE); if (skb_linearize(buf)) goto exit; if (msg_dest_droppable(msg)) goto exit; if (msg_errcode(msg)) goto exit; memcpy(&ohdr, msg, msg_hdr_sz(msg)); imp = min_t(uint, imp + 1, TIPC_CRITICAL_IMPORTANCE); if (msg_isdata(msg)) msg_set_importance(msg, imp); msg_set_errcode(msg, err); msg_set_origport(msg, msg_destport(&ohdr)); msg_set_destport(msg, msg_origport(&ohdr)); msg_set_prevnode(msg, tipc_own_addr); if (!msg_short(msg)) { msg_set_orignode(msg, msg_destnode(&ohdr)); msg_set_destnode(msg, msg_orignode(&ohdr)); } msg_set_size(msg, msg_hdr_sz(msg) + rdsz); skb_trim(buf, msg_size(msg)); skb_orphan(buf); *dnode = msg_orignode(&ohdr); return true; exit: kfree_skb(buf); return false; }
static void mqtt_socket_sent(void *arg) { NODE_DBG("enter mqtt_socket_sent.\n"); struct espconn *pesp_conn = arg; if(pesp_conn == NULL) return; lmqtt_userdata *mud = (lmqtt_userdata *)pesp_conn->reverse; if(mud == NULL) return; if(!mud->connected) return; // call mqtt_sent() mud->event_timeout = 0; mud->keep_alive_tick = 0; if(mud->connState == MQTT_CONNECT_SENDING){ mud->connState = MQTT_CONNECT_SENT; // MQTT_CONNECT not queued. return; } NODE_DBG("sent1, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); // qos = 0, publish and forgot. msg_queue_t *node = msg_peek(&(mud->mqtt_state.pending_msg_q)); if(node && node->msg_type == MQTT_MSG_TYPE_PUBLISH && node->publish_qos == 0) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); if(mud->cb_puback_ref == LUA_NOREF) return; if(mud->self_ref == LUA_NOREF) return; if(mud->L == NULL) return; lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->cb_puback_ref); lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->self_ref); // pass the userdata to callback func in lua lua_call(mud->L, 1, 0); } else if(node && node->msg_type == MQTT_MSG_TYPE_PUBACK && node->publish_qos == 1) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } else if(node && node->msg_type == MQTT_MSG_TYPE_PUBCOMP) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } else if(node && node->msg_type == MQTT_MSG_TYPE_PINGREQ) { msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } NODE_DBG("sent2, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); NODE_DBG("leave mqtt_socket_sent.\n"); }
/** * iucvtty_write_msg() - Write/Send IUCV message * @fd: File descriptor * @msg: Pointer to IUCV message */ int iucvtty_write_msg(int fd, struct iucvtty_msg *msg) { msg->version = MSG_VERSION; if (__write(fd, msg, msg_size(msg)) <= 0) return -1; #ifdef __DEBUG__ __dump_msg(fd, msg, 'S'); #endif return 0; }
void EditorScreen::resize(const Size& size_) { gui_manager->set_rect(Rect(Vector2i(0, 0), size_)); { Size msg_size(600, 160); m_level_new_msgbox->set_rect(Rect(Vector2i((Display::get_width() - msg_size.width)/2, (Display::get_height() - msg_size.height)/2), msg_size)); } update_layout(); }
static int recv_msg(struct sk_buff *buf, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv; u32 size; if (likely(eb_ptr->bearer)) { size = msg_size((struct tipc_msg *)buf->data); skb_trim(buf, size); if (likely(buf->len == size)) { buf->next = NULL; tipc_recv_msg(buf, eb_ptr->bearer); } else { kfree_skb(buf); } } else { kfree_skb(buf); } return TIPC_OK; }
/** * iucvtty_rx_termenv() - Receive terminal environment variable * @fd: File descriptor to read data from * @buf: Buffer to store the terminal environment variable * @len: Size of buffer @buf */ int iucvtty_rx_termenv(int fd, void *buf, size_t len) { int rc; size_t skip; struct iucvtty_msg *msg = msg_alloc(MSG_TYPE_TERMENV, len); if (msg == NULL) return -1; skip = 0; rc = iucvtty_read_msg(fd, msg, msg_size(msg), &skip); iucvtty_skip_msg_residual(fd, &skip); if (!rc) { if (msg->datalen == 0) memset(buf, 0, min(1, len)); else msg_cpy_to(msg, buf, len); } msg_free(msg); return rc; }
static int recv_msg(struct sk_buff *buf, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv; u32 size; if (likely(eb_ptr->bearer)) { if (likely(!dev->promiscuity) || !memcmp(buf->mac.raw,dev->dev_addr,ETH_ALEN) || !memcmp(buf->mac.raw,dev->broadcast,ETH_ALEN)) { size = msg_size((struct tipc_msg *)buf->data); skb_trim(buf, size); if (likely(buf->len == size)) { buf->next = NULL; tipc_recv_msg(buf, eb_ptr->bearer); return TIPC_OK; } } } kfree_skb(buf); return TIPC_OK; }
void tipc_net_route_msg(struct sk_buff *buf) { struct tipc_msg *msg; u32 dnode; if (!buf) return; msg = buf_msg(buf); /* Handle message for this node */ dnode = msg_short(msg) ? tipc_own_addr : msg_destnode(msg); if (tipc_in_scope(dnode, tipc_own_addr)) { if (msg_isdata(msg)) { if (msg_mcast(msg)) tipc_port_mcast_rcv(buf, NULL); else if (msg_destport(msg)) tipc_port_rcv(buf); else net_route_named_msg(buf); return; } switch (msg_user(msg)) { case NAME_DISTRIBUTOR: tipc_named_rcv(buf); break; case CONN_MANAGER: tipc_port_proto_rcv(buf); break; default: kfree_skb(buf); } return; } /* Handle message for another node */ skb_trim(buf, msg_size(msg)); tipc_link_xmit(buf, dnode, msg_link_selector(msg)); }
void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str) { u32 usr = msg_user(msg); tipc_printf(buf, KERN_DEBUG); tipc_printf(buf, str); switch (usr) { case MSG_BUNDLER: tipc_printf(buf, "BNDL::"); tipc_printf(buf, "MSGS(%u):", msg_msgcnt(msg)); break; case BCAST_PROTOCOL: tipc_printf(buf, "BCASTP::"); break; case MSG_FRAGMENTER: tipc_printf(buf, "FRAGM::"); switch (msg_type(msg)) { case FIRST_FRAGMENT: tipc_printf(buf, "FIRST:"); break; case FRAGMENT: tipc_printf(buf, "BODY:"); break; case LAST_FRAGMENT: tipc_printf(buf, "LAST:"); break; default: tipc_printf(buf, "UNKNOWN:%x", msg_type(msg)); } tipc_printf(buf, "NO(%u/%u):", msg_long_msgno(msg), msg_fragm_no(msg)); break; case TIPC_LOW_IMPORTANCE: case TIPC_MEDIUM_IMPORTANCE: case TIPC_HIGH_IMPORTANCE: case TIPC_CRITICAL_IMPORTANCE: tipc_printf(buf, "DAT%u:", msg_user(msg)); if (msg_short(msg)) { tipc_printf(buf, "CON:"); break; } switch (msg_type(msg)) { case TIPC_CONN_MSG: tipc_printf(buf, "CON:"); break; case TIPC_MCAST_MSG: tipc_printf(buf, "MCST:"); break; case TIPC_NAMED_MSG: tipc_printf(buf, "NAM:"); break; case TIPC_DIRECT_MSG: tipc_printf(buf, "DIR:"); break; default: tipc_printf(buf, "UNKNOWN TYPE %u", msg_type(msg)); } if (msg_reroute_cnt(msg)) tipc_printf(buf, "REROUTED(%u):", msg_reroute_cnt(msg)); break; case NAME_DISTRIBUTOR: tipc_printf(buf, "NMD::"); switch (msg_type(msg)) { case PUBLICATION: tipc_printf(buf, "PUBL(%u):", (msg_size(msg) - msg_hdr_sz(msg)) / 20); /* Items */ break; case WITHDRAWAL: tipc_printf(buf, "WDRW:"); break; default: tipc_printf(buf, "UNKNOWN:%x", msg_type(msg)); } if (msg_reroute_cnt(msg)) tipc_printf(buf, "REROUTED(%u):", msg_reroute_cnt(msg)); break; case CONN_MANAGER: tipc_printf(buf, "CONN_MNG:"); switch (msg_type(msg)) { case CONN_PROBE: tipc_printf(buf, "PROBE:"); break; case CONN_PROBE_REPLY: tipc_printf(buf, "PROBE_REPLY:"); break; case CONN_ACK: tipc_printf(buf, "CONN_ACK:"); tipc_printf(buf, "ACK(%u):", msg_msgcnt(msg)); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg)); } if (msg_reroute_cnt(msg)) tipc_printf(buf, "REROUTED(%u):", msg_reroute_cnt(msg)); break; case LINK_PROTOCOL: switch (msg_type(msg)) { case STATE_MSG: tipc_printf(buf, "STATE:"); tipc_printf(buf, "%s:", msg_probe(msg) ? "PRB" : ""); tipc_printf(buf, "NXS(%u):", msg_next_sent(msg)); tipc_printf(buf, "GAP(%u):", msg_seq_gap(msg)); tipc_printf(buf, "LSTBC(%u):", msg_last_bcast(msg)); break; case RESET_MSG: tipc_printf(buf, "RESET:"); if (msg_size(msg) != msg_hdr_sz(msg)) tipc_printf(buf, "BEAR:%s:", msg_data(msg)); break; case ACTIVATE_MSG: tipc_printf(buf, "ACTIVATE:"); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg)); } tipc_printf(buf, "PLANE(%c):", msg_net_plane(msg)); tipc_printf(buf, "SESS(%u):", msg_session(msg)); break; case CHANGEOVER_PROTOCOL: tipc_printf(buf, "TUNL:"); switch (msg_type(msg)) { case DUPLICATE_MSG: tipc_printf(buf, "DUPL:"); break; case ORIGINAL_MSG: tipc_printf(buf, "ORIG:"); tipc_printf(buf, "EXP(%u)", msg_msgcnt(msg)); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x", msg_type(msg)); } break; case LINK_CONFIG: tipc_printf(buf, "CFG:"); switch (msg_type(msg)) { case DSC_REQ_MSG: tipc_printf(buf, "DSC_REQ:"); break; case DSC_RESP_MSG: tipc_printf(buf, "DSC_RESP:"); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x:", msg_type(msg)); break; } break; default: tipc_printf(buf, "UNKNOWN USER:"******"NO_NAME:"); break; case TIPC_ERR_NO_PORT: tipc_printf(buf, "NO_PORT:"); break; case TIPC_ERR_NO_NODE: tipc_printf(buf, "NO_PROC:"); break; case TIPC_ERR_OVERLOAD: tipc_printf(buf, "OVERLOAD:"); break; case TIPC_CONN_SHUTDOWN: tipc_printf(buf, "SHUTDOWN:"); break; default: tipc_printf(buf, "UNKNOWN ERROR(%x):", msg_errcode(msg)); } default: break; } tipc_printf(buf, "HZ(%u):", msg_hdr_sz(msg
void tipc_msg_print(struct print_buf *buf, struct tipc_msg *msg, const char *str) { u32 usr = msg_user(msg); tipc_printf(buf, str); switch (usr) { case MSG_BUNDLER: tipc_printf(buf, "BNDL::"); tipc_printf(buf, "MSGS(%u):", msg_msgcnt(msg)); break; case BCAST_PROTOCOL: tipc_printf(buf, "BCASTP::"); break; case MSG_FRAGMENTER: tipc_printf(buf, "FRAGM::"); switch (msg_type(msg)) { case FIRST_FRAGMENT: tipc_printf(buf, "FIRST:"); break; case FRAGMENT: tipc_printf(buf, "BODY:"); break; case LAST_FRAGMENT: tipc_printf(buf, "LAST:"); break; default: tipc_printf(buf, "UNKNOWN:%x",msg_type(msg)); } tipc_printf(buf, "NO(%u/%u):",msg_long_msgno(msg), msg_fragm_no(msg)); break; case TIPC_LOW_IMPORTANCE: case TIPC_MEDIUM_IMPORTANCE: case TIPC_HIGH_IMPORTANCE: case TIPC_CRITICAL_IMPORTANCE: tipc_printf(buf, "DAT%u:", msg_user(msg)); if (msg_short(msg)) { tipc_printf(buf, "CON:"); break; } switch (msg_type(msg)) { case TIPC_CONN_MSG: tipc_printf(buf, "CON:"); break; case TIPC_MCAST_MSG: tipc_printf(buf, "MCST:"); break; case TIPC_NAMED_MSG: tipc_printf(buf, "NAM:"); break; case TIPC_DIRECT_MSG: tipc_printf(buf, "DIR:"); break; default: tipc_printf(buf, "UNKNOWN TYPE %u",msg_type(msg)); } if (msg_routed(msg) && !msg_non_seq(msg)) tipc_printf(buf, "ROUT:"); if (msg_reroute_cnt(msg)) tipc_printf(buf, "REROUTED(%u):", msg_reroute_cnt(msg)); break; case NAME_DISTRIBUTOR: tipc_printf(buf, "NMD::"); switch (msg_type(msg)) { case PUBLICATION: tipc_printf(buf, "PUBL(%u):", (msg_size(msg) - msg_hdr_sz(msg)) / 20); /* Items */ break; case WITHDRAWAL: tipc_printf(buf, "WDRW:"); break; default: tipc_printf(buf, "UNKNOWN:%x",msg_type(msg)); } if (msg_routed(msg)) tipc_printf(buf, "ROUT:"); if (msg_reroute_cnt(msg)) tipc_printf(buf, "REROUTED(%u):", msg_reroute_cnt(msg)); break; case CONN_MANAGER: tipc_printf(buf, "CONN_MNG:"); switch (msg_type(msg)) { case CONN_PROBE: tipc_printf(buf, "PROBE:"); break; case CONN_PROBE_REPLY: tipc_printf(buf, "PROBE_REPLY:"); break; case CONN_ACK: tipc_printf(buf, "CONN_ACK:"); tipc_printf(buf, "ACK(%u):",msg_msgcnt(msg)); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); } if (msg_routed(msg)) tipc_printf(buf, "ROUT:"); if (msg_reroute_cnt(msg)) tipc_printf(buf, "REROUTED(%u):",msg_reroute_cnt(msg)); break; case LINK_PROTOCOL: tipc_printf(buf, "PROT:TIM(%u):",msg_timestamp(msg)); switch (msg_type(msg)) { case STATE_MSG: tipc_printf(buf, "STATE:"); tipc_printf(buf, "%s:",msg_probe(msg) ? "PRB" :""); tipc_printf(buf, "NXS(%u):",msg_next_sent(msg)); tipc_printf(buf, "GAP(%u):",msg_seq_gap(msg)); tipc_printf(buf, "LSTBC(%u):",msg_last_bcast(msg)); break; case RESET_MSG: tipc_printf(buf, "RESET:"); if (msg_size(msg) != msg_hdr_sz(msg)) tipc_printf(buf, "BEAR:%s:",msg_data(msg)); break; case ACTIVATE_MSG: tipc_printf(buf, "ACTIVATE:"); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); } tipc_printf(buf, "PLANE(%c):",msg_net_plane(msg)); tipc_printf(buf, "SESS(%u):",msg_session(msg)); break; case CHANGEOVER_PROTOCOL: tipc_printf(buf, "TUNL:"); switch (msg_type(msg)) { case DUPLICATE_MSG: tipc_printf(buf, "DUPL:"); break; case ORIGINAL_MSG: tipc_printf(buf, "ORIG:"); tipc_printf(buf, "EXP(%u)",msg_msgcnt(msg)); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); } break; case ROUTE_DISTRIBUTOR: tipc_printf(buf, "ROUTING_MNG:"); switch (msg_type(msg)) { case EXT_ROUTING_TABLE: tipc_printf(buf, "EXT_TBL:"); tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); break; case LOCAL_ROUTING_TABLE: tipc_printf(buf, "LOCAL_TBL:"); tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); break; case SLAVE_ROUTING_TABLE: tipc_printf(buf, "DP_TBL:"); tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); break; case ROUTE_ADDITION: tipc_printf(buf, "ADD:"); tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); break; case ROUTE_REMOVAL: tipc_printf(buf, "REMOVE:"); tipc_printf(buf, "TO:%x:",msg_remote_node(msg)); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg)); } break; case LINK_CONFIG: tipc_printf(buf, "CFG:"); switch (msg_type(msg)) { case DSC_REQ_MSG: tipc_printf(buf, "DSC_REQ:"); break; case DSC_RESP_MSG: tipc_printf(buf, "DSC_RESP:"); break; default: tipc_printf(buf, "UNKNOWN TYPE:%x:",msg_type(msg)); break; } break; default: tipc_printf(buf, "UNKNOWN USER:"******"NO_NAME:"); break; case TIPC_ERR_NO_PORT: tipc_printf(buf, "NO_PORT:"); break; case TIPC_ERR_NO_NODE: tipc_printf(buf, "NO_PROC:"); break; case TIPC_ERR_OVERLOAD: tipc_printf(buf, "OVERLOAD:"); break; case TIPC_CONN_SHUTDOWN: tipc_printf(buf, "SHUTDOWN:"); break; default: tipc_printf(buf, "UNKNOWN ERROR(%x):", msg_errcode(msg)); } default:{} } tipc_printf(buf, "HZ(%u):", msg_hdr_sz(msg)); tipc_printf(buf, "SZ(%u):", msg_size(msg)); tipc_printf(buf, "SQNO(%u):", msg_seqno(msg)); if (msg_non_seq(msg)) tipc_printf(buf, "NOSEQ:"); else { tipc_printf(buf, "ACK(%u):", msg_ack(msg)); } tipc_printf(buf, "BACK(%u):", msg_bcast_ack(msg)); tipc_printf(buf, "PRND(%x)", msg_prevnode(msg)); if (msg_isdata(msg)) { if (msg_named(msg)) { tipc_printf(buf, "NTYP(%u):", msg_nametype(msg)); tipc_printf(buf, "NINST(%u)", msg_nameinst(msg)); } } if ((usr != LINK_PROTOCOL) && (usr != LINK_CONFIG) && (usr != MSG_BUNDLER)) { if (!msg_short(msg)) { tipc_printf(buf, ":ORIG(%x:%u):", msg_orignode(msg), msg_origport(msg)); tipc_printf(buf, ":DEST(%x:%u):", msg_destnode(msg), msg_destport(msg)); } else { tipc_printf(buf, ":OPRT(%u):", msg_origport(msg)); tipc_printf(buf, ":DPRT(%u):", msg_destport(msg)); } if (msg_routed(msg) && !msg_non_seq(msg)) tipc_printf(buf, ":TSEQN(%u)", msg_transp_seqno(msg)); } if (msg_user(msg) == NAME_DISTRIBUTOR) { tipc_printf(buf, ":ONOD(%x):", msg_orignode(msg)); tipc_printf(buf, ":DNOD(%x):", msg_destnode(msg)); if (msg_routed(msg)) { tipc_printf(buf, ":CSEQN(%u)", msg_transp_seqno(msg)); } } if (msg_user(msg) == LINK_CONFIG) { u32* raw = (u32*)msg; struct tipc_media_addr* orig = (struct tipc_media_addr*)&raw[5]; tipc_printf(buf, ":REQL(%u):", msg_req_links(msg)); tipc_printf(buf, ":DDOM(%x):", msg_dest_domain(msg)); tipc_printf(buf, ":NETID(%u):", msg_bc_netid(msg)); tipc_media_addr_printf(buf, orig); } if (msg_user(msg) == BCAST_PROTOCOL) { tipc_printf(buf, "BCNACK:AFTER(%u):", msg_bcgap_after(msg)); tipc_printf(buf, "TO(%u):", msg_bcgap_to(msg)); } tipc_printf(buf, "\n"); if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg))) { tipc_msg_print(buf,msg_get_wrapped(msg)," /"); } if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) { tipc_msg_print(buf,msg_get_wrapped(msg)," /"); } }
// Default constructor EditorScreen::EditorScreen() : plf(new EditorLevel()), level_pathname(), panel(0), viewport(0), object_selector(0), minimap(), object_properties(), action_properties(), level_properties(), file_load_dialog(), file_save_dialog(), m_level_new_msgbox(), show_help(false) { // Create the viewport for the images and data viewport = new Viewport(this, Rect(0, 38, size.width - 244, size.height)); gui_manager->add(viewport); // Create the panel for the buttons panel = new Panel(this); //rect(Vector2i(Display::get_width() - 244 + 2, 38 + 3 + 62), // Size(240, Display::get_height() - (600 - 495))), minimap = new Minimap(this, Rect()); gui_manager->add(minimap); object_properties = gui_manager->create<ObjectProperties>(this, Rect(Vector2i(), Size(200, 150))); action_properties = gui_manager->create<ActionProperties>(this, Rect()); action_properties->hide(); level_properties = gui_manager->create<LevelProperties>(this, Rect()); level_properties->hide(); level_properties->set_level(plf.get()); action_properties->set_level(plf.get()); object_selector = gui_manager->create<ObjectSelector>(this, Rect()); file_load_dialog = gui_manager->create<FileDialog>(this, Rect(Vector2i(50, 50), Size(size.width - 100, size.height - 100)), FileDialog::LOAD); file_load_dialog->hide(); file_save_dialog = gui_manager->create<FileDialog>(this, Rect(Vector2i(50, 50), Size(Display::get_width() - 100, Display::get_height() - 100)), FileDialog::SAVE); file_save_dialog->hide(); { Size msg_size(600, 160); m_level_new_msgbox = gui_manager->create<MessageBox>(Rect(Vector2i((Display::get_width() - msg_size.width)/2, (Display::get_height() - msg_size.height)/2), msg_size)); m_level_new_msgbox->set_title("Create new level"); m_level_new_msgbox->set_text("Replace current level with an empty new one?"); m_level_new_msgbox->set_ok_text("Replace"); m_level_new_msgbox->on_ok.connect(std::bind(&EditorScreen::level_new_without_confirm, this)); m_level_new_msgbox->hide(); } viewport->selection_changed.connect(std::bind(&ObjectProperties::set_objects, object_properties, std::placeholders::_1)); viewport->refresh(); update_layout(); }
static int recv_stream(struct kiocb *iocb, struct socket *sock, struct msghdr *m, size_t buf_len, int flags) { struct sock *sk = sock->sk; struct tipc_port *tport = tipc_sk_port(sk); struct sk_buff *buf; struct tipc_msg *msg; unsigned int sz; int sz_to_copy, target, needed; int sz_copied = 0; char __user *crs = m->msg_iov->iov_base; unsigned char *buf_crs; u32 err; int res = 0; /* Catch invalid receive attempts */ if (m->msg_iovlen != 1) return -EOPNOTSUPP; /* Don't do multiple iovec entries yet */ if (unlikely(!buf_len)) return -EINVAL; lock_sock(sk); if (unlikely((sock->state == SS_UNCONNECTED) || (sock->state == SS_CONNECTING))) { res = -ENOTCONN; goto exit; } target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); restart: /* Look for a message in receive queue; wait if necessary */ while (skb_queue_empty(&sk->sk_receive_queue)) { if (sock->state == SS_DISCONNECTING) { res = -ENOTCONN; goto exit; } if (flags & MSG_DONTWAIT) { res = -EWOULDBLOCK; goto exit; } release_sock(sk); res = wait_event_interruptible(*sk_sleep(sk), (!skb_queue_empty(&sk->sk_receive_queue) || (sock->state == SS_DISCONNECTING))); lock_sock(sk); if (res) goto exit; } /* Look at first message in receive queue */ buf = skb_peek(&sk->sk_receive_queue); msg = buf_msg(buf); sz = msg_data_sz(msg); err = msg_errcode(msg); /* Discard an empty non-errored message & try again */ if ((!sz) && (!err)) { advance_rx_queue(sk); goto restart; } /* Optionally capture sender's address & ancillary data of first msg */ if (sz_copied == 0) { set_orig_addr(m, msg); res = anc_data_recv(m, msg, tport); if (res) goto exit; } /* Capture message data (if valid) & compute return value (always) */ if (!err) { buf_crs = (unsigned char *)(TIPC_SKB_CB(buf)->handle); sz = (unsigned char *)msg + msg_size(msg) - buf_crs; needed = (buf_len - sz_copied); sz_to_copy = (sz <= needed) ? sz : needed; if (unlikely(copy_to_user(crs, buf_crs, sz_to_copy))) { res = -EFAULT; goto exit; } sz_copied += sz_to_copy; if (sz_to_copy < sz) { if (!(flags & MSG_PEEK)) TIPC_SKB_CB(buf)->handle = buf_crs + sz_to_copy; goto exit; } crs += sz_to_copy; } else { if (sz_copied != 0) goto exit; /* can't add error msg to valid data */ if ((err == TIPC_CONN_SHUTDOWN) || m->msg_control) res = 0; else res = -ECONNRESET; } /* Consume received message (optional) */ if (likely(!(flags & MSG_PEEK))) { if (unlikely(++tport->conn_unacked >= TIPC_FLOW_CONTROL_WIN)) tipc_acknowledge(tport->ref, tport->conn_unacked); advance_rx_queue(sk); } /* Loop around if more data is required */ if ((sz_copied < buf_len) && /* didn't get all requested data */ (!skb_queue_empty(&sk->sk_receive_queue) || (sz_copied < target)) && /* and more is ready or required */ (!(flags & MSG_PEEK)) && /* and aren't just peeking at data */ (!err)) /* and haven't reached a FIN */ goto restart; exit: release_sock(sk); return sz_copied ? sz_copied : res; }
void communicate_field_data( const BulkData & mesh , const unsigned field_count , const FieldBase * fields[] , CommAll & sparse ) { const std::vector<Entity*> & entity_comm = mesh.entity_comm(); const unsigned parallel_size = mesh.parallel_size(); // Sizing for send and receive const unsigned zero = 0 ; std::vector<unsigned> msg_size( parallel_size , zero ); size_t j = 0; for ( j = 0 ; j < field_count ; ++j ) { const FieldBase & f = * fields[j] ; for ( std::vector<Entity*>::const_iterator i = entity_comm.begin() ; i != entity_comm.end() ; ++i ) { Entity & e = **i ; const unsigned size = field_data_size( f , e ); if ( size ) { for ( PairIterEntityComm ec = e.comm() ; ! ec.empty() && ec->ghost_id == 0 ; ++ec ) { msg_size[ ec->proc ] += size ; } } } } // Allocate send and receive buffers: { const unsigned * const s_size = & msg_size[0] ; sparse.allocate_buffers( mesh.parallel(), parallel_size / 4 , s_size, s_size); } // Pack for send: for ( j = 0 ; j < field_count ; ++j ) { const FieldBase & f = * fields[j] ; for ( std::vector<Entity*>::const_iterator i = entity_comm.begin() ; i != entity_comm.end() ; ++i ) { Entity & e = **i ; const unsigned size = field_data_size( f , e ); if ( size ) { unsigned char * ptr = reinterpret_cast<unsigned char *>(field_data( f , e )); for ( PairIterEntityComm ec = e.comm() ; ! ec.empty() && ec->ghost_id == 0 ; ++ec ) { CommBuffer & b = sparse.send_buffer( ec->proc ); b.pack<unsigned char>( ptr , size ); } } } } // Communicate: sparse.communicate(); }
// Lua: bool = mqtt:subscribe(topic, qos, function()) static int mqtt_socket_subscribe( lua_State* L ) { NODE_DBG("enter mqtt_socket_subscribe.\n"); uint8_t stack = 1, qos = 0; uint16_t msg_id = 0; const char *topic; size_t il; lmqtt_userdata *mud; mud = (lmqtt_userdata *) luaL_checkudata( L, stack, "mqtt.socket" ); luaL_argcheck( L, mud, stack, "mqtt.socket expected" ); stack++; if(mud==NULL){ NODE_DBG("userdata is nil.\n"); lua_pushboolean(L, 0); return 1; } if(mud->pesp_conn == NULL){ NODE_DBG("mud->pesp_conn is NULL.\n"); lua_pushboolean(L, 0); return 1; } if(!mud->connected){ luaL_error( L, "not connected" ); lua_pushboolean(L, 0); return 1; } uint8_t temp_buffer[MQTT_BUF_SIZE]; mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE); mqtt_message_t *temp_msg = NULL; if( lua_istable( L, stack ) ) { NODE_DBG("subscribe table\n"); lua_pushnil( L ); /* first key */ uint8_t temp_buf[MQTT_BUF_SIZE]; uint32_t temp_pos = 0; while( lua_next( L, stack ) != 0 ) { topic = luaL_checkstring( L, -2 ); qos = luaL_checkinteger( L, -1 ); temp_msg = mqtt_msg_subscribe( &mud->mqtt_state.mqtt_connection, topic, qos, &msg_id ); NODE_DBG("topic: %s - qos: %d, length: %d\n", topic, qos, temp_msg->length); if (temp_pos + temp_msg->length > MQTT_BUF_SIZE){ lua_pop(L, 1); break; // too long message for the outbuffer. } c_memcpy( temp_buf + temp_pos, temp_msg->data, temp_msg->length ); temp_pos += temp_msg->length; lua_pop( L, 1 ); } if (temp_pos == 0){ luaL_error( L, "invalid data" ); lua_pushboolean(L, 0); return 1; } c_memcpy( temp_buffer, temp_buf, temp_pos ); temp_msg->data = temp_buffer; temp_msg->length = temp_pos; stack++; } else { NODE_DBG("subscribe string\n"); topic = luaL_checklstring( L, stack, &il ); stack++; if( topic == NULL ){ luaL_error( L, "need topic name" ); lua_pushboolean(L, 0); return 1; } qos = luaL_checkinteger( L, stack ); temp_msg = mqtt_msg_subscribe( &mud->mqtt_state.mqtt_connection, topic, qos, &msg_id ); stack++; } if( lua_type( L, stack ) == LUA_TFUNCTION || lua_type( L, stack ) == LUA_TLIGHTFUNCTION ) { // TODO: this will overwrite the previous one. lua_pushvalue( L, stack ); // copy argument (func) to the top of stack if( mud->cb_suback_ref != LUA_NOREF ) luaL_unref( L, LUA_REGISTRYINDEX, mud->cb_suback_ref ); mud->cb_suback_ref = luaL_ref( L, LUA_REGISTRYINDEX ); } msg_queue_t *node = msg_enqueue( &(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_SUBSCRIBE, (int)mqtt_get_qos(temp_msg->data) ); NODE_DBG("topic: %s - id: %d - qos: %d, length: %d\n", topic, node->msg_id, node->publish_qos, node->msg.length); if(node && (1==msg_size(&(mud->mqtt_state.pending_msg_q))) && mud->event_timeout == 0){ mud->event_timeout = MQTT_SEND_TIMEOUT; NODE_DBG("Sent: %d\n", node->msg.length); if( mud->secure ) espconn_secure_sent( mud->pesp_conn, node->msg.data, node->msg.length ); else espconn_sent( mud->pesp_conn, node->msg.data, node->msg.length ); mud->keep_alive_tick = 0; } if(!node){ lua_pushboolean(L, 0); } else { lua_pushboolean(L, 1); // enqueued succeed. } NODE_DBG("subscribe, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); NODE_DBG("leave mqtt_socket_subscribe.\n"); return 1; }
// Lua: bool = mqtt:publish( topic, payload, qos, retain, function() ) static int mqtt_socket_publish( lua_State* L ) { NODE_DBG("enter mqtt_socket_publish.\n"); struct espconn *pesp_conn = NULL; lmqtt_userdata *mud; size_t l; uint8_t stack = 1; uint16_t msg_id = 0; mud = (lmqtt_userdata *)luaL_checkudata(L, stack, "mqtt.socket"); luaL_argcheck(L, mud, stack, "mqtt.socket expected"); stack++; if(mud==NULL){ NODE_DBG("userdata is nil.\n"); lua_pushboolean(L, 0); return 1; } if(mud->pesp_conn == NULL){ NODE_DBG("mud->pesp_conn is NULL.\n"); lua_pushboolean(L, 0); return 1; } if(!mud->connected){ luaL_error( L, "not connected" ); lua_pushboolean(L, 0); return 1; } const char *topic = luaL_checklstring( L, stack, &l ); stack ++; if (topic == NULL){ luaL_error( L, "need topic" ); lua_pushboolean(L, 0); return 1; } const char *payload = luaL_checklstring( L, stack, &l ); stack ++; uint8_t qos = luaL_checkinteger( L, stack); stack ++; uint8_t retain = luaL_checkinteger( L, stack); stack ++; uint8_t temp_buffer[MQTT_BUF_SIZE]; mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE); mqtt_message_t *temp_msg = mqtt_msg_publish(&mud->mqtt_state.mqtt_connection, topic, payload, l, qos, retain, &msg_id); if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION){ lua_pushvalue(L, stack); // copy argument (func) to the top of stack if(mud->cb_puback_ref != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref); mud->cb_puback_ref = luaL_ref(L, LUA_REGISTRYINDEX); } msg_queue_t *node = msg_enqueue(&(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_PUBLISH, (int)qos ); if(node && (1==msg_size(&(mud->mqtt_state.pending_msg_q))) && mud->event_timeout == 0){ mud->event_timeout = MQTT_SEND_TIMEOUT; NODE_DBG("Sent: %d\n", node->msg.length); if( mud->secure ) espconn_secure_sent( mud->pesp_conn, node->msg.data, node->msg.length ); else espconn_sent( mud->pesp_conn, node->msg.data, node->msg.length ); mud->keep_alive_tick = 0; } if(!node){ lua_pushboolean(L, 0); } else { lua_pushboolean(L, 1); // enqueued succeed. } NODE_DBG("publish, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); NODE_DBG("leave mqtt_socket_publish.\n"); return 1; }
static void mqtt_socket_received(void *arg, char *pdata, unsigned short len) { NODE_DBG("enter mqtt_socket_received.\n"); uint8_t msg_type; uint8_t msg_qos; uint16_t msg_id; msg_queue_t *node = NULL; int length = (int)len; // uint8_t in_buffer[MQTT_BUF_SIZE]; uint8_t *in_buffer = (uint8_t *)pdata; struct espconn *pesp_conn = arg; if(pesp_conn == NULL) return; lmqtt_userdata *mud = (lmqtt_userdata *)pesp_conn->reverse; if(mud == NULL) return; READPACKET: if(length > MQTT_BUF_SIZE || length <= 0) return; // c_memcpy(in_buffer, pdata, length); uint8_t temp_buffer[MQTT_BUF_SIZE]; mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE); mqtt_message_t *temp_msg = NULL; switch(mud->connState){ case MQTT_CONNECT_SENDING: case MQTT_CONNECT_SENT: if(mqtt_get_type(in_buffer) != MQTT_MSG_TYPE_CONNACK){ NODE_DBG("MQTT: Invalid packet\r\n"); mud->connState = MQTT_INIT; if(mud->secure) espconn_secure_disconnect(pesp_conn); else espconn_disconnect(pesp_conn); } else { mud->connState = MQTT_DATA; NODE_DBG("MQTT: Connected\r\n"); if(mud->cb_connect_ref == LUA_NOREF) break; if(mud->self_ref == LUA_NOREF) break; if(mud->L == NULL) break; lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->cb_connect_ref); lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->self_ref); // pass the userdata(client) to callback func in lua lua_call(mud->L, 1, 0); break; } break; case MQTT_DATA: mud->mqtt_state.message_length_read = length; mud->mqtt_state.message_length = mqtt_get_total_length(in_buffer, mud->mqtt_state.message_length_read); msg_type = mqtt_get_type(in_buffer); msg_qos = mqtt_get_qos(in_buffer); msg_id = mqtt_get_id(in_buffer, mud->mqtt_state.message_length); msg_queue_t *pending_msg = msg_peek(&(mud->mqtt_state.pending_msg_q)); NODE_DBG("MQTT_DATA: type: %d, qos: %d, msg_id: %d, pending_id: %d\r\n", msg_type, msg_qos, msg_id, (pending_msg)?pending_msg->msg_id:0); switch(msg_type) { case MQTT_MSG_TYPE_SUBACK: if(pending_msg && pending_msg->msg_type == MQTT_MSG_TYPE_SUBSCRIBE && pending_msg->msg_id == msg_id){ NODE_DBG("MQTT: Subscribe successful\r\n"); msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); if (mud->cb_suback_ref == LUA_NOREF) break; if (mud->self_ref == LUA_NOREF) break; if(mud->L == NULL) break; lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->cb_suback_ref); lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->self_ref); lua_call(mud->L, 1, 0); } break; case MQTT_MSG_TYPE_UNSUBACK: if(pending_msg && pending_msg->msg_type == MQTT_MSG_TYPE_UNSUBSCRIBE && pending_msg->msg_id == msg_id){ NODE_DBG("MQTT: UnSubscribe successful\r\n"); msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); } break; case MQTT_MSG_TYPE_PUBLISH: if(msg_qos == 1){ temp_msg = mqtt_msg_puback(&mud->mqtt_state.mqtt_connection, msg_id); node = msg_enqueue(&(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_PUBACK, (int)mqtt_get_qos(temp_msg->data) ); } else if(msg_qos == 2){ temp_msg = mqtt_msg_pubrec(&mud->mqtt_state.mqtt_connection, msg_id); node = msg_enqueue(&(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_PUBREC, (int)mqtt_get_qos(temp_msg->data) ); } if(msg_qos == 1 || msg_qos == 2){ NODE_DBG("MQTT: Queue response QoS: %d\r\n", msg_qos); } deliver_publish(mud, in_buffer, mud->mqtt_state.message_length); break; case MQTT_MSG_TYPE_PUBACK: if(pending_msg && pending_msg->msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg->msg_id == msg_id){ NODE_DBG("MQTT: Publish with QoS = 1 successful\r\n"); msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); if(mud->cb_puback_ref == LUA_NOREF) break; if(mud->self_ref == LUA_NOREF) break; if(mud->L == NULL) break; lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->cb_puback_ref); lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->self_ref); // pass the userdata to callback func in lua lua_call(mud->L, 1, 0); } break; case MQTT_MSG_TYPE_PUBREC: if(pending_msg && pending_msg->msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg->msg_id == msg_id){ NODE_DBG("MQTT: Publish with QoS = 2 Received PUBREC\r\n"); // Note: actrually, should not destroy the msg until PUBCOMP is received. msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); temp_msg = mqtt_msg_pubrel(&mud->mqtt_state.mqtt_connection, msg_id); node = msg_enqueue(&(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_PUBREL, (int)mqtt_get_qos(temp_msg->data) ); NODE_DBG("MQTT: Response PUBREL\r\n"); } break; case MQTT_MSG_TYPE_PUBREL: if(pending_msg && pending_msg->msg_type == MQTT_MSG_TYPE_PUBREC && pending_msg->msg_id == msg_id){ msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); temp_msg = mqtt_msg_pubcomp(&mud->mqtt_state.mqtt_connection, msg_id); node = msg_enqueue(&(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_PUBCOMP, (int)mqtt_get_qos(temp_msg->data) ); NODE_DBG("MQTT: Response PUBCOMP\r\n"); } break; case MQTT_MSG_TYPE_PUBCOMP: if(pending_msg && pending_msg->msg_type == MQTT_MSG_TYPE_PUBREL && pending_msg->msg_id == msg_id){ NODE_DBG("MQTT: Publish with QoS = 2 successful\r\n"); msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); if(mud->cb_puback_ref == LUA_NOREF) break; if(mud->self_ref == LUA_NOREF) break; if(mud->L == NULL) break; lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->cb_puback_ref); lua_rawgeti(mud->L, LUA_REGISTRYINDEX, mud->self_ref); // pass the userdata to callback func in lua lua_call(mud->L, 1, 0); } break; case MQTT_MSG_TYPE_PINGREQ: temp_msg = mqtt_msg_pingresp(&mud->mqtt_state.mqtt_connection); node = msg_enqueue(&(mud->mqtt_state.pending_msg_q), temp_msg, msg_id, MQTT_MSG_TYPE_PINGRESP, (int)mqtt_get_qos(temp_msg->data) ); NODE_DBG("MQTT: Response PINGRESP\r\n"); break; case MQTT_MSG_TYPE_PINGRESP: // Ignore NODE_DBG("MQTT: PINGRESP received\r\n"); break; } // NOTE: this is done down here and not in the switch case above // because the PSOCK_READBUF_LEN() won't work inside a switch // statement due to the way protothreads resume. if(msg_type == MQTT_MSG_TYPE_PUBLISH) { length = mud->mqtt_state.message_length_read; if(mud->mqtt_state.message_length < mud->mqtt_state.message_length_read) { length -= mud->mqtt_state.message_length; in_buffer += mud->mqtt_state.message_length; NODE_DBG("Get another published message\r\n"); goto READPACKET; } } break; } if(node && (1==msg_size(&(mud->mqtt_state.pending_msg_q))) && mud->event_timeout == 0){ mud->event_timeout = MQTT_SEND_TIMEOUT; NODE_DBG("Sent: %d\n", node->msg.length); if( mud->secure ) espconn_secure_sent( pesp_conn, node->msg.data, node->msg.length ); else espconn_sent( pesp_conn, node->msg.data, node->msg.length ); } mud->keep_alive_tick = 0; NODE_DBG("receive, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); NODE_DBG("leave mqtt_socket_received.\n"); return; }
void mqtt_socket_timer(void *arg) { NODE_DBG("enter mqtt_socket_timer.\n"); lmqtt_userdata *mud = (lmqtt_userdata*) arg; if(mud == NULL) return; if(mud->pesp_conn == NULL){ NODE_DBG("mud->pesp_conn is NULL.\n"); os_timer_disarm(&mud->mqttTimer); return; } NODE_DBG("timer, queue size: %d\n", msg_size(&(mud->mqtt_state.pending_msg_q))); if(mud->event_timeout > 0){ NODE_DBG("event_timeout: %d.\n", mud->event_timeout); mud->event_timeout --; if(mud->event_timeout > 0){ return; } else { NODE_DBG("event timeout. \n"); if(mud->connState == MQTT_DATA) msg_destroy(msg_dequeue(&(mud->mqtt_state.pending_msg_q))); // should remove the head of the queue and re-send with DUP = 1 // Not implemented yet. } } if(mud->connState == MQTT_INIT){ // socket connect time out. NODE_DBG("Can not connect to broker.\n"); // Never goes here. } else if(mud->connState == MQTT_CONNECT_SENDING){ // MQTT_CONNECT send time out. NODE_DBG("sSend MQTT_CONNECT failed.\n"); mud->connState = MQTT_INIT; if(mud->secure) espconn_secure_disconnect(mud->pesp_conn); else espconn_disconnect(mud->pesp_conn); mud->keep_alive_tick = 0; // not need count anymore } else if(mud->connState == MQTT_CONNECT_SENT){ // wait for CONACK time out. NODE_DBG("MQTT_CONNECT failed.\n"); } else if(mud->connState == MQTT_DATA){ msg_queue_t *pending_msg = msg_peek(&(mud->mqtt_state.pending_msg_q)); if(pending_msg){ mud->event_timeout = MQTT_SEND_TIMEOUT; if(mud->secure) espconn_secure_sent(mud->pesp_conn, pending_msg->msg.data, pending_msg->msg.length); else espconn_sent(mud->pesp_conn, pending_msg->msg.data, pending_msg->msg.length); mud->keep_alive_tick = 0; NODE_DBG("id: %d - qos: %d, length: %d\n", pending_msg->msg_id, pending_msg->publish_qos, pending_msg->msg.length); } else { // no queued event. mud->keep_alive_tick ++; if(mud->keep_alive_tick > mud->mqtt_state.connect_info->keepalive){ mud->event_timeout = MQTT_SEND_TIMEOUT; uint8_t temp_buffer[MQTT_BUF_SIZE]; mqtt_msg_init(&mud->mqtt_state.mqtt_connection, temp_buffer, MQTT_BUF_SIZE); NODE_DBG("\r\nMQTT: Send keepalive packet\r\n"); mqtt_message_t* temp_msg = mqtt_msg_pingreq(&mud->mqtt_state.mqtt_connection); msg_queue_t *node = msg_enqueue( &(mud->mqtt_state.pending_msg_q), temp_msg, 0, MQTT_MSG_TYPE_PINGREQ, (int)mqtt_get_qos(temp_msg->data) ); // only one message in queue, send immediately. if(mud->secure) espconn_secure_sent(mud->pesp_conn, temp_msg->data, temp_msg->length); else espconn_sent(mud->pesp_conn, temp_msg->data, temp_msg->length); mud->keep_alive_tick = 0; } } } NODE_DBG("leave mqtt_socket_timer.\n"); }
void tipc_cltr_recv_routing_table(struct sk_buff *buf) { struct tipc_msg *msg = buf_msg(buf); struct cluster *c_ptr; struct tipc_node *n_ptr; unchar *node_table; u32 table_size; u32 router; u32 rem_node = msg_remote_node(msg); u32 z_num; u32 c_num; u32 n_num; c_ptr = tipc_cltr_find(rem_node); if (!c_ptr) { c_ptr = tipc_cltr_create(rem_node); if (!c_ptr) { buf_discard(buf); return; } } node_table = buf->data + msg_hdr_sz(msg); table_size = msg_size(msg) - msg_hdr_sz(msg); router = msg_prevnode(msg); z_num = tipc_zone(rem_node); c_num = tipc_cluster(rem_node); switch (msg_type(msg)) { case LOCAL_ROUTING_TABLE: assert(is_slave(tipc_own_addr)); case EXT_ROUTING_TABLE: for (n_num = 1; n_num < table_size; n_num++) { if (node_table[n_num]) { u32 addr = tipc_addr(z_num, c_num, n_num); n_ptr = c_ptr->nodes[n_num]; if (!n_ptr) { n_ptr = tipc_node_create(addr); } if (n_ptr) tipc_node_add_router(n_ptr, router); } } break; case SLAVE_ROUTING_TABLE: assert(!is_slave(tipc_own_addr)); assert(in_own_cluster(c_ptr->addr)); for (n_num = 1; n_num < table_size; n_num++) { if (node_table[n_num]) { u32 slave_num = n_num + LOWEST_SLAVE; u32 addr = tipc_addr(z_num, c_num, slave_num); n_ptr = c_ptr->nodes[slave_num]; if (!n_ptr) { n_ptr = tipc_node_create(addr); } if (n_ptr) tipc_node_add_router(n_ptr, router); } } break; case ROUTE_ADDITION: if (!is_slave(tipc_own_addr)) { assert(!in_own_cluster(c_ptr->addr) || is_slave(rem_node)); } else { assert(in_own_cluster(c_ptr->addr) && !is_slave(rem_node)); } n_ptr = c_ptr->nodes[tipc_node(rem_node)]; if (!n_ptr) n_ptr = tipc_node_create(rem_node); if (n_ptr) tipc_node_add_router(n_ptr, router); break; case ROUTE_REMOVAL: if (!is_slave(tipc_own_addr)) { assert(!in_own_cluster(c_ptr->addr) || is_slave(rem_node)); } else { assert(in_own_cluster(c_ptr->addr) && !is_slave(rem_node)); } n_ptr = c_ptr->nodes[tipc_node(rem_node)]; if (n_ptr) tipc_node_remove_router(n_ptr, router); break; default: assert(!"Illegal routing manager message received\n"); } buf_discard(buf); }