MEDIUM: stream-int: make si_update() synchronize flag changes before the I/O

With the new synchronous si_cs_send() at the end of process_stream(),
we're seeing re-appear the I/O layer specific part of the stream interface
which is supposed to deal with I/O event subscription. The only difference
is that now we subscribe to I/Os only after having attempted (and failed)
them.

This patch brings a cleanup in this by reintroducing stream_int_update_conn()
with the send code from process_stream(). However this alone would not be
enough because the flags which are cleared afterwards would result in the
loss of the possible events (write events only at the moment). So the flags
clearing and stream-int state updates are also performed inside si_update()
between the generic code and the I/O specific code. This definitely makes
sense as after this call we can simply check again for channel and SI flag
changes and decide to loop once again or not.
diff --git a/src/stream_interface.c b/src/stream_interface.c
index 8574b4c..08814cf 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -66,6 +66,7 @@
 
 /* stream-interface operations for connections */
 struct si_ops si_conn_ops = {
+	.update  = stream_int_update_conn,
 	.chk_rcv = stream_int_chk_rcv_conn,
 	.chk_snd = stream_int_chk_snd_conn,
 	.shutr   = stream_int_shutr_conn,
@@ -798,6 +799,33 @@
 	}
 }
 
+/* Updates the active status of a connection outside of the connection handler
+ * based on the channel's flags and the stream interface's flags. It needs to
+ * be called once after the channels' flags have settled down and the stream
+ * has been updated. It is not designed to be called from within the connection
+ * handler itself.
+ */
+void stream_int_update_conn(struct stream_interface *si)
+{
+	struct channel *ic = si_ic(si);
+	struct channel *oc = si_oc(si);
+	struct conn_stream *cs = __objt_cs(si->end);
+
+	if (!(ic->flags & CF_SHUTR)) {
+		/* Read not closed, it doesn't seem we have to do anything here */
+	}
+
+	if (!(oc->flags & CF_SHUTW)) {
+		/* Write not closed */
+		if (!channel_is_empty(oc) &&
+		    !(cs->conn->flags & CO_FL_ERROR) &&
+		    !(cs->flags & CS_FL_ERROR) &&
+		    !(oc->flags & CF_SHUTW) &&
+		    !(si->wait_event.wait_reason & SUB_CAN_SEND))
+			si_cs_send(cs);
+	}
+}
+
 /*
  * This function performs a shutdown-read on a stream interface attached to
  * a connection in a connected or init state (it does nothing for other