From 248f6eafa20476014f4bf12d90b2234c4be7eef2 Mon Sep 17 00:00:00 2001
From: José Bollo <jose.bollo@iot.bzh>
Date: Tue, 20 Aug 2019 12:32:02 +0200
Subject: Fix client disconnection close
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Before that change, the client disconection made a loop
on read but wasn't closing the link.

Bug-AGL: SPEC-2759

Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Change-Id: Iecfbb95cb1b7079e695ff5c08155b2310bf4b8d8
---
 src/afb-api-ws.c     | 6 +++---
 src/afb-ws.c         | 6 +++---
 src/afs-supervisor.c | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/afb-api-ws.c b/src/afb-api-ws.c
index dc45edbb..cf1f3921 100644
--- a/src/afb-api-ws.c
+++ b/src/afb-api-ws.c
@@ -144,10 +144,10 @@ static void api_ws_server_listen_callback(void *closure, uint32_t revents, struc
 {
 	struct api_ws_server *apiws = closure;
 
-	if ((revents & EPOLLIN) != 0)
-		api_ws_server_accept(apiws);
-	else if ((revents & EPOLLHUP) != 0)
+	if ((revents & EPOLLHUP) != 0)
 		api_ws_server_connect(apiws);
+	else if ((revents & EPOLLIN) != 0)
+		api_ws_server_accept(apiws);
 }
 
 static void api_ws_server_disconnect(struct api_ws_server *apiws)
diff --git a/src/afb-ws.c b/src/afb-ws.c
index 454ddc1a..6fb9b5f9 100644
--- a/src/afb-ws.c
+++ b/src/afb-ws.c
@@ -132,10 +132,10 @@ static void aws_disconnect(struct afb_ws *ws, int call_on_hangup)
 
 static void fdevcb(void *ws, uint32_t revents, struct fdev *fdev)
 {
-	if ((revents & EPOLLIN) != 0)
-		aws_on_readable(ws);
-	else if ((revents & EPOLLHUP) != 0)
+	if ((revents & EPOLLHUP) != 0)
 		afb_ws_hangup(ws);
+	else if ((revents & EPOLLIN) != 0)
+		aws_on_readable(ws);
 }
 
 /*
diff --git a/src/afs-supervisor.c b/src/afs-supervisor.c
index 5bc31ea9..7f87adbf 100644
--- a/src/afs-supervisor.c
+++ b/src/afs-supervisor.c
@@ -280,12 +280,12 @@ static void accept_supervision_link(int sock)
  */
 static void listening(void *closure, uint32_t revents, struct fdev *fdev)
 {
-	if ((revents & EPOLLIN) != 0)
-		accept_supervision_link((int)(intptr_t)closure);
-	else if ((revents & EPOLLHUP) != 0) {
+	if ((revents & EPOLLHUP) != 0) {
 		ERROR("supervision socket closed");
 		exit(1);
 	}
+	if ((revents & EPOLLIN) != 0)
+		accept_supervision_link((int)(intptr_t)closure);
 }
 
 /*
-- 
cgit