static void cleanup_test() { grpc_call_destroy(g_state.call); cq_verifier_destroy(g_state.cqv); grpc_channel_destroy(g_state.chan); gpr_free(g_state.details); grpc_metadata_array_destroy(&g_state.initial_metadata_recv); grpc_metadata_array_destroy(&g_state.trailing_metadata_recv); if (!g_state.is_client) { grpc_call_destroy(g_state.server_call); grpc_server_shutdown_and_notify(g_state.server, g_state.cq, tag(1000)); GPR_ASSERT(grpc_completion_queue_pluck(g_state.cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL).type == GRPC_OP_COMPLETE); grpc_server_destroy(g_state.server); grpc_call_details_destroy(&g_state.call_details); grpc_metadata_array_destroy(&g_state.server_initial_metadata_recv); } grpc_completion_queue_shutdown(g_state.cq); while (grpc_completion_queue_next(g_state.cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL).type != GRPC_QUEUE_SHUTDOWN) ; grpc_completion_queue_destroy(g_state.cq); }
int main(int argc, char **argv) { grpc_completion_queue *cq1; grpc_completion_queue *cq2; grpc_server *server; grpc_test_init(argc, argv); grpc_init(); cq1 = grpc_completion_queue_create(); cq2 = grpc_completion_queue_create(); server = grpc_server_create(NULL); grpc_server_register_completion_queue(server, cq1); grpc_server_add_insecure_http2_port(server, "[::]:0"); grpc_server_register_completion_queue(server, cq2); grpc_server_start(server); grpc_server_shutdown_and_notify(server, cq2, NULL); grpc_completion_queue_next( cq2, gpr_inf_future(GPR_CLOCK_REALTIME)); /* cue queue hang */ grpc_completion_queue_shutdown(cq1); grpc_completion_queue_shutdown(cq2); grpc_completion_queue_next(cq1, gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME)); grpc_server_destroy(server); grpc_completion_queue_destroy(cq1); grpc_completion_queue_destroy(cq2); grpc_shutdown(); return 0; }
static void pygrpc_server_dealloc(Server *self) { if (self->c_server != NULL) { grpc_server_destroy(self->c_server); } Py_XDECREF(self->completion_queue); self->ob_type->tp_free((PyObject *)self); }
void test_register_method_fail(void) { grpc_server *server = grpc_server_create(NULL, NULL); void *method; void *method_old; method = grpc_server_register_method(server, NULL, NULL, GRPC_SRM_PAYLOAD_NONE, 0); GPR_ASSERT(method == NULL); method_old = grpc_server_register_method(server, "m", "h", GRPC_SRM_PAYLOAD_NONE, 0); GPR_ASSERT(method_old != NULL); method = grpc_server_register_method( server, "m", "h", GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, 0); GPR_ASSERT(method == NULL); method_old = grpc_server_register_method(server, "m2", "h2", GRPC_SRM_PAYLOAD_NONE, GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST); GPR_ASSERT(method_old != NULL); method = grpc_server_register_method(server, "m2", "h2", GRPC_SRM_PAYLOAD_NONE, 0); GPR_ASSERT(method == NULL); method = grpc_server_register_method( server, "m2", "h2", GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST); GPR_ASSERT(method == NULL); grpc_server_destroy(server); }
static void test_early_server_shutdown_finishes_tags( grpc_end2end_test_config config) { grpc_end2end_test_fixture f = begin_test( config, "test_early_server_shutdown_finishes_tags", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); grpc_call *s = (void *)1; grpc_call_details call_details; grpc_metadata_array request_metadata_recv; grpc_metadata_array_init(&request_metadata_recv); grpc_call_details_init(&call_details); /* upon shutdown, the server should finish all requested calls indicating no new call */ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( f.server, &s, &call_details, &request_metadata_recv, f.cq, f.cq, tag(101))); grpc_server_shutdown_and_notify(f.server, f.cq, tag(1000)); CQ_EXPECT_COMPLETION(cqv, tag(101), 0); CQ_EXPECT_COMPLETION(cqv, tag(1000), 1); cq_verify(cqv); GPR_ASSERT(s == NULL); grpc_server_destroy(f.server); end_test(&f); config.tear_down_data(&f); cq_verifier_destroy(cqv); }
static void teardown_servers(servers_fixture *f) { size_t i; /* Destroy server. */ for (i = 0; i < f->num_servers; i++) { if (f->servers[i] == NULL) continue; grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) .type == GRPC_OP_COMPLETE); grpc_server_destroy(f->servers[i]); } grpc_completion_queue_shutdown(f->cq); drain_cq(f->cq); grpc_completion_queue_destroy(f->cq); gpr_free(f->servers); for (i = 0; i < f->num_servers; i++) { gpr_free(f->servers_hostports[i]); grpc_metadata_array_destroy(&f->request_metadata_recv[i]); } gpr_free(f->servers_hostports); gpr_free(f->request_metadata_recv); gpr_free(f->server_calls); gpr_free(f); }
/* call-seq: cq = CompletionQueue.new server = Server.new(cq, {'arg1': 'value1'}) ... // do stuff with server ... ... // to shutdown the server server.destroy(cq) ... // to shutdown the server with a timeout server.destroy(cq, timeout) Destroys server instances. */ static VALUE grpc_rb_server_destroy(int argc, VALUE *argv, VALUE self) { VALUE cqueue = Qnil; VALUE timeout = Qnil; grpc_completion_queue *cq = NULL; grpc_event ev; grpc_rb_server *s = NULL; /* "11" == 1 mandatory args, 1 (timeout) is optional */ rb_scan_args(argc, argv, "11", &cqueue, &timeout); cq = grpc_rb_get_wrapped_completion_queue(cqueue); TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); if (s->wrapped != NULL) { grpc_server_shutdown_and_notify(s->wrapped, cq, NULL); ev = grpc_rb_completion_queue_pluck_event(cqueue, Qnil, timeout); if (!ev.success) { rb_warn("server shutdown failed, cancelling the calls, objects may leak"); grpc_server_cancel_all_calls(s->wrapped); return Qfalse; } grpc_server_destroy(s->wrapped); s->wrapped = NULL; } return Qtrue; }
static void shutdown_server(grpc_end2end_test_fixture *f) { if (!f->server) return; grpc_server_shutdown_and_notify(f->server, f->server_cq, tag(1000)); GPR_ASSERT(grpc_completion_queue_pluck(f->server_cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)).type == GRPC_OP_COMPLETE); grpc_server_destroy(f->server); f->server = NULL; }
static void shutdown_server(grpc_end2end_test_fixture *f) { if (!f->server) return; grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000)); GPR_ASSERT(grpc_completion_queue_pluck( f->cq, tag(1000), grpc_timeout_seconds_to_deadline(5), NULL) .type == GRPC_OP_COMPLETE); grpc_server_destroy(f->server); f->server = NULL; }
static void kill_server(const servers_fixture *f, size_t i) { gpr_log(GPR_INFO, "KILLING SERVER %d", i); GPR_ASSERT(f->servers[i] != NULL); grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); GPR_ASSERT( grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) .type == GRPC_OP_COMPLETE); grpc_server_destroy(f->servers[i]); f->servers[i] = NULL; }
void test_bind_server_twice(void) { char *addr; grpc_server *server1 = grpc_server_create(NULL, NULL); grpc_server *server2 = grpc_server_create(NULL, NULL); grpc_completion_queue *cq = grpc_completion_queue_create(NULL); int port = grpc_pick_unused_port_or_die(); gpr_asprintf(&addr, "[::]:%d", port); grpc_server_register_completion_queue(server1, cq, NULL); grpc_server_register_completion_queue(server2, cq, NULL); GPR_ASSERT(port == grpc_server_add_insecure_http2_port(server1, addr)); GPR_ASSERT(0 == grpc_server_add_insecure_http2_port(server2, addr)); grpc_server_shutdown_and_notify(server1, cq, NULL); grpc_server_shutdown_and_notify(server2, cq, NULL); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); grpc_server_destroy(server1); grpc_server_destroy(server2); grpc_completion_queue_destroy(cq); gpr_free(addr); }
void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { fullstack_fixture_data *ffd = f->fixture_data; if (f->server) { grpc_server_destroy(f->server); } f->server = grpc_server_create(server_args); grpc_server_register_completion_queue(f->server, f->cq); GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); }
// Simple gRPC server. This listens until client_handshake_complete occurs. static void server_thread(void *arg) { const int port = *(int *)arg; // Load key pair and establish server SSL credentials. grpc_ssl_pem_key_cert_pair pem_key_cert_pair; gpr_slice ca_slice, cert_slice, key_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_CA_PATH, 1, &ca_slice))); GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_CERT_PATH, 1, &cert_slice))); GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(SSL_KEY_PATH, 1, &key_slice))); const char *ca_cert = (const char *)GPR_SLICE_START_PTR(ca_slice); pem_key_cert_pair.private_key = (const char *)GPR_SLICE_START_PTR(key_slice); pem_key_cert_pair.cert_chain = (const char *)GPR_SLICE_START_PTR(cert_slice); grpc_server_credentials *ssl_creds = grpc_ssl_server_credentials_create( ca_cert, &pem_key_cert_pair, 1, 0, NULL); // Start server listening on local port. char *addr; gpr_asprintf(&addr, "127.0.0.1:%d", port); grpc_server *server = grpc_server_create(NULL, NULL); GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds)); free(addr); grpc_completion_queue *cq = grpc_completion_queue_create(NULL); grpc_server_register_completion_queue(server, cq, NULL); grpc_server_start(server); // Wait a bounded number of time until client_handshake_complete is set, // sleeping between polls. int retries = 10; while (!gpr_event_get(&client_handshake_complete) && retries-- > 0) { const gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL); GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT); } gpr_log(GPR_INFO, "Shutting down server"); grpc_server_shutdown_and_notify(server, cq, NULL); grpc_completion_queue_shutdown(cq); const gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL); GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); grpc_server_destroy(server); grpc_completion_queue_destroy(cq); grpc_server_credentials_release(ssl_creds); gpr_slice_unref(cert_slice); gpr_slice_unref(key_slice); gpr_slice_unref(ca_slice); }
static VALUE grpc_rb_server_destroy(VALUE self) { grpc_rb_server *s = NULL; Data_Get_Struct(self, grpc_rb_server, s); if (s->wrapped != NULL) { grpc_server_shutdown(s->wrapped); grpc_server_destroy(s->wrapped); s->wrapped = NULL; s->mark = Qnil; } return Qnil; }
void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { fullstack_fixture_data *ffd = f->fixture_data; if (f->server) { grpc_server_destroy(f->server); } f->server = grpc_server_create(server_args, NULL); grpc_server_register_completion_queue(f->server, f->cq, NULL); GPR_ASSERT(grpc_server_add_insecure_http2_port( f->server, grpc_end2end_proxy_get_server_port(ffd->proxy))); grpc_server_start(f->server); }
void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy) { grpc_server_shutdown_and_notify(proxy->server, proxy->cq, new_closure(shutdown_complete, proxy)); gpr_thd_join(proxy->thd); gpr_free(proxy->proxy_port); gpr_free(proxy->server_port); grpc_server_destroy(proxy->server); grpc_channel_destroy(proxy->client); grpc_completion_queue_destroy(proxy->cq); grpc_call_details_destroy(&proxy->new_call_details); gpr_free(proxy); }
static void chttp2_init_server_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *server_args, grpc_server_credentials *server_creds) { fullstack_secure_fixture_data *ffd = f->fixture_data; if (f->server) { grpc_server_destroy(f->server); } f->server = grpc_server_create(f->server_cq, server_args); GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds)); grpc_server_credentials_release(server_creds); grpc_server_start(f->server); }
int main(int argc, char **argv) { grpc_completion_queue *cq1; grpc_completion_queue *cq2; grpc_completion_queue *cq3; grpc_completion_queue_attributes attr; grpc_server *server; grpc_test_init(argc, argv); grpc_init(); attr.version = 1; attr.cq_completion_type = GRPC_CQ_NEXT; attr.cq_polling_type = GRPC_CQ_DEFAULT_POLLING; cq1 = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); attr.cq_polling_type = GRPC_CQ_NON_LISTENING; cq2 = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); attr.cq_polling_type = GRPC_CQ_NON_POLLING; cq3 = grpc_completion_queue_create( grpc_completion_queue_factory_lookup(&attr), &attr, NULL); server = grpc_server_create(NULL, NULL); grpc_server_register_completion_queue(server, cq1, NULL); grpc_server_add_insecure_http2_port(server, "[::]:0"); grpc_server_register_completion_queue(server, cq2, NULL); grpc_server_register_completion_queue(server, cq3, NULL); grpc_server_start(server); grpc_server_shutdown_and_notify(server, cq2, NULL); grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); /* cue queue hang */ grpc_completion_queue_shutdown(cq1); grpc_completion_queue_shutdown(cq2); grpc_completion_queue_shutdown(cq3); grpc_completion_queue_next(cq1, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_completion_queue_next(cq3, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_server_destroy(server); grpc_completion_queue_destroy(cq1); grpc_completion_queue_destroy(cq2); grpc_completion_queue_destroy(cq3); grpc_shutdown(); return 0; }
void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { fullstack_fixture_data *ffd = f->fixture_data; if (f->server) { grpc_server_destroy(f->server); } grpc_arg arg = grpc_load_reporting_config_create_arg(g_server_lrc); server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, NULL); grpc_channel_args_destroy(server_args); grpc_server_register_completion_queue(f->server, f->cq, NULL); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); }
static void test_ping(grpc_end2end_test_config config) { grpc_end2end_test_fixture f = config.create_fixture(NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; int i; config.init_client(&f, NULL, NULL); config.init_server(&f, NULL); grpc_channel_ping(f.client, f.cq, tag(0), NULL); CQ_EXPECT_COMPLETION(cqv, tag(0), 0); /* check that we're still in idle, and start connecting */ GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 1) == GRPC_CHANNEL_IDLE); /* we'll go through some set of transitions (some might be missed), until READY is reached */ while (state != GRPC_CHANNEL_READY) { grpc_channel_watch_connectivity_state( f.client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(99)); CQ_EXPECT_COMPLETION(cqv, tag(99), 1); cq_verify(cqv); state = grpc_channel_check_connectivity_state(f.client, 0); GPR_ASSERT(state == GRPC_CHANNEL_READY || state == GRPC_CHANNEL_CONNECTING || state == GRPC_CHANNEL_TRANSIENT_FAILURE); } for (i = 1; i <= 5; i++) { grpc_channel_ping(f.client, f.cq, tag(i), NULL); CQ_EXPECT_COMPLETION(cqv, tag(i), 1); cq_verify(cqv); } grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead)); CQ_EXPECT_COMPLETION(cqv, tag(0xdead), 1); cq_verify(cqv); /* cleanup server */ grpc_server_destroy(f.server); grpc_channel_destroy(f.client); grpc_completion_queue_shutdown(f.cq); grpc_completion_queue_destroy(f.cq); config.tear_down_data(&f); cq_verifier_destroy(cqv); }
void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { fullstack_compression_fixture_data *ffd = f->fixture_data; if (ffd->server_args_compression != NULL) { grpc_channel_args_destroy(ffd->server_args_compression); } ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( server_args, GRPC_COMPRESS_GZIP); if (f->server) { grpc_server_destroy(f->server); } f->server = grpc_server_create(ffd->server_args_compression); grpc_server_register_completion_queue(f->server, f->cq); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); }
static void destroy_server(grpc_rb_server *server, gpr_timespec deadline) { grpc_event ev; if (server->wrapped != NULL) { grpc_server_shutdown_and_notify(server->wrapped, server->queue, NULL); ev = rb_completion_queue_pluck(server->queue, NULL, deadline, NULL); if (ev.type == GRPC_QUEUE_TIMEOUT) { grpc_server_cancel_all_calls(server->wrapped); rb_completion_queue_pluck(server->queue, NULL, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); } grpc_server_destroy(server->wrapped); grpc_rb_completion_queue_destroy(server->queue); server->wrapped = NULL; server->queue = NULL; } }
/* Destroys server instances. */ static void grpc_rb_server_free(void *p) { grpc_rb_server *svr = NULL; if (p == NULL) { return; }; svr = (grpc_rb_server *)p; /* Deletes the wrapped object if the mark object is Qnil, which indicates that no other object is the actual owner. */ if (svr->wrapped != NULL && svr->mark == Qnil) { grpc_server_shutdown(svr->wrapped); grpc_server_destroy(svr->wrapped); } xfree(p); }
void chttp2_init_server_load_reporting(grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { load_reporting_fixture_data *ffd = f->fixture_data; grpc_arg arg = grpc_load_reporting_enable_arg(); if (f->server) { grpc_server_destroy(f->server); } server_args = grpc_channel_args_copy_and_add(server_args, &arg, 1); f->server = grpc_server_create(server_args, NULL); { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_args_destroy(&exec_ctx, server_args); grpc_exec_ctx_finish(&exec_ctx); } grpc_server_register_completion_queue(f->server, f->cq, NULL); GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); }
void test_add_same_port_twice() { int port = grpc_pick_unused_port_or_die(); char *addr = NULL; grpc_completion_queue *cq = grpc_completion_queue_create(NULL); grpc_server *server = grpc_server_create(NULL, NULL); grpc_server_credentials *fake_creds = grpc_fake_transport_security_server_credentials_create(); gpr_join_host_port(&addr, "localhost", port); GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, fake_creds)); GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, fake_creds) == 0); grpc_server_credentials_release(fake_creds); gpr_free(addr); grpc_server_shutdown_and_notify(server, cq, NULL); grpc_completion_queue_pluck(cq, NULL, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_server_destroy(server); grpc_completion_queue_destroy(cq); }
static void destroy_server(grpc_rb_server* server, gpr_timespec deadline) { grpc_event ev; // This can be started by app or implicitly by GC. Avoid a race between these. if (gpr_atm_full_fetch_add(&server->shutdown_started, (gpr_atm)1) == 0) { if (server->wrapped != NULL) { grpc_server_shutdown_and_notify(server->wrapped, server->queue, NULL); ev = rb_completion_queue_pluck(server->queue, NULL, deadline, NULL); if (ev.type == GRPC_QUEUE_TIMEOUT) { grpc_server_cancel_all_calls(server->wrapped); rb_completion_queue_pluck(server->queue, NULL, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); } grpc_server_destroy(server->wrapped); grpc_rb_completion_queue_destroy(server->queue); server->wrapped = NULL; server->queue = NULL; } } }
/* Destroys server instances. */ static void grpc_rb_server_free(void *p) { grpc_rb_server *svr = NULL; if (p == NULL) { return; }; svr = (grpc_rb_server *)p; /* Deletes the wrapped object if the mark object is Qnil, which indicates that no other object is the actual owner. */ /* grpc_server_shutdown does not exist. Change this to something that does or delete it */ if (svr->wrapped != NULL && svr->mark == Qnil) { // grpc_server_shutdown(svr->wrapped); // Aborting to indicate a bug abort(); grpc_server_destroy(svr->wrapped); } xfree(p); }
static void shutdown_server(grpc_end2end_test_fixture *f) { if (!f->server) return; grpc_server_destroy(f->server); f->server = NULL; }
void grpc_run_bad_client_test(const char *name, const char *client_payload, size_t client_payload_length, grpc_bad_client_server_side_validator validator) { grpc_endpoint_pair sfd; thd_args a; gpr_thd_id id; gpr_slice slice = gpr_slice_from_copied_buffer(client_payload, client_payload_length); /* Add a debug log */ gpr_log(GPR_INFO, "TEST: %s", name); /* Init grpc */ grpc_init(); /* Create endpoints */ sfd = grpc_iomgr_create_endpoint_pair(65536); /* Create server, completion events */ a.server = grpc_server_create_from_filters(NULL, 0, NULL); a.cq = grpc_completion_queue_create(); gpr_event_init(&a.done_thd); gpr_event_init(&a.done_write); a.validator = validator; grpc_server_register_completion_queue(a.server, a.cq); grpc_server_start(a.server); grpc_create_chttp2_transport(server_setup_transport, &a, NULL, sfd.server, NULL, 0, grpc_mdctx_create(), 0); /* Bind everything into the same pollset */ grpc_endpoint_add_to_pollset(sfd.client, grpc_cq_pollset(a.cq)); grpc_endpoint_add_to_pollset(sfd.server, grpc_cq_pollset(a.cq)); /* Check a ground truth */ GPR_ASSERT(grpc_server_has_open_connections(a.server)); /* Start validator */ gpr_thd_new(&id, thd_func, &a, NULL); /* Write data */ switch (grpc_endpoint_write(sfd.client, &slice, 1, done_write, &a)) { case GRPC_ENDPOINT_WRITE_DONE: done_write(&a, 1); break; case GRPC_ENDPOINT_WRITE_PENDING: break; case GRPC_ENDPOINT_WRITE_ERROR: done_write(&a, 0); break; } /* Await completion */ GPR_ASSERT( gpr_event_wait(&a.done_write, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))); GPR_ASSERT(gpr_event_wait(&a.done_thd, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))); /* Shutdown */ grpc_endpoint_destroy(sfd.client); grpc_server_destroy(a.server); grpc_completion_queue_destroy(a.cq); grpc_shutdown(); }
GPR_EXPORT void GPR_CALLTYPE grpcsharp_server_destroy(grpc_server *server) { grpc_server_destroy(server); }