int release_main_loop() { int returnValue = 0; SOL_DBG("Entering with state %s", RESOLVE_MAINLOOP_STATE(mainloopState)); if (mainloopState == MAINLOOP_RELEASED || mainloopState == MAINLOOP_RELEASING_STARTED) { return returnValue; } SOL_DBG("Stopping token handle"); returnValue = uv_prepare_stop(&uv_token_handle); if (returnValue) { return returnValue; } // hijack_main_loop() was called, but the idler has not run yet if (mainloopState == MAINLOOP_HIJACKING_STARTED) { SOL_DBG("idler has not run yet, so stopping it"); returnValue = uv_idle_stop(&uv_idle); if (!returnValue) { mainloopState = MAINLOOP_RELEASED; } } else { SOL_DBG("quitting main loop"); mainloopState = MAINLOOP_RELEASING_STARTED; sol_quit(); } return returnValue; }
static bool on_timeout_quit(void *data) { timeout_called++; sol_quit(); return true; }
static gboolean on_signal(gpointer ptr) { SOL_DBG("got signal, quit main loop..."); sol_quit(); return true; }
static bool on_stdin(void *data, int fd, uint32_t flags) { if (flags & (SOL_FD_FLAGS_ERR | SOL_FD_FLAGS_HUP)) { fprintf(stderr, "ERROR: Something wrong happened with file descriptor: %d\n", fd); goto err; } if (flags & SOL_FD_FLAGS_IN) { int err; value.used = 0; /* this will loop trying to read as much data as possible to buffer. */ err = sol_util_load_file_fd_buffer(fd, &value); if (err < 0) { fprintf(stderr, "ERROR: failed to read from stdin: %s\n", sol_util_strerrora(-err)); goto err; } if (value.used == 0) { /* no data usually means ^D on the terminal, quit the application */ puts("no data on stdin, quitting."); sol_quit(); } else { printf("Now serving %zd bytes:\n--BEGIN--\n%.*s\n--END--\n", value.used, SOL_STR_SLICE_PRINT(sol_buffer_get_slice(&value))); } } return true; err: sol_quit_with_code(EXIT_FAILURE); return false; }
static void delete_cb(void *data, const struct sol_http_progressive_response *sse) { sol_ptr_vector_remove(&responses, sse); if (should_quit && !sol_ptr_vector_get_len(&responses)) sol_quit(); }
static bool producer_make_data(void *data) { void *v; size_t size; struct sol_blob *blob; struct sol_buffer buf = SOL_BUFFER_INIT_EMPTY; static uint16_t packets_created = 0; bool keep_running = true; int r; //Stop the production until the pendind blob is sent if (pending_blob) { printf("Waiting for blob data: %.*s to be transfered.\n", SOL_STR_SLICE_PRINT(sol_str_slice_from_blob(pending_blob))); return true; } packets_created++; //Generate data if (packets_created != MAX_PACKETS) r = sol_util_uuid_gen(true, true, &buf); else { r = sol_buffer_append_slice(&buf, sol_str_slice_from_str("close")); keep_running = false; } if (r < 0) { fprintf(stderr, "Could not create the UUID - Reason: %s\n", sol_util_strerrora(-r)); goto err_exit; } v = sol_buffer_steal(&buf, &size); blob = sol_blob_new(&SOL_BLOB_TYPE_DEFAULT, NULL, v, size + 1); if (!blob) { fprintf(stderr, "Could not alloc memory for the blob\n"); goto err_exit; } //Send it if (!send_blob(blob)) goto err_exit; if (!keep_running) goto exit; return true; err_exit: sol_quit(); exit: producer_timeout = NULL; return false; }
//! [uart write completed] static void producer_data_written(void *data, struct sol_uart *uart, struct sol_blob *blob, int status) { struct sol_str_slice slice; slice = sol_str_slice_from_blob(blob); if (status < 0) { fprintf(stderr, "Could not write the UUID %.*s - Reason: %s\n", SOL_STR_SLICE_PRINT(slice), sol_util_strerrora(-status)); sol_quit(); } else { printf("Producer: UUID %.*s written\n", SOL_STR_SLICE_PRINT(slice)); if (pending_blob) { //If we have a pending blob now it's the time to try to send it! if (!send_blob(pending_blob)) { fprintf(stderr, "Could not send the pending blob!\n"); sol_quit(); } } } }
static void pass(const struct sol_flow_node *node) { struct test_result_data *d = sol_flow_node_get_private_data(node); if (!d->done) node_count--; mark_done(node); if (node_count == 0) sol_quit(); }
static bool write_cancelled_timeout(void *data) { write_one_cancelled(); read_one(); /* write_one_cancelled writes same values as write_one */ write_two(); /* reuse second part of test */ read_two(); sol_quit(); return false; }
static int _match_disconnected(sd_bus_message *m, void *userdata, sd_bus_error *error) { struct ctx *ctx = userdata; if (!ctx->exiting) { SOL_WRN("D-Bus connection terminated: %s. Exiting.", error && error->message ? error->message : "(unknown reason)"); sol_quit(); } return 0; }
//! [uart read] static ssize_t consumer_read_available(void *data, struct sol_uart *uart, const struct sol_buffer *buf) { struct sol_str_slice slice = sol_buffer_get_slice(buf); char *sep; sep = memchr(slice.data, '\0', slice.len); if (!sep) return 0; //Bytes will not be removed fom the rx buffer //Close the UART! if (sol_str_slice_str_contains(slice, "close")) { sol_uart_close(uart); //This is completely safe consumer = NULL; printf("\n\n** Consumer **: Received the close command\n\n"); sol_quit(); } else { printf("\n\n** Consumer ** : Received UUID %.*s\n\n", SOL_STR_SLICE_PRINT(slice)); } return slice.len; //slice.len bytes will be removed from the rx buffer }
static void on_digest_ready(void *data, struct sol_message_digest *handle, struct sol_blob *digest) { struct feed_ctx *ctx = data; struct sol_buffer buf; int r; sol_buffer_init(&buf); r = sol_buffer_append_as_base16(&buf, sol_str_slice_from_blob(digest), false); if (r == 0) { printf("%s\t%s\n", (char *)buf.data, ctx->file); } sol_buffer_fini(&buf); print_time(ctx, ctx->done, "final"); sol_message_digest_del(handle); free(ctx); pending--; if (pending == 0) sol_quit(); }
static void check_done(void) { if (did_idle && did_timeout && did_fd) sol_quit(); }