| 110 | }; |
| 111 | |
| 112 | int server(actor_system& sys, std::string_view mode, uint16_t port) { |
| 113 | auto wait_for_shutdown = [] { |
| 114 | while (!shutdown_flag) |
| 115 | std::this_thread::sleep_for(250ms); |
| 116 | return EXIT_SUCCESS; |
| 117 | }; |
| 118 | auto& mm = sys.middleman(); |
| 119 | if (mode == "remote_actor") { |
| 120 | auto cell = sys.spawn(cell_impl, 42); |
| 121 | auto actual_port = io::publish(cell, port, nullptr, true); |
| 122 | if (!actual_port) { |
| 123 | std::cout << "failed to open port " << port << ": " |
| 124 | << to_string(actual_port.error()) << '\n'; |
| 125 | return EXIT_FAILURE; |
| 126 | } |
| 127 | return EXIT_SUCCESS; |
| 128 | } |
| 129 | if (mode == "remote_spawn") { |
| 130 | auto actual_port = mm.open(port, nullptr, true); |
| 131 | if (!actual_port) { |
| 132 | std::cout << "failed to open port " << port << ": " |
| 133 | << to_string(actual_port.error()) << '\n'; |
| 134 | return EXIT_FAILURE; |
| 135 | } |
| 136 | return wait_for_shutdown(); |
| 137 | } |
| 138 | if (mode == "remote_lookup") { |
| 139 | auto cell = sys.spawn(cell_impl, 23); |
| 140 | sys.registry().put("cell", cell); |
| 141 | auto actual_port = mm.open(port, nullptr, true); |
| 142 | if (!actual_port) { |
| 143 | std::cout << "failed to open port " << port << ": " |
| 144 | << to_string(actual_port.error()) << '\n'; |
| 145 | return EXIT_FAILURE; |
| 146 | } |
| 147 | wait_for_shutdown(); |
| 148 | anon_send_exit(cell, exit_reason::user_shutdown); |
| 149 | return EXIT_SUCCESS; |
| 150 | } |
| 151 | if (mode == "unpublish" || mode == "monitor_node" |
| 152 | || mode == "deserialization_error") { |
| 153 | auto ctrl = sys.spawn(controller_impl); |
| 154 | auto actual_port = io::publish(ctrl, port, nullptr, true); |
| 155 | if (!actual_port) { |
| 156 | std::cout << "failed to open port " << port << ": " |
| 157 | << to_string(actual_port.error()) << '\n'; |
| 158 | return EXIT_FAILURE; |
| 159 | } |
| 160 | wait_for_shutdown(); |
| 161 | anon_send_exit(ctrl, exit_reason::user_shutdown); |
| 162 | return EXIT_SUCCESS; |
| 163 | } |
| 164 | if (mode == "prometheus") { |
| 165 | return wait_for_shutdown(); |
| 166 | } |
| 167 | if (mode == "rendezvous") { |
| 168 | auto cell = sys.spawn(actor_hdl_cell_impl); |
| 169 | auto actual_port = io::publish(cell, port, nullptr, true); |