[ds6-devel] nc6/src io_stream.c,1.16,1.17 readwrite.c,1.28,1.29
mauro at deepspace6.net
mauro at deepspace6.net
Sat Jan 4 15:41:49 CET 2003
Update of /cvs/nc6/src
Modified Files:
io_stream.c readwrite.c
Log Message:
src/io_stream.c: 1) added ios_assert function (same as cb_assert)
2) in io_stream_init a deep copy of argument name is made
before assigning it to ios->name
src/readwrite.c: minor layout changes
Index: io_stream.c
===================================================================
RCS file: /cvs/nc6/src/io_stream.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- io_stream.c 3 Jan 2003 17:07:02 -0000 1.16
+++ io_stream.c 4 Jan 2003 14:41:47 -0000 1.17
@@ -41,6 +41,7 @@
assert(ios != NULL);
assert(inbuf != NULL);
assert(outbuf != NULL);
+ assert(name != NULL);
ios->fd_in = -1;
ios->fd_out = -1;
@@ -58,24 +59,42 @@
ios->hold_time = -1; /* infinite */
timerclear(&(ios->read_closed));
- ios->name = name;
+ ios->name = xstrdup(name);
ios->rcvd = 0;
ios->sent = 0;
}
+#ifndef NDEBUG
+static void ios_assert(const io_stream *ios)
+{
+ if (ios == NULL ||
+ ios->name == NULL ||
+ ios->buf_in == NULL ||
+ ios->buf_out == NULL)
+ fatal("internal error with I/O streams: please"
+ "contact the authors of nc6 for bugfixing ;-)");
+}
+#else
+#define ios_assert(IOS) do {} while(0)
+#endif
+
+
+
void io_stream_destroy(io_stream *ios)
{
- assert(ios != NULL);
+ ios_assert(ios);
+
ios_shutdown(ios, SHUT_RDWR);
+ free(ios->name);
}
void ios_assign_socket(io_stream *ios, int fd, int socktype)
{
- assert(ios != NULL);
+ ios_assert(ios);
assert(fd >= 0);
ios->fd_in = fd;
@@ -88,6 +107,7 @@
void ios_assign_stdio(io_stream *ios)
{
assert(ios != NULL);
+ ios_assert(ios);
if ((ios->fd_in = dup(STDIN_FILENO)) < 0)
fatal("error in duplicating stdin file descriptor: %s",
@@ -105,8 +125,12 @@
int ios_schedule_read(io_stream *ios)
{
- size_t space = cb_space(ios->buf_in);
+ size_t space;
+ ios_assert(ios);
+
+ space = cb_space(ios->buf_in);
+
/* if closed, the buffer is full or there isn't enough free space in
* the buffer to satisfy the nru, then we can't read */
if ((ios->fd_in < 0) || space == 0 || space < ios->nru)
@@ -120,6 +144,8 @@
int ios_schedule_write(io_stream *ios)
{
+ ios_assert(ios);
+
/* if closed or there is no data in the buffer, then we can't write */
if ((ios->fd_out < 0) || cb_is_empty(ios->buf_out))
return -1;
@@ -134,7 +160,7 @@
{
struct timeval now;
- assert(ios != NULL);
+ ios_assert(ios);
assert(tv != NULL);
[...39 lines suppressed...]
Index: readwrite.c
===================================================================
RCS file: /cvs/nc6/src/readwrite.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- readwrite.c 3 Jan 2003 17:07:02 -0000 1.28
+++ readwrite.c 4 Jan 2003 14:41:47 -0000 1.29
@@ -136,9 +136,9 @@
rr = ios_read(ios1);
if (rr < 0) {
- if (rr == IOS_EOF)
+ if (rr == IOS_EOF) {
ios_write_eof(ios2);
- else {
+ } else {
/* something bad happened -
* exit the main loop */
retval = -1;
@@ -152,9 +152,9 @@
rr = ios_read(ios2);
if (rr < 0) {
- if (rr == IOS_EOF)
+ if (rr == IOS_EOF) {
ios_write_eof(ios1);
- else {
+ } else {
/* something bad happened -
* exit the main loop */
retval = -1;
More information about the ds6-devel
mailing list