MCPcopy Create free account
hub / github.com/antirez/ds4 / dist_worker_read_loop

Function dist_worker_read_loop

ds4_distributed.c:5758–5826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5756 if (pthread_create(&accept_tid, NULL, dist_coordinator_accept_main, &accept_ctx) != 0) {
5757 fprintf(stderr, "ds4: distributed coordinator: pthread_create failed for accept loop\n");
5758 close(listen_fd);
5759 return 1;
5760 }
5761 pthread_detach(accept_tid);
5762
5763 return dist_run_coordinator_generation(&state, gen);
5764}
5765
5766/* =========================================================================
5767 * Worker Control Loop And Result Frames
5768 * ========================================================================= */
5769
5770static int dist_worker_read_loop(ds4_dist_worker_state *state, int fd) {
5771 ds4_dist_worker_upstream upstream;
5772 dist_worker_upstream_init(&upstream, state, fd);
5773 int loop_rc = 0;
5774
5775 for (;;) {
5776 uint32_t type = 0, bytes = 0;
5777 char err[256];
5778 int rc = dist_read_frame_header(fd, &type, &bytes, err, sizeof(err));
5779 if (rc == 0) break;
5780 if (rc < 0) {
5781 fprintf(stderr, "ds4: distributed worker: protocol error: %s\n", err);
5782 loop_rc = 1;
5783 break;
5784 }
5785 if (type == DS4_DIST_MSG_ERROR) {
5786 char msg[512];
5787 uint32_t n = bytes < sizeof(msg) - 1u ? bytes : (uint32_t)sizeof(msg) - 1u;
5788 rc = dist_read_full(fd, msg, n);
5789 if (rc <= 0) {
5790 loop_rc = 1;
5791 break;
5792 }
5793 msg[n] = '\0';
5794 if (bytes > n) dist_discard_bytes(fd, bytes - n);
5795 fprintf(stderr, "ds4: distributed worker: coordinator error: %s\n", msg);
5796 loop_rc = 1;
5797 break;
5798 }
5799 if (type == DS4_DIST_MSG_WORK) {
5800 rc = dist_worker_handle_work(state, &upstream, bytes);
5801 if (rc <= 0) {
5802 loop_rc = rc == 0 ? 0 : 1;
5803 break;
5804 }
5805 continue;
5806 }
5807 if (type == DS4_DIST_MSG_SNAPSHOT_SAVE_REQ) {
5808 rc = dist_worker_handle_snapshot_save(state, &upstream, bytes);
5809 if (rc <= 0) {
5810 loop_rc = rc == 0 ? 0 : 1;
5811 break;
5812 }
5813 continue;
5814 }
5815 if (type == DS4_DIST_MSG_SNAPSHOT_LOAD_BEGIN) {

Callers 2

dist_run_workerFunction · 0.85

Calls 9

dist_read_frame_headerFunction · 0.85
dist_read_fullFunction · 0.85
dist_discard_bytesFunction · 0.85
dist_worker_handle_workFunction · 0.85
dist_send_errorFunction · 0.85

Tested by

no test coverage detected