Commit 91a01b450ce761ba6f8b9ba59a74d1029297d237
1 parent
97de2366
Exists in
master
and in
3 other branches
Adjustments for performance.
Showing
8 changed files
with
105 additions
and
10 deletions
Show diff stats
src/core/iocalls.c
| ... | ... | @@ -325,9 +325,12 @@ static void internal_ring_bell(H3270 GNUC_UNUSED(*session)) |
| 325 | 325 | |
| 326 | 326 | void * AddTimer(unsigned long interval_ms, H3270 *session, int (*proc)(H3270 *session, void *userdata), void *userdata) |
| 327 | 327 | { |
| 328 | - void *timer; | |
| 329 | - CHECK_SESSION_HANDLE(session); | |
| 330 | - timer = add_timer(session,interval_ms,proc,userdata); | |
| 328 | + void *timer = add_timer( | |
| 329 | + session, | |
| 330 | + interval_ms ? interval_ms : 100, // Prevents a zero-value timer. | |
| 331 | + proc, | |
| 332 | + userdata | |
| 333 | + ); | |
| 331 | 334 | trace("Timeout %p created with %ld ms",timer,interval_ms); |
| 332 | 335 | return timer; |
| 333 | 336 | } | ... | ... |
src/core/linux/connect.c
| ... | ... | @@ -245,6 +245,15 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG |
| 245 | 245 | |
| 246 | 246 | if(seconds) |
| 247 | 247 | { |
| 248 | + int rc = lib3270_wait_for_cstate(hSession,LIB3270_CONNECTED_TN3270E,seconds); | |
| 249 | + if(rc) | |
| 250 | + { | |
| 251 | + lib3270_disconnect(hSession); | |
| 252 | + lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); | |
| 253 | + return errno = rc; | |
| 254 | + } | |
| 255 | + | |
| 256 | + /* | |
| 248 | 257 | time_t end = time(0)+seconds; |
| 249 | 258 | |
| 250 | 259 | while(time(0) < end) |
| ... | ... | @@ -282,6 +291,7 @@ static void net_connected(H3270 *hSession, int GNUC_UNUSED(fd), LIB3270_IO_FLAG |
| 282 | 291 | lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); |
| 283 | 292 | |
| 284 | 293 | return errno = ETIMEDOUT; |
| 294 | + */ | |
| 285 | 295 | } |
| 286 | 296 | |
| 287 | 297 | return 0; | ... | ... |
src/core/properties/boolean.c
| ... | ... | @@ -45,10 +45,13 @@ |
| 45 | 45 | return hSession->starting != 0; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - void lib3270_disable_crl_download(H3270 *hSession) | |
| 48 | + int lib3270_disable_crl_download(H3270 *hSession, int enabled) | |
| 49 | 49 | { |
| 50 | 50 | #ifdef SSL_ENABLE_CRL_CHECK |
| 51 | - hSession->ssl.crl.download = 0; | |
| 51 | + hSession->ssl.crl.download = enabled ? 1 : 0; | |
| 52 | + return 0; | |
| 53 | +#else | |
| 54 | + return errno = ENOTSUP; | |
| 52 | 55 | #endif // SSL_ENABLE_CRL_CHECK |
| 53 | 56 | } |
| 54 | 57 | ... | ... |
src/core/wait.c
| ... | ... | @@ -84,6 +84,7 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds) |
| 84 | 84 | break; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | + debug("%s: Waiting",__FUNCTION__); | |
| 87 | 88 | lib3270_main_iterate(hSession,1); |
| 88 | 89 | } |
| 89 | 90 | RemoveTimer(hSession,timer); |
| ... | ... | @@ -189,7 +190,7 @@ int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *k |
| 189 | 190 | |
| 190 | 191 | } |
| 191 | 192 | |
| 192 | -int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, unsigned int col, const char *key, int seconds) | |
| 193 | +LIB3270_EXPORT int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, unsigned int col, const char *key, int seconds) | |
| 193 | 194 | { |
| 194 | 195 | int baddr = lib3270_translate_to_address(hSession,row,col); |
| 195 | 196 | if(baddr < 0) |
| ... | ... | @@ -197,3 +198,37 @@ int lib3270_wait_for_string_at(H3270 *hSession, unsigned int row, unsigned int c |
| 197 | 198 | |
| 198 | 199 | return lib3270_wait_for_string_at_address(hSession,baddr,key,seconds); |
| 199 | 200 | } |
| 201 | + | |
| 202 | +LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstate, int seconds) | |
| 203 | +{ | |
| 204 | + | |
| 205 | + int rc = -1; | |
| 206 | + int timeout = 0; | |
| 207 | + void * timer = AddTimer(seconds * 1000, hSession, timer_expired, &timeout); | |
| 208 | + | |
| 209 | + while(rc == -1) | |
| 210 | + { | |
| 211 | + if(timeout) { | |
| 212 | + // Timeout! The timer was destroyed. | |
| 213 | + return errno = ETIMEDOUT; | |
| 214 | + } | |
| 215 | + | |
| 216 | + if(hSession->connection.state == LIB3270_NOT_CONNECTED) | |
| 217 | + { | |
| 218 | + rc = ENOTCONN; | |
| 219 | + break; | |
| 220 | + } | |
| 221 | + | |
| 222 | + if(!hSession->starting && hSession->connection.state == cstate) | |
| 223 | + { | |
| 224 | + rc = 0; | |
| 225 | + break; | |
| 226 | + } | |
| 227 | + | |
| 228 | + lib3270_main_iterate(hSession,1); | |
| 229 | + | |
| 230 | + } | |
| 231 | + RemoveTimer(hSession,timer); | |
| 232 | + | |
| 233 | + return errno = rc; | |
| 234 | +} | ... | ... |
src/core/windows/connect.c
| ... | ... | @@ -347,6 +347,18 @@ int net_reconnect(H3270 *hSession, int seconds) |
| 347 | 347 | |
| 348 | 348 | if(seconds) |
| 349 | 349 | { |
| 350 | + int rc = lib3270_wait_for_cstate(hSession,LIB3270_CONNECTED_TN3270E,seconds); | |
| 351 | + if(rc) | |
| 352 | + { | |
| 353 | + lib3270_disconnect(hSession); | |
| 354 | + lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(rc)); | |
| 355 | + return errno = rc; | |
| 356 | + } | |
| 357 | + } | |
| 358 | + | |
| 359 | + /* | |
| 360 | + if(seconds) | |
| 361 | + { | |
| 350 | 362 | time_t end = time(0)+seconds; |
| 351 | 363 | |
| 352 | 364 | while(time(0) < end) |
| ... | ... | @@ -382,6 +394,7 @@ int net_reconnect(H3270 *hSession, int seconds) |
| 382 | 394 | lib3270_write_log(hSession,"connect", "%s: %s",__FUNCTION__,strerror(ETIMEDOUT)); |
| 383 | 395 | return errno = ETIMEDOUT; |
| 384 | 396 | } |
| 397 | + */ | |
| 385 | 398 | |
| 386 | 399 | return 0; |
| 387 | 400 | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -1111,7 +1111,7 @@ |
| 1111 | 1111 | LIB3270_EXPORT int lib3270_wait_for_update(H3270 *hSession, int seconds); |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
| 1114 | - * Wait "N" seconds for "ready" state. | |
| 1114 | + * @brief Wait "N" seconds for "ready" state. | |
| 1115 | 1115 | * |
| 1116 | 1116 | * @param seconds Number of seconds to wait. |
| 1117 | 1117 | * |
| ... | ... | @@ -1121,6 +1121,20 @@ |
| 1121 | 1121 | LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds); |
| 1122 | 1122 | |
| 1123 | 1123 | /** |
| 1124 | + * @brief Wait "N" seconds for online state. | |
| 1125 | + * | |
| 1126 | + * @param seconds Number of seconds to wait. | |
| 1127 | + * | |
| 1128 | + * @return 0 if ok, errno code if not. | |
| 1129 | + * | |
| 1130 | + * @retval ETIMEDOUT Timeout waiting. | |
| 1131 | + * @retval ENOTCONN Not connected to host. | |
| 1132 | + * @retval 0 Session is online and in required state. | |
| 1133 | + * | |
| 1134 | + */ | |
| 1135 | + LIB3270_EXPORT int lib3270_wait_for_cstate(H3270 *hSession, LIB3270_CSTATE cstate, int seconds); | |
| 1136 | + | |
| 1137 | + /** | |
| 1124 | 1138 | * "beep" to notify user. |
| 1125 | 1139 | * |
| 1126 | 1140 | * If available play a sound signal do alert user. | ... | ... |
src/include/lib3270/properties.h
| ... | ... | @@ -216,9 +216,14 @@ |
| 216 | 216 | * @brief Disable automatic download of the CRL. |
| 217 | 217 | * |
| 218 | 218 | * @param hSession Session handle. |
| 219 | + * @param Value Non zero to enable automatic download of CRL. | |
| 219 | 220 | * |
| 221 | + * @return 0 if ok or error code if not (Sets errno). | |
| 222 | + * | |
| 223 | + * @retval 0 Download of the CRL was disabled. | |
| 224 | + * @retval ENOTSUP No SSL/TLS support. | |
| 220 | 225 | */ |
| 221 | - LIB3270_EXPORT void lib3270_disable_crl_download(H3270 *hSession); | |
| 226 | + LIB3270_EXPORT int lib3270_ssl_set_crl_download(H3270 *hSession, int enabled); | |
| 222 | 227 | |
| 223 | 228 | /** |
| 224 | 229 | * @brief Get lib3270 version info. | ... | ... |
src/testprogram/testprogram.c
| ... | ... | @@ -154,13 +154,25 @@ int main(int argc, char *argv[]) |
| 154 | 154 | |
| 155 | 155 | const void * online_listener = lib3270_register_action_group_listener(h,LIB3270_ACTION_GROUP_ONLINE,online_group_state_changed,NULL); |
| 156 | 156 | |
| 157 | - rc = lib3270_reconnect(h,120); | |
| 157 | + rc = lib3270_reconnect(h,0); | |
| 158 | 158 | printf("\n\nConnect exits with rc=%d (%s)\n\n",rc,strerror(rc)); |
| 159 | 159 | |
| 160 | 160 | if(!rc) |
| 161 | 161 | { |
| 162 | + rc = lib3270_wait_for_cstate(h,LIB3270_CONNECTED_TN3270E, 60); | |
| 163 | + printf("\n\nWait for LIB3270_CONNECTED_TN3270E exits with rc=%d (%s)\n\n",rc,strerror(rc)); | |
| 164 | + } | |
| 165 | + | |
| 166 | + if(!rc) | |
| 167 | + { | |
| 168 | + rc = lib3270_wait_for_ready(h,60); | |
| 169 | + printf("\n\nWait for ready exits with rc=%d (%s)\n\n",rc,strerror(rc)); | |
| 170 | + } | |
| 171 | + | |
| 172 | + if(!rc) | |
| 173 | + { | |
| 174 | + | |
| 162 | 175 | printf("\n\nWaiting starts %u\n",(unsigned int) time(NULL)); |
| 163 | - lib3270_wait_for_ready(h,10); | |
| 164 | 176 | |
| 165 | 177 | { |
| 166 | 178 | // Performance checks | ... | ... |