Commit 62dff8b4750ca9f993c642d0af2dae6c349a3426
1 parent
faf92292
Exists in
master
and in
3 other branches
Incluindo toggle para ativar/desativar a utilizacao do keep-alive da rede
Showing
2 changed files
with
39 additions
and
13 deletions
Show diff stats
telnet.c
... | ... | @@ -488,6 +488,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo |
488 | 488 | int passthru_len = 0; |
489 | 489 | unsigned short passthru_port = 0; |
490 | 490 | int on = 1; |
491 | + int optval; | |
491 | 492 | char errmsg[1024]; |
492 | 493 | int rc; |
493 | 494 | #if defined(OMTU) /*[*/ |
... | ... | @@ -630,12 +631,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo |
630 | 631 | close_fail; |
631 | 632 | } |
632 | 633 | |
633 | - if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0) | |
634 | - { | |
635 | - popup_a_sockerr(session, N_( "setsockopt(%s)" ), "SO_KEEPALIVE"); | |
636 | - close_fail; | |
637 | - } | |
638 | - | |
639 | 634 | #if defined(OMTU) |
640 | 635 | if (setsockopt(session->sock, SOL_SOCKET, SO_SNDBUF, (char *)&mtu,sizeof(mtu)) < 0) |
641 | 636 | { |
... | ... | @@ -666,8 +661,22 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo |
666 | 661 | if(!rc) |
667 | 662 | { |
668 | 663 | trace_dsn(session,"Connected.\n"); |
664 | + | |
665 | + optval = lib3270_get_toggle(session,LIB3270_TOGGLE_KEEP_ALIVE) ? 1 : 0; | |
666 | + | |
667 | + if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) | |
668 | + { | |
669 | + popup_a_sockerr(session, N_( "Can´t %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); | |
670 | + close_fail; | |
671 | + } | |
672 | + else | |
673 | + { | |
674 | + trace_dsn(session,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); | |
675 | + } | |
676 | + | |
669 | 677 | if(net_connected(session)) |
670 | 678 | return -1; |
679 | + | |
671 | 680 | } |
672 | 681 | else |
673 | 682 | { | ... | ... |
toggles.c
... | ... | @@ -51,8 +51,6 @@ |
51 | 51 | #include "togglesc.h" |
52 | 52 | #include "api.h" |
53 | 53 | |
54 | - | |
55 | - | |
56 | 54 | static const char *toggle_names[LIB3270_TOGGLE_COUNT] = |
57 | 55 | { |
58 | 56 | "monocase", |
... | ... | @@ -79,6 +77,7 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] = |
79 | 77 | "beep", /**< Beep on errors */ |
80 | 78 | "fieldattr", /**< View Field attribute */ |
81 | 79 | "altscreen", /**< auto resize on altscreen */ |
80 | + "keepalive", /**< Enable network keep-alive with SO_KEEPALIVE */ | |
82 | 81 | |
83 | 82 | |
84 | 83 | }; |
... | ... | @@ -158,10 +157,29 @@ static void toggle_redraw(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGG |
158 | 157 | /* |
159 | 158 | * No-op toggle. |
160 | 159 | */ |
161 | -static void toggle_nop(H3270 *session, struct lib3270_toggle *t unused, LIB3270_TOGGLE_TYPE tt unused) | |
160 | +static void toggle_nop(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE tt unused) | |
162 | 161 | { |
163 | 162 | } |
164 | 163 | |
164 | +static void toggle_keepalive(H3270 *session, struct lib3270_toggle *t unused, LIB3270_TOGGLE_TYPE tt unused) | |
165 | +{ | |
166 | + if(session->sock > 0) | |
167 | + { | |
168 | + // Update keep-alive option | |
169 | + int optval = t->value ? 1 : 0; | |
170 | + | |
171 | + if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) | |
172 | + { | |
173 | + popup_a_sockerr(session, N_( "Can´t %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); | |
174 | + } | |
175 | + else | |
176 | + { | |
177 | + trace_dsn(session,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); | |
178 | + } | |
179 | + | |
180 | + } | |
181 | +} | |
182 | + | |
165 | 183 | /* |
166 | 184 | * Called from system initialization code to handle initial toggle settings. |
167 | 185 | */ |
... | ... | @@ -176,10 +194,8 @@ void initialize_toggles(H3270 *session) |
176 | 194 | session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw; |
177 | 195 | session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw; |
178 | 196 | session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen; |
179 | - | |
180 | -#if defined(X3270_ANSI) | |
181 | - session->toggle[LIB3270_TOGGLE_LINE_WRAP].upcall = toggle_lineWrap; | |
182 | -#endif | |
197 | + session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen; | |
198 | + session->toggle[LIB3270_TOGGLE_KEEP_ALIVE].upcall = toggle_keepalive; | |
183 | 199 | |
184 | 200 | static const LIB3270_TOGGLE active_by_default[] = |
185 | 201 | { |
... | ... | @@ -187,6 +203,7 @@ void initialize_toggles(H3270 *session) |
187 | 203 | LIB3270_TOGGLE_CURSOR_POS, |
188 | 204 | LIB3270_TOGGLE_BEEP, |
189 | 205 | LIB3270_TOGGLE_ALTSCREEN, |
206 | + LIB3270_TOGGLE_KEEP_ALIVE | |
190 | 207 | }; |
191 | 208 | |
192 | 209 | for(f=0;f< (sizeof(active_by_default)/sizeof(active_by_default[0])); f++) | ... | ... |