| 208 | static int no_sync_chunks_sent; |
| 209 | |
| 210 | bin_packet_t *cl_sync_chunk_start(str *capability, int cluster_id, int dst_id, |
| 211 | short data_version) |
| 212 | { |
| 213 | str bin_buffer; |
| 214 | int prev_chunk_size = 0; |
| 215 | int aloc_new_pkt = 0; |
| 216 | bin_packet_t *new_packet = NULL; |
| 217 | |
| 218 | if (sync_packet_last) { |
| 219 | bin_get_buffer(sync_packet_last, &bin_buffer); |
| 220 | prev_chunk_size = bin_buffer.len - sync_prev_buf_len; |
| 221 | /* assume this chunk will have aprox the same size as the previous one |
| 222 | * and check if there is enough space in the packet */ |
| 223 | if (bin_buffer.len + prev_chunk_size > sync_packet_size) |
| 224 | aloc_new_pkt = 1; |
| 225 | } else |
| 226 | aloc_new_pkt = 1; |
| 227 | |
| 228 | if (aloc_new_pkt) { /* next chunk will be in a new packet */ |
| 229 | if (sync_packet_last) { |
| 230 | *sync_last_chunk_sz = prev_chunk_size; |
| 231 | |
| 232 | /* properly end the previous packet (to be sent later) */ |
| 233 | msg_add_trailer(sync_packet_last, cluster_id, dst_id); |
| 234 | sync_last_chunk_sz = NULL; |
| 235 | } |
| 236 | |
| 237 | new_packet = malloc(sizeof *new_packet); |
| 238 | if (!new_packet) { |
| 239 | LM_ERR("No more pkg memory\n"); |
| 240 | return NULL; |
| 241 | } |
| 242 | new_packet->next = NULL; |
| 243 | |
| 244 | if (_bin_init(new_packet,&cl_extra_cap,CLUSTERER_SYNC,BIN_SYNC_VERSION,0,1)<0) { |
| 245 | LM_ERR("Failed to init bin packet\n"); |
| 246 | free(new_packet); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | bin_push_str(new_packet, capability); |
| 251 | bin_push_int(new_packet, data_version); |
| 252 | if (sync_packet_last) |
| 253 | sync_packet_last->next = new_packet; |
| 254 | else |
| 255 | sync_packets = new_packet; |
| 256 | sync_packet_last = new_packet; |
| 257 | sync_packets_cnt++; |
| 258 | } |
| 259 | |
| 260 | if (sync_last_chunk_sz) |
| 261 | *sync_last_chunk_sz = prev_chunk_size; |
| 262 | |
| 263 | /* reserve and remember a holder for the upcoming data chunk size */ |
| 264 | bin_get_buffer(sync_packet_last, &bin_buffer); |
| 265 | bin_push_int(sync_packet_last, 0); |
| 266 | sync_last_chunk_sz = (int *)(bin_buffer.s + bin_buffer.len); |
| 267 |
nothing calls this directly
no test coverage detected