MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterSendModule

Function clusterSendModule

app/redis-6.2.6/src/cluster.c:2778–2810  ·  view source on GitHub ↗

Send a MODULE message. * * If link is NULL, then the message is broadcasted to the whole cluster. */

Source from the content-addressed store, hash-verified

2776 *
2777 * If link is NULL, then the message is broadcasted to the whole cluster. */
2778void clusterSendModule(clusterLink *link, uint64_t module_id, uint8_t type,
2779 unsigned char *payload, uint32_t len) {
2780 unsigned char *heapbuf;
2781 clusterMsg buf[1];
2782 clusterMsg *hdr = (clusterMsg*) buf;
2783 uint32_t totlen;
2784
2785 clusterBuildMessageHdr(hdr,CLUSTERMSG_TYPE_MODULE);
2786 totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
2787 totlen += sizeof(clusterMsgModule) - 3 + len;
2788
2789 hdr->data.module.msg.module_id = module_id; /* Already endian adjusted. */
2790 hdr->data.module.msg.type = type;
2791 hdr->data.module.msg.len = htonl(len);
2792 hdr->totlen = htonl(totlen);
2793
2794 /* Try to use the local buffer if possible */
2795 if (totlen < sizeof(buf)) {
2796 heapbuf = (unsigned char*)buf;
2797 } else {
2798 heapbuf = zmalloc(totlen);
2799 memcpy(heapbuf,hdr,sizeof(*hdr));
2800 hdr = (clusterMsg*) heapbuf;
2801 }
2802 memcpy(hdr->data.module.msg.bulk_data,payload,len);
2803
2804 if (link)
2805 clusterSendMessage(link,heapbuf,totlen);
2806 else
2807 clusterBroadcastMessage(heapbuf,totlen);
2808
2809 if (heapbuf != (unsigned char*)buf) zfree(heapbuf);
2810}
2811
2812/* This function gets a cluster node ID string as target, the same way the nodes
2813 * addresses are represented in the modules side, resolves the node, and sends

Callers 1

Calls 6

clusterBuildMessageHdrFunction · 0.85
zmallocFunction · 0.85
clusterSendMessageFunction · 0.85
clusterBroadcastMessageFunction · 0.85
zfreeFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected