Commit c949a338b81b7da27090a2f655e7ec5072888040
1 parent
caa2ecc7
Exists in
master
and in
5 other branches
Incluindo toggle para ativar/desativar a utilizacao do keep-alive da rede
Showing
6 changed files
with
44 additions
and
15 deletions
Show diff stats
src/include/lib3270.h
| ... | ... | @@ -116,6 +116,7 @@ |
| 116 | 116 | LIB3270_TOGGLE_BEEP, /**< Beep on errors */ |
| 117 | 117 | LIB3270_TOGGLE_VIEW_FIELD, /**< View Field attribute */ |
| 118 | 118 | LIB3270_TOGGLE_ALTSCREEN, /**< auto resize on altscreen */ |
| 119 | + LIB3270_TOGGLE_KEEP_ALIVE, /**< Enable network keep-alive with SO_KEEPALIVE */ | |
| 119 | 120 | |
| 120 | 121 | // LIB3270_TOGGLE_ALT_CURSOR, |
| 121 | 122 | // LIB3270_TOGGLE_AID_WAIT, | ... | ... |
src/lib3270/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 | { | ... | ... |
src/lib3270/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++) | ... | ... |
src/plugins/rx3270/rexx_methods.cc
| ... | ... | @@ -328,7 +328,8 @@ RexxMethod3(int, rx3270_method_set_option, CSELF, sessionPtr, CSTRING, name, int |
| 328 | 328 | { "kpalternative", LIB3270_TOGGLE_KP_ALTERNATIVE }, |
| 329 | 329 | { "beep", LIB3270_TOGGLE_BEEP }, |
| 330 | 330 | { "fieldattr", LIB3270_TOGGLE_VIEW_FIELD }, |
| 331 | - { "altscreen", LIB3270_TOGGLE_ALTSCREEN } | |
| 331 | + { "altscreen", LIB3270_TOGGLE_ALTSCREEN }, | |
| 332 | + { "keepalive", LIB3270_TOGGLE_KEEP_ALIVE }, | |
| 332 | 333 | }; |
| 333 | 334 | |
| 334 | 335 | session *hSession = (session *) sessionPtr; | ... | ... |
src/pw3270/common/config.c
| ... | ... | @@ -439,7 +439,7 @@ void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val) |
| 439 | 439 | DWORD disp; |
| 440 | 440 | gchar * path = g_strdup_printf("%s\\%s\\%s",registry_path,g_get_application_name(),group); |
| 441 | 441 | |
| 442 | - trace("Creating key %s",path); | |
| 442 | +// trace("Creating key %s",path); | |
| 443 | 443 | if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS) |
| 444 | 444 | { |
| 445 | 445 | DWORD value = val ? 1 : 0; | ... | ... |
ui/00default.xml
| ... | ... | @@ -131,6 +131,7 @@ |
| 131 | 131 | <menuitem action='toggle' id='SmartPaste' label='Smart paste' /> |
| 132 | 132 | <menuitem action='toggle' id='Beep' label='Alert sound' /> |
| 133 | 133 | <menuitem action='toggle' id='KPAlternative' label='Use +/- for field navigation' /> |
| 134 | + <menuitem action='toggle' id='keepalive' label='Network keep alive' /> | |
| 134 | 135 | </menu> |
| 135 | 136 | |
| 136 | 137 | <!--- Special action - InputMethod menu will be populated with Gtk input_method menu items ---> | ... | ... |