diff options
-rw-r--r-- | src/vcl/vcl_private.h | 2 | ||||
-rw-r--r-- | src/vcl/vppcom.c | 32 | ||||
-rw-r--r-- | src/vcl/vppcom.h | 8 |
3 files changed, 42 insertions, 0 deletions
diff --git a/src/vcl/vcl_private.h b/src/vcl/vcl_private.h index 9c905333440..624a2dad50e 100644 --- a/src/vcl/vcl_private.h +++ b/src/vcl/vcl_private.h @@ -172,6 +172,8 @@ typedef struct vcl_session_ transport_endpt_ext_cfg_t *ext_config; u8 dscp; + i32 vpp_error; + #if VCL_ELOG elog_track_t elog_track; #endif diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c index 8476ea44d68..05b84d4674b 100644 --- a/src/vcl/vppcom.c +++ b/src/vcl/vppcom.c @@ -411,6 +411,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk, format_session_error, mp->retval); session->session_state = VCL_STATE_DETACHED; session->vpp_handle = VCL_INVALID_SESSION_HANDLE; + session->vpp_error = mp->retval; return session_index; } @@ -1398,6 +1399,7 @@ vppcom_session_create (u8 proto, u8 is_nonblocking) session->session_state = VCL_STATE_CLOSED; session->vpp_handle = ~0; session->is_dgram = vcl_proto_is_dgram (proto); + session->vpp_error = SESSION_E_NONE; if (is_nonblocking) vcl_session_set_attr (session, VCL_SESS_ATTR_NONBLOCK); @@ -4420,6 +4422,10 @@ vppcom_retval_str (int retval) st = "VPPCOM_ETIMEDOUT"; break; + case VPPCOM_EADDRINUSE: + st = "VPPCOM_EADDRINUSE"; + break; + default: st = "UNKNOWN_STATE"; break; @@ -4446,6 +4452,32 @@ vppcom_del_cert_key_pair (uint32_t ckpair_index) return vcl_bapi_del_cert_key_pair (ckpair_index); } +int +vppcom_session_get_error (uint32_t session_handle) +{ + vcl_worker_t *wrk = vcl_worker_get_current (); + vcl_session_t *session = 0; + + session = vcl_session_get_w_handle (wrk, session_handle); + if (!session) + return VPPCOM_EBADFD; + + if (PREDICT_FALSE (session->flags & VCL_SESSION_F_IS_VEP)) + { + VWRN ("epoll session %u! will not have connect", session->session_index); + return VPPCOM_EBADFD; + } + + if (session->vpp_error == SESSION_E_PORTINUSE) + return VPPCOM_EADDRINUSE; + else if (session->vpp_error == SESSION_E_REFUSED) + return VPPCOM_ECONNREFUSED; + else if (session->vpp_error != SESSION_E_NONE) + return VPPCOM_EFAULT; + else + return VPPCOM_OK; +} + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/vcl/vppcom.h b/src/vcl/vppcom.h index c50850c9cc3..6e15cd17cd4 100644 --- a/src/vcl/vppcom.h +++ b/src/vcl/vppcom.h @@ -102,6 +102,7 @@ typedef enum VPPCOM_ENOPROTOOPT = -ENOPROTOOPT, VPPCOM_EPIPE = -EPIPE, VPPCOM_ENOENT = -ENOENT, + VPPCOM_EADDRINUSE = -EADDRINUSE } vppcom_error_t; typedef enum @@ -264,6 +265,13 @@ extern void vppcom_worker_index_set (int); */ extern int vppcom_worker_mqs_epfd (void); +/** + * Returns Session error + * + * Application can use this API to find the detailed session error + */ +extern int vppcom_session_get_error (uint32_t session_handle); + /* *INDENT-OFF* */ #ifdef __cplusplus } |