From c4569a308c2240d6f2bed0cc10f1e1f0082af751 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 12 Feb 2019 15:54:34 -0200 Subject: [PATCH] Better error codes when the session is connected. --- src/include/api.h | 4 ++++ src/include/lib3270.h | 2 +- src/lib3270/connect.c | 2 +- src/lib3270/ctlr.c | 2 +- src/lib3270/ft.c | 2 +- src/lib3270/options.c | 2 +- src/lib3270/private.h | 4 ++-- src/lib3270/session.c | 20 ++++---------------- 8 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/include/api.h b/src/include/api.h index 2260df7..9c23487 100644 --- a/src/include/api.h +++ b/src/include/api.h @@ -89,6 +89,10 @@ #define ENOTCONN -1107 #endif + #ifndef EISCONN + #define EISCONN -1106 + #endif + #ifndef CN #define CN ((char *) NULL) #endif diff --git a/src/include/lib3270.h b/src/include/lib3270.h index d706deb..67babdd 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -595,7 +595,7 @@ * @param h Session handle. * @param seconds Seconds to wait for connection. * - * @return 0 for success, EAGAIN if auto-reconnect is in progress, EBUSY if connected, ENOTCONN if connection has failed, -1 on unexpected failure. + * @return 0 for success, non zero if fails (sets errno). * */ LIB3270_EXPORT int lib3270_reconnect(H3270 *h,int seconds); diff --git a/src/lib3270/connect.c b/src/lib3270/connect.c index 6cbb375..99e9bfb 100644 --- a/src/lib3270/connect.c +++ b/src/lib3270/connect.c @@ -62,7 +62,7 @@ return errno = EAGAIN; if(hSession->sock > 0) - return errno = EBUSY; + return errno = EISCONN; if(!(hSession->host.current && hSession->host.srvc)) { diff --git a/src/lib3270/ctlr.c b/src/lib3270/ctlr.c index 2236ef0..f987455 100644 --- a/src/lib3270/ctlr.c +++ b/src/lib3270/ctlr.c @@ -252,7 +252,7 @@ int lib3270_set_model(H3270 *hSession, const char *model) int model_number; if(hSession->cstate != LIB3270_NOT_CONNECTED) - return errno = EBUSY; + return errno = EISCONN; strncpy(hSession->full_model_name,"IBM-",LIB3270_FULL_MODEL_NAME_LENGTH); hSession->model_name = &hSession->full_model_name[4]; diff --git a/src/lib3270/ft.c b/src/lib3270/ft.c index 693b7e8..f673152 100644 --- a/src/lib3270/ft.c +++ b/src/lib3270/ft.c @@ -153,7 +153,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); } if(!force) - return EBUSY; + return errno = EBUSY; // Impatient user or hung host -- just clean up. ft_failed(ft, N_("Cancelled by user") ); diff --git a/src/lib3270/options.c b/src/lib3270/options.c index d746d97..8ee6e42 100644 --- a/src/lib3270/options.c +++ b/src/lib3270/options.c @@ -97,7 +97,7 @@ LIB3270_EXPORT int lib3270_set_color_type(H3270 *hSession, int colortype) CHECK_SESSION_HANDLE(hSession); if(hSession->cstate != LIB3270_NOT_CONNECTED) - return errno = EBUSY; + return errno = EISCONN; switch(colortype) { diff --git a/src/lib3270/private.h b/src/lib3270/private.h index 25267e2..ee05ca1 100644 --- a/src/lib3270/private.h +++ b/src/lib3270/private.h @@ -669,10 +669,10 @@ LIB3270_INTERNAL int check_online_session(H3270 *hSession); LIB3270_INTERNAL int check_offline_session(H3270 *hSession); /// @brief Returns -1 if the session is invalid or not online (sets errno). -#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return -1; +#define FAIL_IF_NOT_ONLINE(x) if(check_online_session(x)) return errno; /// @brief Returns -1 if the session is invalid or online (sets errno). -#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return -1; +#define FAIL_IF_ONLINE(x) if(check_offline_session(x)) return errno; LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on); diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 212c676..6f69c50 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -432,17 +432,11 @@ LIB3270_INTERNAL int check_online_session(H3270 *hSession) { // Is the session valid? if(!hSession) - { - errno = EINVAL; - return -1; - } + return errno = EINVAL; // Is it connected? if((int) hSession->cstate < (int)LIB3270_CONNECTED_INITIAL) - { - errno = ENOTCONN; - return -1; - } + return errno = ENOTCONN; return 0; } @@ -451,17 +445,11 @@ LIB3270_INTERNAL int check_offline_session(H3270 *hSession) { // Is the session valid? if(!hSession) - { - errno = EINVAL; - return -1; - } + return errno = EINVAL; // Is it connected? if((int) hSession->cstate >= (int)LIB3270_CONNECTED_INITIAL) - { - errno = EBUSY; - return -1; - } + return errno = EISCONN; return 0; } -- libgit2 0.21.2