diff mbox series

mongoose: not block the sender if update is ended

Message ID 20210805155822.1339792-1-sbabic@denx.de
State Accepted
Headers show
Series mongoose: not block the sender if update is ended | expand

Commit Message

Stefano Babic Aug. 5, 2021, 3:58 p.m. UTC
The interface between the webserver and the installer was set in not
blocking mode. However, holding the data to be sent should be done just
in case SWUpdate reports -EBUSY, that is the pipe is full. In case
SWUpdate has already finished, it closes the pipe and returns -EPIPE.
The sender (mongoose) should then ignored it and consume incoming data
to unblock the sender.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 mongoose/mongoose_interface.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 290f33a..2e9416b 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -336,16 +336,20 @@  static void upload_handler(struct mg_connection *nc, int ev, void *p)
 		 * IPC seems to block, wait for a while
 		 */
 		if (written != mp->data.len) {
-			if (errno != EAGAIN && errno != EWOULDBLOCK) {
-				if (!fus->error_report) {
-					ERROR("Writing to IPC fails due to %s", strerror(errno));
-					fus->error_report = true;
-				}
+			if (written < 0) {
+				if (errno != EAGAIN && errno != EWOULDBLOCK) {
+					if (!fus->error_report) {
+						ERROR("Writing to IPC fails due to %s", strerror(errno));
+						fus->error_report = true;
+					}
+					/*
+					 * Simply consumes the data to unblock the sender
+					 */
+					written = mp->data.len;
+				} else
+					written = 0;
 			}
 			usleep(100);
-
-			if (written < 0)
-				written = 0;
 		}
 
 		mp->num_data_consumed = written;