Put stuff into the send buffer. * * It is guaranteed that this function will never have as a side effect * the link to be invalidated, so it is safe to call this function * from event handlers that will do stuff with the same link later. */
| 2445 | * the link to be invalidated, so it is safe to call this function |
| 2446 | * from event handlers that will do stuff with the same link later. */ |
| 2447 | void clusterSendMessage(clusterLink *link, unsigned char *msg, size_t msglen) { |
| 2448 | serverAssert(GlobalLocksAcquired()); |
| 2449 | if (sdslen(link->sndbuf) == 0 && msglen != 0) |
| 2450 | { |
| 2451 | aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [link] { |
| 2452 | /* The connection could be timed out before this posted function executes (thanks to TCP keepalive). |
| 2453 | * So check that the connection is still there before setting the write handler, otherwise you segfault */ |
| 2454 | if (link->conn != nullptr) |
| 2455 | connSetWriteHandlerWithBarrier(link->conn, clusterWriteHandler, 1); |
| 2456 | }); |
| 2457 | } |
| 2458 | |
| 2459 | link->sndbuf = sdscatlen(link->sndbuf, msg, msglen); |
| 2460 | |
| 2461 | /* Populate sent messages stats. */ |
| 2462 | clusterMsg *hdr = (clusterMsg*) msg; |
| 2463 | uint16_t type = ntohs(hdr->type); |
| 2464 | if (type < CLUSTERMSG_TYPE_COUNT) |
| 2465 | g_pserver->cluster->stats_bus_messages_sent[type]++; |
| 2466 | } |
| 2467 | |
| 2468 | /* Send a message to all the nodes that are part of the cluster having |
| 2469 | * a connected link. |
no test coverage detected