Send a MODULE message. * * If link is NULL, then the message is broadcasted to the whole cluster. */
| 2834 | * |
| 2835 | * If link is NULL, then the message is broadcasted to the whole cluster. */ |
| 2836 | void clusterSendModule(clusterLink *link, uint64_t module_id, uint8_t type, |
| 2837 | unsigned char *payload, uint32_t len) { |
| 2838 | unsigned char *heapbuf; |
| 2839 | clusterMsg buf[1]; |
| 2840 | clusterMsg *hdr = (clusterMsg*) buf; |
| 2841 | uint32_t totlen; |
| 2842 | |
| 2843 | clusterBuildMessageHdr(hdr,CLUSTERMSG_TYPE_MODULE); |
| 2844 | totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData); |
| 2845 | totlen += sizeof(clusterMsgModule) - 3 + len; |
| 2846 | |
| 2847 | hdr->data.module.msg.module_id = module_id; /* Already endian adjusted. */ |
| 2848 | hdr->data.module.msg.type = type; |
| 2849 | hdr->data.module.msg.len = htonl(len); |
| 2850 | hdr->totlen = htonl(totlen); |
| 2851 | |
| 2852 | /* Try to use the local buffer if possible */ |
| 2853 | if (totlen < sizeof(buf)) { |
| 2854 | heapbuf = (unsigned char*)buf; |
| 2855 | } else { |
| 2856 | heapbuf = (unsigned char*)zmalloc(totlen, MALLOC_LOCAL); |
| 2857 | memcpy(heapbuf,hdr,sizeof(*hdr)); |
| 2858 | hdr = (clusterMsg*) heapbuf; |
| 2859 | } |
| 2860 | memcpy(hdr->data.module.msg.bulk_data,payload,len); |
| 2861 | |
| 2862 | if (link) |
| 2863 | clusterSendMessage(link,heapbuf,totlen); |
| 2864 | else |
| 2865 | clusterBroadcastMessage(heapbuf,totlen); |
| 2866 | |
| 2867 | if (heapbuf != (unsigned char*)buf) zfree(heapbuf); |
| 2868 | } |
| 2869 | |
| 2870 | /* This function gets a cluster node ID string as target, the same way the nodes |
| 2871 | * addresses are represented in the modules side, resolves the node, and sends |
no test coverage detected