static hg_return_t hg_test_bulk_forward_cb(const struct hg_cb_info *callback_info) { hg_handle_t handle = callback_info->info.forward.handle; hg_request_t *request = (hg_request_t *) callback_info->arg; size_t bulk_write_ret = 0; bulk_write_out_t bulk_write_out_struct; hg_return_t ret = HG_SUCCESS; /* Get output */ ret = HG_Get_output(handle, &bulk_write_out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get output\n"); goto done; } /* Get output parameters */ bulk_write_ret = bulk_write_out_struct.ret; printf("bulk_write returned: %zu\n", bulk_write_ret); /* Free request */ ret = HG_Free_output(handle, &bulk_write_out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not free output\n"); goto done; } hg_request_complete(request); done: return ret; }
/* callback triggered upon receipt of rpc response */ static hg_return_t my_rpc_cb(const struct hg_cb_info *info) { my_rpc_out_t out; int ret; struct my_rpc_state *my_rpc_state_p = info->arg; assert(info->ret == HG_SUCCESS); /* decode response */ ret = HG_Get_output(info->info.forward.handle, &out); assert(ret == 0); (void)ret; printf("Got response ret: %d\n", out.ret); /* clean up resources consumed by this rpc */ HG_Bulk_free(my_rpc_state_p->bulk_handle); HG_Free_output(info->info.forward.handle, &out); HG_Destroy(info->info.forward.handle); free(my_rpc_state_p->buffer); free(my_rpc_state_p); /* signal to main() that we are done */ pthread_mutex_lock(&done_mutex); done++; pthread_cond_signal(&done_cond); pthread_mutex_unlock(&done_mutex); return(HG_SUCCESS); }
static hg_return_t hg_test_rpc_forward_cb(const struct hg_cb_info *callback_info) { hg_handle_t handle = callback_info->handle; hg_request_t *request = (hg_request_t *) callback_info->arg; int rpc_open_ret; int rpc_open_event_id; rpc_open_out_t rpc_open_out_struct; hg_return_t ret = HG_SUCCESS; /* Get output */ ret = HG_Get_output(handle, &rpc_open_out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get output\n"); goto done; } /* Get output parameters */ rpc_open_ret = rpc_open_out_struct.ret; rpc_open_event_id = rpc_open_out_struct.event_id; printf("rpc_open returned: %d with event_id: %d\n", rpc_open_ret, rpc_open_event_id); /* Free request */ ret = HG_Free_output(handle, &rpc_open_out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not free output\n"); goto done; } hg_request_complete(request); done: return ret; }
static hg_return_t hg_test_rpc_forward_cb(const struct hg_cb_info *callback_info) { hg_handle_t handle = callback_info->info.forward.handle; hg_request_t *request = (hg_request_t *) callback_info->arg; int rpc_open_ret; int rpc_open_event_id; rpc_open_out_t rpc_open_out_struct; hg_return_t ret = HG_SUCCESS; if (callback_info->ret != HG_CANCELED) { fprintf(stderr, "Error: HG_Forward() was not canceled: %d\n", callback_info->ret); /* Get output */ ret = HG_Get_output(handle, &rpc_open_out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not get output\n"); goto done; } /* Get output parameters */ rpc_open_ret = rpc_open_out_struct.ret; rpc_open_event_id = rpc_open_out_struct.event_id; printf("rpc_open returned: %d with event_id: %d\n", rpc_open_ret, rpc_open_event_id); /* Free request */ ret = HG_Free_output(handle, &rpc_open_out_struct); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not free output\n"); goto done; } } else { printf("HG_Forward() was successfully canceled\n"); } hg_request_complete(request); done: return ret; }
/*---------------------------------------------------------------------------*/ static hg_return_t hg_test_rpc_forward_cb(const struct hg_cb_info *callback_info) { hg_handle_t handle = callback_info->info.forward.handle; hg_request_t *request = (hg_request_t *) callback_info->arg; overflow_out_t out_struct; hg_string_t string; size_t string_len; hg_return_t ret = HG_SUCCESS; if (callback_info->ret != HG_SUCCESS) { HG_TEST_LOG_WARNING("Return from callback info is not HG_SUCCESS"); goto done; } /* Get output */ ret = HG_Get_output(handle, &out_struct); if (ret != HG_SUCCESS) { HG_TEST_LOG_ERROR("Could not get output"); goto done; } /* Get output parameters */ string = out_struct.string; string_len = out_struct.string_len; HG_TEST_LOG_DEBUG("Returned string (length %zu): %s", string_len, string); (void) string; (void) string_len; /* Free request */ ret = HG_Free_output(handle, &out_struct); if (ret != HG_SUCCESS) { HG_TEST_LOG_ERROR("Could not free output"); goto done; } done: hg_request_complete(request); return ret; }
/* This routine gets executed after a call to HG_Trigger and * the RPC has completed */ static hg_return_t snappy_compress_rpc_cb(const struct hg_cb_info *callback_info) { struct snappy_compress_rpc_args *snappy_compress_rpc_args = (struct snappy_compress_rpc_args *) callback_info->arg; hg_handle_t handle = callback_info->info.forward.handle; int *input; size_t source_length; void *compressed; size_t compressed_length; int *uncompressed; size_t uncompressed_length; snappy_compress_out_t snappy_compress_output; snappy_status ret; /* Get output */ printf("Received output from target\n"); HG_Get_output(handle, &snappy_compress_output); /* Get Snappy output parameters */ ret = snappy_compress_output.ret; compressed_length = snappy_compress_output.compressed_length; compressed = snappy_compress_rpc_args->compressed; input = snappy_compress_rpc_args->input; source_length = snappy_compress_rpc_args->input_length; /* Check ret */ if (ret != SNAPPY_OK) { fprintf(stderr, "Error: snappy_compressed failed with ret %d\n", ret); } /* The output data is now in the bulk buffer */ printf("Compressed buffer length is: %zu\n", compressed_length); print_buf(5, (int *)compressed); if (snappy_validate_compressed_buffer(compressed, compressed_length) == SNAPPY_OK) { printf("Compressed buffer validated: compressed successfully\n"); } uncompressed_length = source_length * sizeof(int); uncompressed = (int *) malloc(uncompressed_length); /* Uncompress data and check uncompressed_length */ printf("Uncompressing buffer...\n"); snappy_uncompress(compressed, compressed_length, (char *) uncompressed, &uncompressed_length); printf("Uncompressed buffer length is: %zu\n", uncompressed_length); print_buf(20, uncompressed); /* Free output and handles */ HG_Free_output(handle, &snappy_compress_output); HG_Bulk_free(snappy_compress_rpc_args->input_bulk_handle); HG_Bulk_free(snappy_compress_rpc_args->compressed_bulk_handle); /* Free data */ free(uncompressed); free(compressed); free(input); free(snappy_compress_rpc_args); /* We're done */ snappy_compress_done_g = HG_TRUE; return HG_SUCCESS; }
/*---------------------------------------------------------------------------*/ static hg_return_t hg_test_drc_token_request(struct hg_test_info *hg_test_info) { hg_request_t *request = NULL; hg_handle_t handle; #ifdef HG_TEST_DRC_USE_TOKEN hg_string_t token; #else hg_uint32_t credential; #endif hg_test_drc_grant_in_t in_struct; hg_test_drc_grant_out_t out_struct; hg_return_t ret = HG_SUCCESS; #ifndef HG_TEST_DRC_IGNORE int rc; #endif /* Look up target addr using target name info */ ret = HG_Hl_addr_lookup_wait(hg_test_info->context, hg_test_info->request_class, hg_test_info->na_test_info.target_name, &hg_test_info->target_addr, HG_MAX_IDLE_TIME); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not find addr for target %s", hg_test_info->na_test_info.target_name); goto done; } /* Create new request */ request = hg_request_create(hg_test_info->request_class); /* Create request with invalid RPC id */ ret = HG_Create(hg_test_info->context, hg_test_info->target_addr, hg_test_drc_grant_id_g, &handle); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not create handle"); goto done; } /* Get WLM ID and set input */ #ifndef HG_TEST_DRC_IGNORE in_struct.wlm_id = drc_get_wlm_id(); #else in_struct.wlm_id = 12340; #endif /* Forward call to target addr */ printf("# %u requesting access to remote...\n", in_struct.wlm_id); fflush(stdout); ret = HG_Forward(handle, hg_test_drc_token_request_cb, request, &in_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not forward call with id=%d", hg_test_drc_grant_id_g); goto done; } /* Wait for completion */ hg_request_wait(request, HG_MAX_IDLE_TIME, NULL); /* Get output */ ret = HG_Get_output(handle, &out_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not get output"); goto done; } #ifdef HG_TEST_DRC_USE_TOKEN /* Get token back */ token = out_struct.token; printf("# Received token %s\n", token); fflush(stdout); /* Translate token */ #ifndef HG_TEST_DRC_IGNORE rc = drc_access_with_token(token, 0, &hg_test_info->credential_info); if (rc != DRC_SUCCESS) {/* failed to grant access to the credential */ HG_LOG_ERROR("drc_access_with_token() failed (%d, %s)", rc, drc_strerror(-rc)); ret = HG_PROTOCOL_ERROR; goto done; } #endif #else /* Get credential back */ credential = out_struct.credential; printf("# Received credential %u\n", credential); fflush(stdout); /* Access credential */ #ifndef HG_TEST_DRC_IGNORE drc_access_again: rc = drc_access(credential, 0, &hg_test_info->credential_info); if (rc != DRC_SUCCESS) { /* failed to access credential */ if (rc == -DRC_EINVAL) { sleep(1); goto drc_access_again; } HG_LOG_ERROR("drc_access() failed (%d, %s)", rc, drc_strerror(-rc)); ret = HG_PROTOCOL_ERROR; goto done; } #endif #endif /* Set cookie for further use */ #ifndef HG_TEST_DRC_IGNORE hg_test_info->cookie = drc_get_first_cookie(hg_test_info->credential_info); #else hg_test_info->cookie = 123456789; #endif printf("# Cookie is %u\n", hg_test_info->cookie); fflush(stdout); /* Clean up resources */ ret = HG_Free_output(handle, &out_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not free output"); goto done; } ret = HG_Destroy(handle); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not destroy handle"); goto done; } hg_request_destroy(request); /* Free target addr */ ret = HG_Addr_free(hg_test_info->hg_class, hg_test_info->target_addr); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not free addr"); goto done; } done: return ret; }