patch 8.2.0694: Haiku: channel and terminal do not work

Problem:    Haiku: channel and terminal do not work.
Solution:   Close files when the job has finished. (Ozaki Kiichi,
            closes #6039)
diff --git a/src/gui_haiku.cc b/src/gui_haiku.cc
index ff460ad..78ca7b2 100644
--- a/src/gui_haiku.cc
+++ b/src/gui_haiku.cc
@@ -1145,10 +1145,11 @@
 VimTextAreaView::VimTextAreaView(BRect frame):
     BView(frame, "VimTextAreaView", B_FOLLOW_ALL_SIDES,
 #ifdef FEAT_MBYTE_IME
-	B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INPUT_METHOD_AWARE),
+	B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_INPUT_METHOD_AWARE
 #else
-	B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
+	B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE
 #endif
+	),
     mouseDragEventCount(0)
 {
 #ifdef FEAT_MBYTE_IME
@@ -3093,7 +3094,7 @@
 			}
 		    }
 #else
-		    add_to_input_buf_csi(string, len);
+			add_to_input_buf_csi(string, len);
 #endif
 		    else
 			add_to_input_buf(string, len);
@@ -4437,15 +4438,16 @@
 	int	wtime)
 {
     int		focus;
-    bigtime_t	    until, timeout;
-    status_t	    st;
+    bigtime_t	until, timeout;
+    status_t	st;
 
-    if (wtime >= 0) {
+    if (wtime >= 0)
+    {
 	timeout = wtime * 1000;
 	until = system_time() + timeout;
-    } else {
-	timeout = B_INFINITE_TIMEOUT;
     }
+    else
+	timeout = B_INFINITE_TIMEOUT;
 
     focus = gui.in_focus;
     for (;;)
@@ -4461,6 +4463,28 @@
 	}
 
 	gui_mch_flush();
+
+#ifdef MESSAGE_QUEUE
+# ifdef FEAT_TIMERS
+	did_add_timer = FALSE;
+# endif
+	parse_queued_messages();
+# ifdef FEAT_TIMERS
+	if (did_add_timer)
+	    // Need to recompute the waiting time.
+	    break;
+# endif
+# ifdef FEAT_JOB_CHANNEL
+	if (has_any_channel())
+	{
+	    if (wtime < 0 || timeout > 20000)
+		timeout = 20000;
+	}
+	else if (wtime < 0)
+	    timeout = B_INFINITE_TIMEOUT;
+# endif
+#endif
+
 	/*
 	 * Don't use gui_mch_update() because then we will spin-lock until a
 	 * char arrives, instead we use gui_haiku_process_event() to hang until
@@ -4478,7 +4502,8 @@
 	 * Calculate how much longer we're willing to wait for the
 	 * next event.
 	 */
-	if (wtime >= 0) {
+	if (wtime >= 0)
+	{
 	    timeout = until - system_time();
 	    if (timeout < 0)
 		break;