asks for a server address again, when connection is failed
This commit is contained in:
+12
-4
@@ -1,9 +1,10 @@
|
|||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||||
|
|
||||||
|
#include "alert.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <widget.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -14,19 +15,26 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <widget.h>
|
||||||
|
|
||||||
void connect_to_server(app_t *app) {
|
bool connect_to_server(app_t *app) {
|
||||||
struct sockaddr_in server;
|
struct sockaddr_in server;
|
||||||
server.sin_family = AF_INET;
|
server.sin_family = AF_INET;
|
||||||
server.sin_addr.s_addr = app->params->addr;
|
server.sin_addr.s_addr = app->params->addr;
|
||||||
server.sin_port = app->params->port;
|
server.sin_port = app->params->port;
|
||||||
if (-1 ==
|
if (-1 ==
|
||||||
connect(app->params->sd, (struct sockaddr *)&server, sizeof(server))) {
|
connect(app->params->sd, (struct sockaddr *)&server, sizeof(server))) {
|
||||||
perror("connect");
|
w_alert(strerror(errno));
|
||||||
app_destroy(app, 2);
|
/* TODO: ask new server address */
|
||||||
|
// app_destroy(app, 2);
|
||||||
|
app->query_args->state = S_ASK_SEVER_IP;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
app->params->is_connected = TRUE;
|
app->params->is_connected = TRUE;
|
||||||
|
app->query_args->sd = app->params->sd;
|
||||||
app_draw_bars(app);
|
app_draw_bars(app);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_params(params_t *params) {
|
void init_params(params_t *params) {
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <widget.h>
|
#include <widget.h>
|
||||||
|
|
||||||
void connect_to_server(app_t *params);
|
bool connect_to_server(app_t *params);
|
||||||
void init_params(params_t *restrict);
|
void init_params(params_t *restrict);
|
||||||
void clear_params(params_t *params);
|
void clear_params(params_t *params);
|
||||||
void get_ip_port(params_t *params, char *ip, char *port);
|
void get_ip_port(params_t *params, char *ip, char *port);
|
||||||
|
|||||||
@@ -55,10 +55,8 @@ int main(int argc, char **argv) {
|
|||||||
app->query_args->state = S_ASK_SEVER_IP;
|
app->query_args->state = S_ASK_SEVER_IP;
|
||||||
} else {
|
} else {
|
||||||
connect_to_server(app);
|
connect_to_server(app);
|
||||||
app->query_args->state = S_WAIT_SERVER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app->query_args->sd = app->params->sd;
|
|
||||||
app->query_args->main_ui = &(app->main_ui);
|
app->query_args->main_ui = &(app->main_ui);
|
||||||
|
|
||||||
query_loop(app);
|
query_loop(app);
|
||||||
|
|||||||
@@ -25,9 +25,10 @@ void asa_modal_dialogue_callback(w_cb_args_t *args) {
|
|||||||
switch (d_args.resp_data.val.val.num) {
|
switch (d_args.resp_data.val.val.num) {
|
||||||
case 1:
|
case 1:
|
||||||
get_ip_port(app->params, in_ip->value, in_port->value);
|
get_ip_port(app->params, in_ip->value, in_port->value);
|
||||||
connect_to_server(app);
|
if (connect_to_server(app)) {
|
||||||
d->needs_destroy = true;
|
d->needs_destroy = true;
|
||||||
app->query_args->state = S_WAIT_SERVER;
|
app->query_args->state = S_WAIT_SERVER;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
app_destroy(app, 0);
|
app_destroy(app, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user