• 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 }
65 
iomgr_platform_flush(void)66 static void iomgr_platform_flush(void) { grpc_iocp_flush(); }
67 
iomgr_platform_shutdown(void)68 static void iomgr_platform_shutdown(void) {
69   grpc_pollset_global_shutdown();
70   grpc_iocp_shutdown();
71   winsock_shutdown();
72 }
73 
74 static grpc_iomgr_platform_vtable vtable = {
75     iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown};
76 
grpc_set_default_iomgr_platform()77 void grpc_set_default_iomgr_platform() {
78   grpc_set_tcp_client_impl(&grpc_windows_tcp_client_vtable);
79   grpc_set_tcp_server_impl(&grpc_windows_tcp_server_vtable);
80   grpc_set_timer_impl(&grpc_generic_timer_vtable);
81   grpc_set_pollset_vtable(&grpc_windows_pollset_vtable);
82   grpc_set_pollset_set_vtable(&grpc_windows_pollset_set_vtable);
83   grpc_set_resolver_impl(&grpc_windows_resolver_vtable);
84   grpc_set_iomgr_platform_vtable(&vtable);
85 }
86 
87 #endif /* GRPC_WINSOCK_SOCKET */
88