Commit c949a338b81b7da27090a2f655e7ec5072888040

Authored by perry.werneck@gmail.com
1 parent caa2ecc7

Incluindo toggle para ativar/desativar a utilizacao do keep-alive da rede

src/include/lib3270.h
@@ -116,6 +116,7 @@ @@ -116,6 +116,7 @@
116 LIB3270_TOGGLE_BEEP, /**< Beep on errors */ 116 LIB3270_TOGGLE_BEEP, /**< Beep on errors */
117 LIB3270_TOGGLE_VIEW_FIELD, /**< View Field attribute */ 117 LIB3270_TOGGLE_VIEW_FIELD, /**< View Field attribute */
118 LIB3270_TOGGLE_ALTSCREEN, /**< auto resize on altscreen */ 118 LIB3270_TOGGLE_ALTSCREEN, /**< auto resize on altscreen */
  119 + LIB3270_TOGGLE_KEEP_ALIVE, /**< Enable network keep-alive with SO_KEEPALIVE */
119 120
120 // LIB3270_TOGGLE_ALT_CURSOR, 121 // LIB3270_TOGGLE_ALT_CURSOR,
121 // LIB3270_TOGGLE_AID_WAIT, 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,6 +488,7 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
488 int passthru_len = 0; 488 int passthru_len = 0;
489 unsigned short passthru_port = 0; 489 unsigned short passthru_port = 0;
490 int on = 1; 490 int on = 1;
  491 + int optval;
491 char errmsg[1024]; 492 char errmsg[1024];
492 int rc; 493 int rc;
493 #if defined(OMTU) /*[*/ 494 #if defined(OMTU) /*[*/
@@ -630,12 +631,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -630,12 +631,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
630 close_fail; 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 #if defined(OMTU) 634 #if defined(OMTU)
640 if (setsockopt(session->sock, SOL_SOCKET, SO_SNDBUF, (char *)&mtu,sizeof(mtu)) < 0) 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,8 +661,22 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
666 if(!rc) 661 if(!rc)
667 { 662 {
668 trace_dsn(session,"Connected.\n"); 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 if(net_connected(session)) 677 if(net_connected(session))
670 return -1; 678 return -1;
  679 +
671 } 680 }
672 else 681 else
673 { 682 {
src/lib3270/toggles.c
@@ -51,8 +51,6 @@ @@ -51,8 +51,6 @@
51 #include "togglesc.h" 51 #include "togglesc.h"
52 #include "api.h" 52 #include "api.h"
53 53
54 -  
55 -  
56 static const char *toggle_names[LIB3270_TOGGLE_COUNT] = 54 static const char *toggle_names[LIB3270_TOGGLE_COUNT] =
57 { 55 {
58 "monocase", 56 "monocase",
@@ -79,6 +77,7 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] = @@ -79,6 +77,7 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] =
79 "beep", /**< Beep on errors */ 77 "beep", /**< Beep on errors */
80 "fieldattr", /**< View Field attribute */ 78 "fieldattr", /**< View Field attribute */
81 "altscreen", /**< auto resize on altscreen */ 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,10 +157,29 @@ static void toggle_redraw(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGG
158 /* 157 /*
159 * No-op toggle. 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 * Called from system initialization code to handle initial toggle settings. 184 * Called from system initialization code to handle initial toggle settings.
167 */ 185 */
@@ -176,10 +194,8 @@ void initialize_toggles(H3270 *session) @@ -176,10 +194,8 @@ void initialize_toggles(H3270 *session)
176 session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw; 194 session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw;
177 session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw; 195 session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw;
178 session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen; 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 static const LIB3270_TOGGLE active_by_default[] = 200 static const LIB3270_TOGGLE active_by_default[] =
185 { 201 {
@@ -187,6 +203,7 @@ void initialize_toggles(H3270 *session) @@ -187,6 +203,7 @@ void initialize_toggles(H3270 *session)
187 LIB3270_TOGGLE_CURSOR_POS, 203 LIB3270_TOGGLE_CURSOR_POS,
188 LIB3270_TOGGLE_BEEP, 204 LIB3270_TOGGLE_BEEP,
189 LIB3270_TOGGLE_ALTSCREEN, 205 LIB3270_TOGGLE_ALTSCREEN,
  206 + LIB3270_TOGGLE_KEEP_ALIVE
190 }; 207 };
191 208
192 for(f=0;f< (sizeof(active_by_default)/sizeof(active_by_default[0])); f++) 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,7 +328,8 @@ RexxMethod3(int, rx3270_method_set_option, CSELF, sessionPtr, CSTRING, name, int
328 { "kpalternative", LIB3270_TOGGLE_KP_ALTERNATIVE }, 328 { "kpalternative", LIB3270_TOGGLE_KP_ALTERNATIVE },
329 { "beep", LIB3270_TOGGLE_BEEP }, 329 { "beep", LIB3270_TOGGLE_BEEP },
330 { "fieldattr", LIB3270_TOGGLE_VIEW_FIELD }, 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 session *hSession = (session *) sessionPtr; 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,7 +439,7 @@ void set_boolean_to_config(const gchar *group, const gchar *key, gboolean val)
439 DWORD disp; 439 DWORD disp;
440 gchar * path = g_strdup_printf("%s\\%s\\%s",registry_path,g_get_application_name(),group); 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 if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS) 443 if(RegCreateKeyEx(HKEY_CURRENT_USER,path,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS)
444 { 444 {
445 DWORD value = val ? 1 : 0; 445 DWORD value = val ? 1 : 0;
ui/00default.xml
@@ -131,6 +131,7 @@ @@ -131,6 +131,7 @@
131 <menuitem action='toggle' id='SmartPaste' label='Smart paste' /> 131 <menuitem action='toggle' id='SmartPaste' label='Smart paste' />
132 <menuitem action='toggle' id='Beep' label='Alert sound' /> 132 <menuitem action='toggle' id='Beep' label='Alert sound' />
133 <menuitem action='toggle' id='KPAlternative' label='Use +/- for field navigation' /> 133 <menuitem action='toggle' id='KPAlternative' label='Use +/- for field navigation' />
  134 + <menuitem action='toggle' id='keepalive' label='Network keep alive' />
134 </menu> 135 </menu>
135 136
136 <!--- Special action - InputMethod menu will be populated with Gtk input_method menu items ---> 137 <!--- Special action - InputMethod menu will be populated with Gtk input_method menu items --->