• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include <grpc/credentials.h>
20 #include <grpc/grpc.h>
21 #include <grpc/grpc_security.h>
22 #include <grpc/support/time.h>
23 
24 #include "test/core/test_util/test_config.h"
25 
main(int argc,char ** argv)26 int main(int argc, char** argv) {
27   grpc_completion_queue* cq1;
28   grpc_completion_queue* cq2;
29   grpc_completion_queue* cq3;
30   grpc_completion_queue_attributes attr;
31 
32   grpc_server* server;
33 
34   grpc::testing::TestEnvironment env(&argc, argv);
35   grpc_init();
36 
37   attr.version = 1;
38   attr.cq_completion_type = GRPC_CQ_NEXT;
39   attr.cq_polling_type = GRPC_CQ_DEFAULT_POLLING;
40   attr.cq_shutdown_cb = nullptr;
41   cq1 = grpc_completion_queue_create(
42       grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
43 
44   attr.cq_polling_type = GRPC_CQ_NON_LISTENING;
45   cq2 = grpc_completion_queue_create(
46       grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
47 
48   attr.cq_polling_type = GRPC_CQ_NON_POLLING;
49   cq3 = grpc_completion_queue_create(
50       grpc_completion_queue_factory_lookup(&attr), &attr, nullptr);
51 
52   server = grpc_server_create(nullptr, nullptr);
53   grpc_server_register_completion_queue(server, cq1, nullptr);
54   grpc_server_credentials* server_creds =
55       grpc_insecure_server_credentials_create();
56   grpc_server_add_http2_port(server, "[::]:0", server_creds);
57   grpc_server_credentials_release(server_creds);
58   grpc_server_register_completion_queue(server, cq2, nullptr);
59   grpc_server_register_completion_queue(server, cq3, nullptr);
60 
61   grpc_server_start(server);
62   grpc_server_shutdown_and_notify(server, cq2, nullptr);
63   grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME),
64                              nullptr);  // cue queue freeze
65   grpc_completion_queue_shutdown(cq1);
66   grpc_completion_queue_shutdown(cq2);
67   grpc_completion_queue_shutdown(cq3);
68 
69   grpc_completion_queue_next(cq1, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
70   grpc_completion_queue_next(cq2, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
71   grpc_completion_queue_next(cq3, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr);
72 
73   grpc_server_destroy(server);
74   grpc_completion_queue_destroy(cq1);
75   grpc_completion_queue_destroy(cq2);
76   grpc_completion_queue_destroy(cq3);
77   grpc_shutdown();
78   return 0;
79 }
80