summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-11-07 19:25:44 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-11-07 19:25:44 +0100
commitbb5d6e408b08d82b89e0b1e91e05a0e4c0226c18 (patch)
treef63a2b1d92c65209d446cedf7b4ff0abc62112a7
parent9fcc6c5d9cb59065e57fa24a80a8912516c8c20c (diff)
afb-stub-ws: autoclose session on disconnection
Change-Id: If46ca2fa34a080b7087edb4e0da109c5ee85b14f Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-session.c10
-rw-r--r--src/afb-session.h1
-rw-r--r--src/afb-stub-ws.c2
3 files changed, 12 insertions, 1 deletions
diff --git a/src/afb-session.c b/src/afb-session.c
index 1cb1d8d8..6b6ad634 100644
--- a/src/afb-session.c
+++ b/src/afb-session.c
@@ -57,6 +57,7 @@ struct afb_session
time_t expiration; // expiration time of the token
pthread_mutex_t mutex;
struct cookie *cookies[COOKEYCOUNT];
+ char autoclose;
char idx;
char uuid[SIZEUUID]; // long term authentication of remote client
char token[SIZEUUID]; // short term authentication of remote client
@@ -358,7 +359,7 @@ void afb_session_unref(struct afb_session *session)
assert(session->refcount != 0);
if (!__atomic_sub_fetch(&session->refcount, 1, __ATOMIC_RELAXED)) {
pthread_mutex_lock(&session->mutex);
- if (session->uuid[0] == 0)
+ if (session->autoclose || session->uuid[0] == 0)
destroy (session);
else
pthread_mutex_unlock(&session->mutex);
@@ -383,6 +384,13 @@ void afb_session_close (struct afb_session *session)
pthread_mutex_unlock(&session->mutex);
}
+/* set the autoclose flag */
+void afb_session_set_autoclose(struct afb_session *session, int autoclose)
+{
+ assert(session != NULL);
+ session->autoclose = (char)!!autoclose;
+}
+
// is the session active?
int afb_session_is_active (struct afb_session *session)
{
diff --git a/src/afb-session.h b/src/afb-session.h
index b27cbc80..d79ec414 100644
--- a/src/afb-session.h
+++ b/src/afb-session.h
@@ -33,6 +33,7 @@ extern const char *afb_session_uuid (struct afb_session *session);
extern struct afb_session *afb_session_addref(struct afb_session *session);
extern void afb_session_unref(struct afb_session *session);
+extern void afb_session_set_autoclose(struct afb_session *session, int autoclose);
extern void afb_session_close(struct afb_session *session);
extern int afb_session_is_active (struct afb_session *session);
diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c
index d5355ff8..740a8575 100644
--- a/src/afb-stub-ws.c
+++ b/src/afb-stub-ws.c
@@ -533,6 +533,8 @@ static void on_call(void *closure, struct afb_proto_ws_call *call, const char *v
goto unconnected;
wreq->xreq.context.validated = 1;
record_session(stubws, wreq->xreq.context.session);
+ if (wreq->xreq.context.created)
+ afb_session_set_autoclose(wreq->xreq.context.session, 1);
/* makes the call */
wreq->xreq.cred = afb_cred_addref(stubws->cred);