• 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/support/port_platform.h>
20 
21 #include "src/core/lib/iomgr/port.h"
22 
23 #ifdef GRPC_WINSOCK_SOCKET
24 
25 #include "src/core/lib/iomgr/sockaddr_windows.h"
26 
27 #include <grpc/support/log.h>
28 
29 #include "src/core/lib/iomgr/iocp_windows.h"
30 #include "src/core/lib/iomgr/iomgr.h"
31 #include "src/core/lib/iomgr/pollset_windows.h"
32 #include "src/core/lib/iomgr/resolve_address.h"
33 #include "src/core/lib/iomgr/socket_windows.h"
34 #include "src/core/lib/iomgr/tcp_client.h"
35 #include "src/core/lib/iomgr/tcp_server.h"
36 #include "src/core/lib/iomgr/timer.h"
37 
38 extern grpc_tcp_server_vtable grpc_windows_tcp_server_vtable;
39 extern grpc_tcp_client_vtable grpc_windows_tcp_client_vtable;
40 extern grpc_timer_vtable grpc_generic_timer_vtable;
41 extern grpc_pollset_vtable grpc_windows_pollset_vtable;
42 extern grpc_pollset_set_vtable grpc_windows_pollset_set_vtable;
43 extern grpc_address_resolver_vtable grpc_windows_resolver_vtable;
44 
45 /* Windows' io manager is going to be fully designed using IO completion
46    ports. All of what we're doing here is basically make sure that
47    Windows sockets are initialized in and out. */
48 
winsock_init(void)49 static void winsock_init(void) {
50   WSADATA wsaData;
51   int status = WSAStartup(MAKEWORD(2, 0), &wsaData);
52   GPR_ASSERT(status == 0);
53 }
54 
winsock_shutdown(void)55 static void winsock_shutdown(void) {
56   int status = WSACleanup();
57   GPR_ASSERT(status == 0);
58 }
59 
iomgr_platform_init(void)60 static void iomgr_platform_init(void) {
61   winsock_init();
62   grpc_iocp_init();
63   grpc_pollset_global_init();
64   grpc_wsa_socket_flags_init();
65 }
66 
iomgr_platform_flush(void)67 static void iomgr_platform_flush(void) { grpc_iocp_flush(); }
68 
iomgr_platform_shutdown(void)69 static void iomgr_platform_shutdown(void) {
70   grpc_pollset_global_shutdown();
71   grpc_iocp_shutdown();
72   winsock_shutdown();
73 }
74 
iomgr_platform_shutdown_background_closure(void)75 static void iomgr_platform_shutdown_background_closure(void) {}
76 
iomgr_platform_is_any_background_poller_thread(void)77 static bool iomgr_platform_is_any_background_poller_thread(void) {
78   return false;
79 }
80 
iomgr_platform_add_closure_to_background_poller(grpc_closure * closure,grpc_error * error)81 static bool iomgr_platform_add_closure_to_background_poller(
82     grpc_closure* closure, grpc_error* error) {
83   return false;
84 }
85 
86 static grpc_iomgr_platform_vtable vtable = {
87     iomgr_platform_init,
88     iomgr_platform_flush,
89     iomgr_platform_shutdown,
90     iomgr_platform_shutdown_background_closure,
91     iomgr_platform_is_any_background_poller_thread,
92     iomgr_platform_add_closure_to_background_poller};
93 
grpc_set_default_iomgr_platform()94 void grpc_set_default_iomgr_platform() {
95   grpc_set_tcp_client_impl(&grpc_windows_tcp_client_vtable);
96   grpc_set_tcp_server_impl(&grpc_windows_tcp_server_vtable);
97   grpc_set_timer_impl(&grpc_generic_timer_vtable);
98   grpc_set_pollset_vtable(&grpc_windows_pollset_vtable);
99   grpc_set_pollset_set_vtable(&grpc_windows_pollset_set_vtable);
100   grpc_set_resolver_impl(&grpc_windows_resolver_vtable);
101   grpc_set_iomgr_platform_vtable(&vtable);
102 }
103 
grpc_iomgr_run_in_background()104 bool grpc_iomgr_run_in_background() { return false; }
105 
106 #endif /* GRPC_WINSOCK_SOCKET */
107