patch 8.0.1076: term_start() does not take callbacks

Problem:    term_start() does not take callbacks. When using two terminals
            without a job only one is read from.  A terminal without a window
            returns the wrong pty.
Solution:   Support "callback", "out_cb" and "err_cb".  Fix terminal without a
            window. Fix reading from multiple channels.
diff --git a/src/channel.c b/src/channel.c
index c401df2..dfb8ac9 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -3692,13 +3692,10 @@
 	{
 	    res = fd_write(fd, (char *)buf, len);
 #ifdef WIN32
-	    if (channel->ch_named_pipe)
+	    if (channel->ch_named_pipe && res < 0)
 	    {
-		if (res < 0)
-		{
-		    DisconnectNamedPipe((HANDLE)fd);
-		    ConnectNamedPipe((HANDLE)fd, NULL);
-		}
+		DisconnectNamedPipe((HANDLE)fd);
+		ConnectNamedPipe((HANDLE)fd, NULL);
 	    }
 #endif
 
@@ -4084,6 +4081,7 @@
 	    if (ret > 0 && fd != INVALID_FD && FD_ISSET(fd, rfds))
 	    {
 		channel_read(channel, part, "channel_select_check");
+		FD_CLR(fd, rfds);
 		--ret;
 	    }
 	}
@@ -4093,6 +4091,7 @@
 					    && FD_ISSET(in_part->ch_fd, wfds))
 	{
 	    channel_write_input(channel);
+	    FD_CLR(in_part->ch_fd, wfds);
 	    --ret;
 	}
     }