session: cleanup part 1
[vpp.git] / src / vcl / vcl_private.h
index c61bb0b..d55ecd4 100644 (file)
@@ -72,7 +72,7 @@ typedef enum
   STATE_FAILED = 0x20,
   STATE_UPDATED = 0x40,
   STATE_LISTEN_NO_MQ = 0x80,
-} session_state_t;
+} vcl_session_state_t;
 
 #define SERVER_STATE_OPEN  (STATE_ACCEPT|STATE_VPP_CLOSING)
 #define CLIENT_STATE_OPEN  (STATE_CONNECT|STATE_VPP_CLOSING)
@@ -496,7 +496,7 @@ vcl_session_table_lookup_listener (vcl_worker_t * wrk, u64 listener_handle)
   return session;
 }
 
-const char *vppcom_session_state_str (session_state_t state);
+const char *vppcom_session_state_str (vcl_session_state_t state);
 
 static inline u8
 vcl_session_is_ct (vcl_session_t * s)
@@ -504,6 +504,34 @@ vcl_session_is_ct (vcl_session_t * s)
   return (s->our_evt_q != 0);
 }
 
+static inline u8
+vcl_session_is_open (vcl_session_t * s)
+{
+  return ((s->session_state & STATE_OPEN)
+         || (s->session_state == STATE_LISTEN
+             && s->session_type == VPPCOM_PROTO_UDP));
+}
+
+static inline u8
+vcl_session_is_closing (vcl_session_t * s)
+{
+  return (s->session_state == STATE_VPP_CLOSING
+         || s->session_state == STATE_DISCONNECT);
+}
+
+static inline int
+vcl_session_closing_error (vcl_session_t * s)
+{
+  return s->session_state == STATE_DISCONNECT ? VPPCOM_ECONNRESET : 0;
+}
+
+static inline int
+vcl_session_closed_error (vcl_session_t * s)
+{
+  return s->session_state == STATE_DISCONNECT
+    ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
+}
+
 /*
  * Helpers
  */