Commit c4569a308c2240d6f2bed0cc10f1e1f0082af751

Authored by Perry Werneck
1 parent 97072052

Better error codes when the session is connected.

src/include/api.h
... ... @@ -89,6 +89,10 @@
89 89 #define ENOTCONN -1107
90 90 #endif
91 91  
  92 + #ifndef EISCONN
  93 + #define EISCONN -1106
  94 + #endif
  95 +
92 96 #ifndef CN
93 97 #define CN ((char *) NULL)
94 98 #endif
... ...
src/include/lib3270.h
... ... @@ -595,7 +595,7 @@
595 595 * @param h Session handle.
596 596 * @param seconds Seconds to wait for connection.
597 597 *
598   - * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure.
  598 + * @return 0 for success, non zero if fails (sets errno).
599 599 *
600 600 */
601 601 LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int seconds);
... ...
src/lib3270/connect.c
... ... @@ -62,7 +62,7 @@
62 62 return errno = EAGAIN;
63 63  
64 64 if(hSession->sock > 0)
65   - return errno = EBUSY;
  65 + return errno = EISCONN;
66 66  
67 67 if(!(hSession->host.current && hSession->host.srvc))
68 68 {
... ...
src/lib3270/ctlr.c
... ... @@ -252,7 +252,7 @@ int lib3270_set_model(H3270 *hSession, const char *model)
252 252 int model_number;
253 253  
254 254 if(hSession->cstate != LIB3270_NOT_CONNECTED)
255   - return errno = EBUSY;
  255 + return errno = EISCONN;
256 256  
257 257 strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH);
258 258 hSession->model_name = &hSession->full_model_name[4];
... ...
src/lib3270/ft.c
... ... @@ -153,7 +153,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
153 153 }
154 154  
155 155 if(!force)
156   - return EBUSY;
  156 + return errno = EBUSY;
157 157  
158 158 // Impatient user or hung host -- just clean up.
159 159 ft_failed(ft, N_("Cancelled by user") );
... ...
src/lib3270/options.c
... ... @@ -97,7 +97,7 @@ LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, int colortype)
97 97 CHECK_SESSION_HANDLE(hSession);
98 98  
99 99 if(hSession->cstate != LIB3270_NOT_CONNECTED)
100   - return errno = EBUSY;
  100 + return errno = EISCONN;
101 101  
102 102 switch(colortype)
103 103 {
... ...
src/lib3270/private.h
... ... @@ -669,10 +669,10 @@ LIB3270_INTERNAL int check_online_session(H3270 *hSession);
669 669 LIB3270_INTERNAL int check_offline_session(H3270 *hSession);
670 670  
671 671 /// @brief Returns -1 if the session is invalid or not online (sets errno).
672   -#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return -1;
  672 +#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return errno;
673 673  
674 674 /// @brief Returns -1 if the session is invalid or online (sets errno).
675   -#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return -1;
  675 +#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return errno;
676 676  
677 677 LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
678 678  
... ...
src/lib3270/session.c
... ... @@ -432,17 +432,11 @@ LIB3270_INTERNAL int check_online_session(H3270 *hSession) {
432 432  
433 433 // Is the session valid?
434 434 if(!hSession)
435   - {
436   - errno = EINVAL;
437   - return -1;
438   - }
  435 + return errno = EINVAL;
439 436  
440 437 // Is it connected?
441 438 if((int) hSession->cstate < (int)LIB3270_CONNECTED_INITIAL)
442   - {
443   - errno = ENOTCONN;
444   - return -1;
445   - }
  439 + return errno = ENOTCONN;
446 440  
447 441 return 0;
448 442 }
... ... @@ -451,17 +445,11 @@ LIB3270_INTERNAL int check_offline_session(H3270 *hSession) {
451 445  
452 446 // Is the session valid?
453 447 if(!hSession)
454   - {
455   - errno = EINVAL;
456   - return -1;
457   - }
  448 + return errno = EINVAL;
458 449  
459 450 // Is it connected?
460 451 if((int) hSession->cstate >= (int)LIB3270_CONNECTED_INITIAL)
461   - {
462   - errno = EBUSY;
463   - return -1;
464   - }
  452 + return errno = EISCONN;
465 453  
466 454 return 0;
467 455 }
... ...