| 331 | } |
| 332 | |
| 333 | void send_sync_repl(int sender, void *param) |
| 334 | { |
| 335 | bin_packet_t sync_end_pkt, *pkt, *next_pkt; |
| 336 | str bin_buffer; |
| 337 | struct local_cap *cap; |
| 338 | int rc, cluster_id, pkt_no = 0; |
| 339 | struct reply_rpc_params *p = (struct reply_rpc_params *)param; |
| 340 | |
| 341 | for (cap = p->cluster->capabilities; cap; cap = cap->next) |
| 342 | if (!str_strcmp(&p->cap_name, &cap->reg.name)) |
| 343 | break; |
| 344 | if (!cap) { |
| 345 | LM_ERR("Sync request for unknown capability: %.*s\n", |
| 346 | p->cap_name.len, p->cap_name.s); |
| 347 | goto out_free; |
| 348 | } |
| 349 | |
| 350 | no_sync_chunks_sent = 0; |
| 351 | |
| 352 | cap->reg.event_cb(SYNC_REQ_RCV, p->node_id); |
| 353 | |
| 354 | lock_start_read(cl_list_lock); |
| 355 | |
| 356 | if (sync_packets) { |
| 357 | bin_get_buffer(sync_packet_last, &bin_buffer); |
| 358 | *sync_last_chunk_sz = bin_buffer.len - sync_prev_buf_len; |
| 359 | |
| 360 | /* send and free the lastly built packet */ |
| 361 | msg_add_trailer(sync_packet_last, p->cluster->cluster_id, p->node_id); |
| 362 | |
| 363 | for (pkt = sync_packets; pkt; pkt = next_pkt) { |
| 364 | next_pkt = pkt->next; |
| 365 | |
| 366 | if ((rc = clusterer_send_msg(pkt, p->cluster->cluster_id, |
| 367 | p->node_id, 0, 1))<0) |
| 368 | LM_ERR("Failed to send sync packet, rc=%d\n", rc); |
| 369 | |
| 370 | bin_free_packet(pkt); |
| 371 | free(pkt); |
| 372 | } |
| 373 | |
| 374 | sync_packets = NULL; |
| 375 | pkt_no = sync_packets_cnt; |
| 376 | sync_packets_cnt = 0; |
| 377 | sync_packet_last = NULL; |
| 378 | sync_last_chunk_sz = NULL; |
| 379 | } |
| 380 | |
| 381 | /* send indication that all sync packets were sent */ |
| 382 | if (bin_init(&sync_end_pkt,&cl_extra_cap,CLUSTERER_SYNC_END,BIN_SYNC_VERSION,0)<0) { |
| 383 | LM_ERR("Failed to init bin packet\n"); |
| 384 | lock_stop_read(cl_list_lock); |
| 385 | goto out_free; |
| 386 | } |
| 387 | bin_push_str(&sync_end_pkt, &p->cap_name); |
| 388 | bin_push_int(&sync_end_pkt, no_sync_chunks_sent); |
| 389 | msg_add_trailer(&sync_end_pkt, p->cluster->cluster_id, p->node_id); |
| 390 |
nothing calls this directly
no test coverage detected