+/* cui_server_wait - Connect to the discover server.
+ * @arg: Pointer to the cui instance.
+ *
+ * A timeout callback that attempts to connect to the discover server; on
+ * failure it registers itself with a one second timeout to try again.
+ * On success the cui->client struct will be set.
+ *
+ * Since this updates the status line when called it must not be called
+ * before the UI is ready.
+ */
+static int cui_server_wait(void *arg)
+{
+ struct cui *cui = cui_from_arg(arg);
+
+ if (cui->client) {
+ pb_debug("We already have a server!\n");
+ return 0;
+ }
+
+ /* We haven't yet connected to the server */
+ pb_log("Trying to connect...\n");
+ cui->client = discover_client_init(cui->waitset,
+ &cui_client_ops, cui);
+
+ if (!cui->client) {
+ waiter_register_timeout(cui->waitset, 1000, cui_server_wait,
+ cui);
+ nc_scr_status_printf(cui->current, "Info: Waiting for server");
+ } else {
+ nc_scr_status_printf(cui->current, "Info: Connected to server!");
+ talloc_steal(cui, cui->client);
+
+ if (cui->has_input) {
+ pb_log("Aborting default boot on server connect\n");
+ discover_client_cancel_default(cui->client);
+ }
+ }
+
+ return 0;
+}
+