Commit 01859ebfbfbdf03c42f983e6e172d0221d8283be
1 parent
7d4f3364
Exists in
master
and in
1 other branch
Implementing lib3270_wait_for_connected, cleaning up code, fixing
warning.
Showing
4 changed files
with
48 additions
and
41 deletions
Show diff stats
src/core/ft/ft.c
... | ... | @@ -474,7 +474,7 @@ LIB3270_EXPORT int lib3270_ft_start(H3270 *hSession) { |
474 | 474 | // Erase the line and enter the command. |
475 | 475 | flen = kybd_prime(ft->host); |
476 | 476 | if (!flen || flen < strlen(buffer) - 1) { |
477 | - lib3270_write_log(ft->host, "ft", "Unable to send command \"%s\" (flen=%d szBuffer=%ld)",buffer,flen,strlen(buffer)); | |
477 | + lib3270_write_log(ft->host, "ft", "Unable to send command \"%s\" (flen=%d szBuffer=%u)",buffer,flen,(unsigned int) strlen(buffer)); | |
478 | 478 | ft_failed(ft,_( "Unable to send file-transfer request" )); |
479 | 479 | return errno = EINVAL; |
480 | 480 | } | ... | ... |
src/core/linux/connect.c
... | ... | @@ -373,46 +373,6 @@ int net_reconnect(H3270 *hSession, int seconds) { |
373 | 373 | lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); |
374 | 374 | return errno = rc; |
375 | 375 | } |
376 | - | |
377 | - /* | |
378 | - time_t end = time(0)+seconds; | |
379 | - | |
380 | - while(time(0) < end) | |
381 | - { | |
382 | - lib3270_main_iterate(hSession,1); | |
383 | - | |
384 | - switch(hSession->connection.state) | |
385 | - { | |
386 | - case LIB3270_PENDING: | |
387 | - case LIB3270_CONNECTED_INITIAL: | |
388 | - case LIB3270_CONNECTED_ANSI: | |
389 | - case LIB3270_CONNECTED_3270: | |
390 | - case LIB3270_CONNECTED_INITIAL_E: | |
391 | - case LIB3270_CONNECTED_NVT: | |
392 | - case LIB3270_CONNECTED_SSCP: | |
393 | - case LIB3270_CONNECTING: | |
394 | - break; | |
395 | - | |
396 | - case LIB3270_NOT_CONNECTED: | |
397 | - return errno = ENOTCONN; | |
398 | - | |
399 | - case LIB3270_CONNECTED_TN3270E: | |
400 | - if(!hSession->starting) | |
401 | - return 0; | |
402 | - break; | |
403 | - | |
404 | - default: | |
405 | - lib3270_write_log(hSession,"connect", "%s: State changed to unexpected state %d",__FUNCTION__,hSession->connection.state); | |
406 | - return errno = EINVAL; | |
407 | - } | |
408 | - | |
409 | - } | |
410 | - | |
411 | - lib3270_disconnect(hSession); | |
412 | - lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); | |
413 | - | |
414 | - return errno = ETIMEDOUT; | |
415 | - */ | |
416 | 376 | } |
417 | 377 | |
418 | 378 | return 0; | ... | ... |
src/core/wait.c
... | ... | @@ -46,6 +46,7 @@ LIB3270_EXPORT int lib3270_wait_for_update(H3270 GNUC_UNUSED(*hSession), int GNU |
46 | 46 | } |
47 | 47 | |
48 | 48 | LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { |
49 | + | |
49 | 50 | debug("%s",__FUNCTION__); |
50 | 51 | debug("Session lock state is %d",lib3270_get_lock_status(hSession)); |
51 | 52 | |
... | ... | @@ -87,6 +88,7 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) { |
87 | 88 | } |
88 | 89 | |
89 | 90 | int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds) { |
91 | + | |
90 | 92 | FAIL_IF_NOT_ONLINE(hSession); |
91 | 93 | |
92 | 94 | int rc = 0; |
... | ... | @@ -180,6 +182,37 @@ LIB3270_EXPORT int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, |
180 | 182 | return lib3270_wait_for_string_at_address(hSession,baddr,key,seconds); |
181 | 183 | } |
182 | 184 | |
185 | +LIB3270_EXPORT int lib3270_wait_for_connected(H3270 *hSession, int seconds) { | |
186 | + | |
187 | + int rc = -1; | |
188 | + int timeout = 0; | |
189 | + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout); | |
190 | + | |
191 | + while(rc == -1) { | |
192 | + if(timeout) { | |
193 | + // Timeout! The timer was destroyed. | |
194 | + return errno = ETIMEDOUT; | |
195 | + } | |
196 | + | |
197 | + if(hSession->connection.state == LIB3270_NOT_CONNECTED) { | |
198 | + rc = ENOTCONN; | |
199 | + break; | |
200 | + } | |
201 | + | |
202 | + if(!hSession->starting && hSession->connection.state >= (int)LIB3270_CONNECTED_INITIAL) { | |
203 | + rc = 0; | |
204 | + break; | |
205 | + } | |
206 | + | |
207 | + lib3270_main_iterate(hSession,1); | |
208 | + | |
209 | + } | |
210 | + RemoveTimer(hSession,timer); | |
211 | + | |
212 | + return errno = rc; | |
213 | +} | |
214 | + | |
215 | + | |
183 | 216 | LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstate, int seconds) { |
184 | 217 | |
185 | 218 | int rc = -1; | ... | ... |
src/include/lib3270.h
... | ... | @@ -1061,6 +1061,20 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds); |
1061 | 1061 | LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstate, int seconds); |
1062 | 1062 | |
1063 | 1063 | /** |
1064 | + * @brief Wait "N" seconds for connected state. | |
1065 | + * | |
1066 | + * @param seconds Number of seconds to wait. | |
1067 | + * | |
1068 | + * @return 0 if ok, errno code if not. | |
1069 | + * | |
1070 | + * @retval ETIMEDOUT Timeout waiting. | |
1071 | + * @retval ENOTCONN Not connected to host. | |
1072 | + * @retval 0 Session is online and in required state. | |
1073 | + * | |
1074 | + */ | |
1075 | +LIB3270_EXPORT int lib3270_wait_for_connected(H3270 *hSession, int seconds); | |
1076 | + | |
1077 | +/** | |
1064 | 1078 | * "beep" to notify user. |
1065 | 1079 | * |
1066 | 1080 | * If available play a sound signal do alert user. | ... | ... |