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/channel.c b/src/channel.c
index 68ac4bc..2234ad5 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -3940,7 +3940,7 @@
     free_job_options(&opt);
 }
 
-# if defined(MSWIN) || defined(FEAT_GUI) || defined(PROTO)
+#if defined(MSWIN) || defined(__HAIKU__) || defined(FEAT_GUI) || defined(PROTO)
 /*
  * Check the channels for anything that is ready to be read.
  * The data is put in the read queue.
@@ -3973,9 +3973,23 @@
 						     "channel_handle_events");
 	    }
 	}
+
+# ifdef __HAIKU__
+	// Workaround for Haiku: Since select/poll cannot detect EOF from tty,
+	// should close fds when the job has finished if 'channel' connects to
+	// the pty.
+	if (channel->ch_job != NULL)
+	{
+	    job_T *job = channel->ch_job;
+
+	    if (job->jv_tty_out != NULL && job->jv_status == JOB_FINISHED)
+		for (part = PART_SOCK; part < PART_COUNT; ++part)
+		    ch_close_part(channel, part);
+	}
+# endif
     }
 }
-# endif
+#endif
 
 # if defined(FEAT_GUI) || defined(PROTO)
 /*
@@ -4541,6 +4555,20 @@
 	    channel_write_input(channel);
 	    --ret;
 	}
+
+# ifdef __HAIKU__
+	// Workaround for Haiku: Since select/poll cannot detect EOF from tty,
+	// should close fds when the job has finished if 'channel' connects to
+	// the pty.
+	if (channel->ch_job != NULL)
+	{
+	    job_T *job = channel->ch_job;
+
+	    if (job->jv_tty_out != NULL && job->jv_status == JOB_FINISHED)
+		for (part = PART_SOCK; part < PART_COUNT; ++part)
+		    ch_close_part(channel, part);
+	}
+# endif
     }
 
     return ret;