Commit 93053fe45f4810c9c6cfb00bf2b049e49ca44289

Authored by Perry Werneck
1 parent aba431be

Refactoring and centralizing auto-reconnect feature.

src/core/connect.c
... ... @@ -83,19 +83,15 @@
83 83  
84 84 LIB3270_POPUP popup = {
85 85 .name = "CantConnect",
86   - .title = _( "Connection failed" ),
  86 +// .title = _( "Connection failed" ),
87 87 .type = LIB3270_NOTIFY_INFO,
88 88 .summary = summary,
89 89 .body = message,
90 90 .label = _("Try again")
91 91 };
92 92  
93   -// if(hSession->cbk.popup_show(hSession,&popup,lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT) && !hSession->auto_reconnect_inprogress) == 0) {
94   - if(hSession->cbk.popup_show(hSession,&popup,!hSession->auto_reconnect_inprogress) == 0) {
95   - // Schedule an automatic reconnection.
96   - hSession->auto_reconnect_inprogress = 1;
97   - (void) AddTimer(1000, hSession, lib3270_check_for_auto_reconnect);
98   - }
  93 + if(hSession->cbk.popup_show(hSession,&popup,!hSession->auto_reconnect_inprogress) == 0)
  94 + lib3270_activate_auto_reconnect(hSession,1000);
99 95  
100 96 }
101 97  
... ...
src/core/host.c
... ... @@ -64,7 +64,7 @@
64 64 /**
65 65 * @brief Called from timer to attempt an automatic reconnection.
66 66 */
67   -int lib3270_check_for_auto_reconnect(H3270 *hSession)
  67 +static int check_for_auto_reconnect(H3270 *hSession)
68 68 {
69 69  
70 70 if(hSession->auto_reconnect_inprogress)
... ... @@ -78,6 +78,27 @@ int lib3270_check_for_auto_reconnect(H3270 *hSession)
78 78 return 0;
79 79 }
80 80  
  81 +/**
  82 + * @brief Activate auto-reconnect timer.
  83 + *
  84 + * @param hSession TN3270 Session handle.
  85 + * @param msec Time to reconnect.
  86 + *
  87 + * @return 0 if ok or error code if not.
  88 + *
  89 + * @retval EBUSY Auto reconnect is already active.
  90 + */
  91 +int lib3270_activate_auto_reconnect(H3270 *hSession, unsigned long msec)
  92 +{
  93 + if(hSession->auto_reconnect_inprogress)
  94 + return EBUSY;
  95 +
  96 + hSession->auto_reconnect_inprogress = 1;
  97 + (void) AddTimer(msec, hSession, check_for_auto_reconnect);
  98 +
  99 + return 0;
  100 +}
  101 +
81 102 LIB3270_EXPORT int lib3270_disconnect(H3270 *h)
82 103 {
83 104 return host_disconnect(h,0);
... ... @@ -95,12 +116,8 @@ int host_disconnect(H3270 *hSession, int failed)
95 116  
96 117 trace("Disconnected (Failed: %d Reconnect: %d in_progress: %d)",failed,lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT),hSession->auto_reconnect_inprogress);
97 118  
98   - if(failed && lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT) && !hSession->auto_reconnect_inprogress)
99   - {
100   - /* Schedule an automatic reconnection. */
101   - hSession->auto_reconnect_inprogress = 1;
102   - (void) AddTimer(failed ? RECONNECT_ERR_MS : RECONNECT_MS, hSession, lib3270_check_for_auto_reconnect);
103   - }
  119 + if(failed && lib3270_get_toggle(hSession,LIB3270_TOGGLE_RECONNECT))
  120 + lib3270_activate_auto_reconnect(hSession,failed ? RECONNECT_ERR_MS : RECONNECT_MS);
104 121  
105 122 /*
106 123 * Remember a disconnect from ANSI mode, to keep screen tracing
... ...
src/core/telnet.c
... ... @@ -2223,12 +2223,11 @@ static const char * cmd(int c)
2223 2223 return nnn(c);
2224 2224 }
2225 2225  
2226   -/*
2227   - * opt
2228   - * Expands a TELNET option into a character string.
  2226 +/***
  2227 + *
  2228 + * @brief Expands a TELNET option into a character string.
2229 2229 */
2230   -static const char *
2231   -opt(unsigned char c)
  2230 +static const char * opt(unsigned char c)
2232 2231 {
2233 2232 if (TELOPT_OK(c))
2234 2233 return TELOPT(c);
... ...
src/include/internals.h
... ... @@ -753,11 +753,6 @@ LIB3270_INTERNAL int do_select(H3270 *h, unsigned int start, unsigned int end,
753 753  
754 754 LIB3270_INTERNAL void connection_failed(H3270 *hSession, const char *message);
755 755  
756   -/**
757   - * @brief Called from timer to attempt an automatic reconnection.
758   - */
759   -LIB3270_INTERNAL int lib3270_check_for_auto_reconnect(H3270 *hSession);
760   -
761 756 #if defined(DEBUG)
762 757 #define CHECK_SESSION_HANDLE(x) check_session_handle(&x,__FUNCTION__);
763 758 LIB3270_INTERNAL void check_session_handle(H3270 **hSession, const char *fname);
... ... @@ -766,6 +761,18 @@ LIB3270_INTERNAL int lib3270_check_for_auto_reconnect(H3270 *hSession);
766 761 LIB3270_INTERNAL void check_session_handle(H3270 **hSession);
767 762 #endif // DEBUG
768 763  
  764 +/**
  765 + * @brief Activate auto-reconnect timer.
  766 + *
  767 + * @param hSession TN3270 Session handle.
  768 + * @param msec Time to reconnect.
  769 + *
  770 + * @return 0 if ok or error code if not.
  771 + *
  772 + * @retval EBUSY Auto reconnect is already active.
  773 + */
  774 +LIB3270_INTERNAL int lib3270_activate_auto_reconnect(H3270 *hSession, unsigned long msec);
  775 +
769 776 LIB3270_INTERNAL int check_online_session(const H3270 *hSession);
770 777 LIB3270_INTERNAL int check_offline_session(const H3270 *hSession);
771 778  
... ...
src/ssl/state.c
... ... @@ -78,6 +78,7 @@ void set_ssl_state(H3270 *hSession, LIB3270_SSL_STATE state)
78 78  
79 79 hSession->ssl.state = state;
80 80 trace_dsn(hSession,"SSL state changes to %d\n",(int) state);
  81 + debug("SSL state changes to %d\n",(int) state);
81 82  
82 83 hSession->cbk.update_ssl(hSession,hSession->ssl.state);
83 84 }
... ...