diff --git a/examples/Makefile b/examples/Makefile
index 51d4ac6069cabbe69e11f41ade7f325ce7a082ff..d94ac8ef632808ecebd60aeb302b08353eb28303 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -48,6 +48,10 @@ upload: upload.c ../mongoose.c
 auth: auth.c ../mongoose.c
 	$(CC) auth.c ../mongoose.c $(OUT) $(CFLAGS)
 
+mjpg: mjpg.c ../mongoose.c
+	$(CC) mjpg.c ../mongoose.c $(OUT) $(CFLAGS)
+
+
 websocket_html.c: websocket.html
 	perl mkdata.pl $< > $@
 
@@ -55,4 +59,4 @@ u:
 	g++ unit_test.c -Wall -W -pedantic -lssl -g -O0 $(CFLAGS_EXTRA) && ./a.out
 
 clean:
-	-@$(RM) hello upload post websocket auth server multi_threaded websocket_html.c *.exe *.dSYM *.obj .*o
+	-@$(RM) hello mjpg upload post websocket auth server multi_threaded websocket_html.c *.exe *.dSYM *.obj .*o
diff --git a/mongoose.c b/mongoose.c
index e4480a1c242315e1cc083ab12c02ec9d53aeae49..d9502ca7bfd5afe47ee719b34e43a81c1e2b3abb 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -4783,6 +4783,10 @@ static void mg_ev_handler(struct ns_connection *nc, enum ns_event ev, void *p) {
       break;
 
     case NS_POLL:
+      if (call_user(conn, MG_POLL) == MG_TRUE) {
+        nc->flags |= NSF_FINISHED_SENDING_DATA;
+      }
+
       if (conn != NULL && conn->endpoint_type == EP_FILE) {
         transfer_file_data(conn);
       }
diff --git a/mongoose.h b/mongoose.h
index c430ff9ab70c34c018c8a02ae9650d806d59ad30..734147557846d5200d26d31d2f14d95c20a33a23 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -58,7 +58,7 @@ struct mg_connection {
 };
 
 struct mg_server; // Opaque structure describing server instance
-enum mg_result { MG_FALSE, MG_TRUE };
+enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
 enum mg_event {
   MG_POLL = 100,  // Callback return value is ignored
   MG_CONNECT,     // If callback returns MG_FALSE, connect fails