| 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_POSIX_SOCKET_IOMGR |
| 24 |
|
| 25 |
#include "src/core/lib/iomgr/ev_posix.h" |
| 26 |
#include "src/core/lib/iomgr/iomgr_internal.h" |
| 27 |
#include "src/core/lib/iomgr/resolve_address.h" |
| 28 |
#include "src/core/lib/iomgr/resolve_address_posix.h" |
| 29 |
#include "src/core/lib/iomgr/tcp_client.h" |
| 30 |
#include "src/core/lib/iomgr/tcp_posix.h" |
| 31 |
#include "src/core/lib/iomgr/tcp_server.h" |
| 32 |
#include "src/core/lib/iomgr/timer.h" |
| 33 |
|
| 34 |
extern grpc_tcp_server_vtable grpc_posix_tcp_server_vtable; |
| 35 |
extern grpc_tcp_client_vtable grpc_posix_tcp_client_vtable; |
| 36 |
extern grpc_timer_vtable grpc_generic_timer_vtable; |
| 37 |
extern grpc_pollset_vtable grpc_posix_pollset_vtable; |
| 38 |
extern grpc_pollset_set_vtable grpc_posix_pollset_set_vtable; |
| 39 |
|
| 40 |
static void iomgr_platform_init(void) { |
| 41 |
grpc_core::ResetDNSResolver(std::make_unique<grpc_core::NativeDNSResolver>()); |
| 42 |
grpc_wakeup_fd_global_init(); |
| 43 |
grpc_event_engine_init(); |
| 44 |
grpc_tcp_posix_init(); |
| 45 |
} |
| 46 |
|
| 47 |
static void iomgr_platform_flush(void) {} |
| 48 |
|
| 49 |
static void iomgr_platform_shutdown(void) { |
| 50 |
grpc_tcp_posix_shutdown(); |
| 51 |
grpc_event_engine_shutdown(); |
| 52 |
grpc_wakeup_fd_global_destroy(); |
| 53 |
grpc_core::ResetDNSResolver(nullptr); // delete the resolver |
| 54 |
} |
| 55 |
|
| 56 |
static void iomgr_platform_shutdown_background_closure(void) { |
| 57 |
grpc_shutdown_background_closure(); |
| 58 |
} |
| 59 |
|
| 60 |
static bool iomgr_platform_is_any_background_poller_thread(void) { |
| 61 |
return grpc_is_any_background_poller_thread(); |
| 62 |
} |
| 63 |
|
| 64 |
static bool iomgr_platform_add_closure_to_background_poller( |
| 65 |
grpc_closure* closure, grpc_error_handle error) { |
| 66 |
return grpc_add_closure_to_background_poller(closure, error); |
| 67 |
} |
| 68 |
|
| 69 |
static grpc_iomgr_platform_vtable vtable = { |
| 70 |
iomgr_platform_init, |
| 71 |
iomgr_platform_flush, |
| 72 |
iomgr_platform_shutdown, |
| 73 |
iomgr_platform_shutdown_background_closure, |
| 74 |
iomgr_platform_is_any_background_poller_thread, |
| 75 |
iomgr_platform_add_closure_to_background_poller}; |
| 76 |
|
| 77 |
void grpc_set_default_iomgr_platform() { |
| 78 |
grpc_set_tcp_client_impl(&grpc_posix_tcp_client_vtable); |
| 79 |
grpc_set_tcp_server_impl(&grpc_posix_tcp_server_vtable); |
| 80 |
grpc_set_timer_impl(&grpc_generic_timer_vtable); |
| 81 |
grpc_set_pollset_vtable(&grpc_posix_pollset_vtable); |
| 82 |
grpc_set_pollset_set_vtable(&grpc_posix_pollset_set_vtable); |
| 83 |
grpc_tcp_client_global_init(); |
| 84 |
grpc_set_iomgr_platform_vtable(&vtable); |
| 85 |
} |
| 86 |
|
| 87 |
bool grpc_iomgr_run_in_background() { |
| 88 |
return grpc_event_engine_run_in_background(); |
| 89 |
} |
| 90 |
|
| 91 |
#endif /* GRPC_POSIX_SOCKET_IOMGR */ |