[ds6-devel] nc6/src io_stream.c,1.14,1.15 io_stream.h,1.8,1.9 readwrite.c,1.26,1.27

chris at deepspace6.net chris@deepspace6.net
Fri Jan 3 14:38:29 CET 2003


Update of /cvs/nc6/src

Modified Files:
	io_stream.c io_stream.h readwrite.c 
Log Message:
I was thinking over the half close stuff and realised there was a major
problem with the implementation.  Whenever a eof was received, the opposing
write stream was shutdown - REGARDLESS or any data still in the output buffer.

To rectify this, I've added a method to io_stream called ios_write_eof, which
signals the io_stream that no more data will be added to the output buffer.
When the output buffer is emptied, the io_stream takes care of calling
shutdown for the write stream.

This change stuffs up the very verbose logging a little, but I'm working on a
fix for this.


Index: io_stream.c
===================================================================
RCS file: /cvs/nc6/src/io_stream.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- io_stream.c	3 Jan 2003 00:14:39 -0000	1.14
+++ io_stream.c	3 Jan 2003 14:38:27 -0000	1.15
@@ -47,6 +47,7 @@
 
 	ios->buf_in  = inbuf;
 	ios->buf_out = outbuf;
+	ios->out_eof = FALSE;
 
 	ios->mtu = 0; /* unlimited */
 	ios->nru = 0; /* unlimited */
@@ -200,10 +201,26 @@
 	else
 		rr = cb_write(ios->buf_out, ios->fd_out, ios->mtu);
 
-	if (rr > 0)
+	if (rr > 0) {
 		ios->sent += rr;
 
+		/* shutdown the write if buf_out is empty and out_eof is set */
+		if (ios->out_eof && cb_is_empty(ios->buf_out))
+			ios_shutdown(ios, SHUT_WR);
+	}
+
 	return rr;
+}
+
+
+
+void ios_write_eof(io_stream* ios)
+{
+	assert(ios != NULL);
+	ios->out_eof = TRUE;
+	/* check if the buffer is already empty */
+	if (cb_is_empty(ios->buf_out))
+		ios_shutdown(ios, SHUT_WR);
 }
 
 
Index: io_stream.h
===================================================================
RCS file: /cvs/nc6/src/io_stream.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- io_stream.h	3 Jan 2003 00:14:39 -0000	1.8
+++ io_stream.h	3 Jan 2003 14:38:27 -0000	1.9
@@ -34,6 +34,8 @@
 
 	circ_buf* buf_in;  /* the input buffer */
 	circ_buf* buf_out; /* the output buffer */
+	bool out_eof;      /* true if no more data will be added
+			    * to the output buffer */
 
 	size_t mtu;        /* Maximum Transmition Unit */
 	size_t nru;        /* miNimum Receive Unit */
@@ -41,7 +43,7 @@
 	bool half_close_suppress; /* true if half-closes should be suppressed */
 
 	int hold_time;     /* time to hold the stream open after read closes,
-	                      -1 means hold indefinately */
+	                    * -1 means hold indefinately */
 	struct timeval read_closed; /* the time that the read was closed */
 
 	const char* name;  /* the name of this io stream (for logging) */
@@ -87,6 +89,11 @@
 /* write from the output buffer.
  * should only be called if ios_schedule_write returned a true value */
 ssize_t ios_write(io_stream *ios);
+
+
+/* signal that no more data will be added to the output buffer.  Once the
+ * buffer is cleared, the io_stream will shutdown it's write stream */
+void ios_write_eof(io_stream *ios);
 
 
 #define is_read_open(IOS)   ((IOS)->fd_in >= 0)
Index: readwrite.c
===================================================================
RCS file: /cvs/nc6/src/readwrite.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- readwrite.c	3 Jan 2003 10:34:06 -0000	1.26
+++ readwrite.c	3 Jan 2003 14:38:27 -0000	1.27
@@ -160,12 +160,10 @@
 				if (very_verbose_mode == TRUE) {
 					warn("read eof from %s",
 					     ios_name(ios1));
-					warn("closing write of %s",
-					     ios_name(ios2));
 				}
 #endif
 				ios_shutdown(ios1, SHUT_RD);
-				ios_shutdown(ios2, SHUT_WR);
+				ios_write_eof(ios2);
 			} else if (rr < 0 && errno != EAGAIN) {
 				/* error while reading ios1:
 				 * print an error message and exit. */
@@ -189,12 +187,10 @@
 				if (very_verbose_mode == TRUE) {
 					warn("read eof from %s",
 					     ios_name(ios2));
-					warn("closing write of %s",
-					     ios_name(ios1));
 				}
 #endif
 				ios_shutdown(ios2, SHUT_RD);
-				ios_shutdown(ios1, SHUT_WR);
+				ios_write_eof(ios1);
 			} else if (rr < 0 && errno != EAGAIN) {
 				/* error while reading ios2:
 				 * print an error message and exit. */



More information about the ds6-devel mailing list