gboolean weather_update_text(void* ptr) { struct weather_monitor* m; if ((m = (struct weather_monitor*)ptr) != NULL) { char* output; CURLcode code = download_data(m->curl, m->request_str->str, m->res); if (code == CURLE_OK && format_output(m->res, m->icon) != -1) { output = m->res->str; } else { output = m->err; } g_mutex_lock(m->mutex); m->bar_text = g_string_assign(m->bar_text, output); g_mutex_unlock(m->mutex); return TRUE; } else { fprintf(stderr, "Weather monitor not received in update.\n"); exit(EXIT_FAILURE); } }
/* ================ client_thread_main() ================ */ void client_thread_main(zsock_t *pipe, void *user_data) { client_t *client = (client_t*)user_data; int id = client->id; UNUSED const char *file_data = client->file_data; UNUSED uint32_t file_size = client->file_size; trace_log("Client %d Ready.", id); zsock_signal(pipe, 0); char sz_id[16]; sprintf(sz_id, "%d", id); message_send_status(pipe, MSG_STATUS_ACTOR_READY); zsock_t *sock_client = zsock_new_req(client->endpoint); if ( sock_client == NULL ){ error_log("Connect broker failed. Client %d", client->id); return; } uint32_t file_count = 0; while ( true ){ char key[NAME_MAX]; client_rebuild_data_key(client, file_count, key); int retries = 0; while ( retries++ < RETRIES ) { int rc = 0; if ( client->op_code == 1 ) { rc = upload_data(sock_client, key, file_data, file_size); } else if ( client->op_code == 2 ) { rc = download_data(sock_client, key); } else if ( client->op_code == 3 ) { rc = delete_data(sock_client, key); } if ( rc == -2 ) break; if ( rc == 0 ) break; notice_log("Retry %d/%d...", retries, RETRIES); zclock_sleep(1000); } /* ---------------- Check exit loop ---------------- */ file_count++; if ( file_count % 100 == 1 || file_count + 5 >= client->total_files ){ info_log("Client %d Send message %d/%d", client->id, file_count, client->total_files); } if ( file_count >= client->total_files ) break; } message_send_status(pipe, MSG_STATUS_ACTOR_OVER); zsock_destroy(&sock_client); trace_log("Client %d Exit.", id); }