[ds6-devel] nc6/src connection.c,1.11,1.12 io_stream.c,1.10,1.11
io_stream.h,1.4,1.5 main.c,1.14,1.15 parser.c,1.24,1.25
parser.h,1.10,1.11 readwrite.c,1.22,1.23
chris@deepspace6.net
chris@deepspace6.net
Wed Jan 1 10:05:34 2003
Update of /cvs/nc6/src
Modified Files:
connection.c io_stream.c io_stream.h main.c parser.c parser.h
readwrite.c
Log Message:
Moved half-close handling out of flags and into io_stream (where it belongs).
Also moved byte counts out of readwrite into io_stream - makes more sense.
Renamed --hold-timeouts to --hold-timeout since it doesn't have to be plural ;)
Index: connection.c
===================================================================
RCS file: /cvs/nc6/src/connection.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- connection.c 30 Dec 2002 22:35:47 -0000 1.11
+++ connection.c 1 Jan 2003 10:05:32 -0000 1.12
@@ -63,6 +63,9 @@
* entire connection will be torn down */
ios_set_hold_timeout(&(attrs->remote_stream), 0);
+ /* by default we don't send TCP half closes to the remote system */
+ ios_suppress_half_close(&(attrs->remote_stream), TRUE);
+
/* no connect timeout */
attrs->connect_timeout = -1;
}
Index: io_stream.c
===================================================================
RCS file: /cvs/nc6/src/io_stream.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- io_stream.c 30 Dec 2002 22:35:47 -0000 1.10
+++ io_stream.c 1 Jan 2003 10:05:32 -0000 1.11
@@ -50,8 +50,13 @@
ios->mtu = 0; /* unlimited */
ios->nru = 0; /* unlimited */
+ ios->half_close_suppress = FALSE;
+
ios->hold_time = -1; /* infinite */
timerclear(&(ios->read_closed));
+
+ ios->rcvd = 0;
+ ios->sent = 0;
}
@@ -157,31 +162,44 @@
ssize_t ios_read(io_stream *ios)
{
+ ssize_t rr;
+
/* should only be called if ios_schedule_read returned a true result */
assert(ios->fd_in >= 0);
assert(cb_space(ios->buf_in) >= ios->nru);
/* read as much as possible */
if (ios->socktype == SOCK_DGRAM)
- return cb_recv(ios->buf_in, ios->fd_in, 0, NULL, 0);
+ rr = cb_recv(ios->buf_in, ios->fd_in, 0, NULL, 0);
else
- return cb_read(ios->buf_in, ios->fd_in, 0);
+ rr = cb_read(ios->buf_in, ios->fd_in, 0);
+ if (rr > 0)
+ ios->rcvd += rr;
+
+ return rr;
}
ssize_t ios_write(io_stream *ios)
{
+ ssize_t rr;
+
/* should only be called if ios_schedule_write returned a true result */
assert(ios->fd_out >= 0);
assert(!cb_is_empty(ios->buf_out));
/* write as much as the mtu allows */
if (ios->socktype == SOCK_DGRAM)
- return cb_send(ios->buf_out, ios->fd_out, ios->mtu, NULL, 0);
+ rr = cb_send(ios->buf_out, ios->fd_out, ios->mtu, NULL, 0);
else
- return cb_write(ios->buf_out, ios->fd_out, ios->mtu);
+ rr = cb_write(ios->buf_out, ios->fd_out, ios->mtu);
+
+ if (rr > 0)
+ ios->sent += rr;
+
+ return rr;
}
@@ -205,10 +223,12 @@
/* close the input */
if (ios->fd_in >= 0) {
/* if the fd is duplex, use shutdown */
- if (ios->fd_in == ios->fd_out)
- shutdown(ios->fd_in, SHUT_RD);
- else
+ if (ios->fd_in == ios->fd_out) {
+ if (!ios->half_close_suppress)
+ shutdown(ios->fd_in, SHUT_RD);
+ } else {
close(ios->fd_in);
+ }
ios->fd_in = -1;
/* record the read shutdown time */
gettimeofday(&(ios->read_closed), NULL);
@@ -218,10 +238,12 @@
/* close the output */
if (ios->fd_out >= 0) {
/* if the fd is duplex, use shutdown */
- if (ios->fd_in == ios->fd_out)
- shutdown(ios->fd_out, SHUT_WR);
- else
+ if (ios->fd_in == ios->fd_out) {
+ if (!ios->half_close_suppress)
+ shutdown(ios->fd_out, SHUT_WR);
+ } else {
close(ios->fd_out);
+ }
[...3 lines suppressed...]
Index: io_stream.h
===================================================================
RCS file: /cvs/nc6/src/io_stream.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- io_stream.h 30 Dec 2002 22:35:47 -0000 1.4
+++ io_stream.h 1 Jan 2003 10:05:32 -0000 1.5
@@ -38,9 +38,14 @@
size_t mtu; /* Maximum Transmition Unit */
size_t nru; /* miNimum Receive Unit */
+ 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 */
struct timeval read_closed; /* the time that the read was closed */
+
+ size_t rcvd; /* bytes received */
+ size_t sent; /* bytes sent */
} io_stream;
@@ -57,6 +62,9 @@
* this is the minimum amount of data that can be handled in any read */
#define ios_set_nru(IOS, U) ((IOS)->nru = (U))
+/* sets half closes suppression */
+#define ios_suppress_half_close(IOS, B) ((IOS)->half_close_suppress = (B))
+
/* sets the time (in sec) after read is shutdown that timeout occurs */
#define ios_set_hold_timeout(IOS, T) ((IOS)->hold_time = (T))
@@ -85,5 +93,8 @@
/* shutdown the stream as per shutdown(2) */
void ios_shutdown(io_stream *ios, int how);
+
+#define ios_bytes_received(IOS) ((IOS)->rcvd)
+#define ios_bytes_sent(IOS) ((IOS)->sent)
#endif /* IO_STREAM_H */
Index: main.c
===================================================================
RCS file: /cvs/nc6/src/main.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- main.c 30 Dec 2002 23:14:02 -0000 1.14
+++ main.c 1 Jan 2003 10:05:32 -0000 1.15
@@ -140,6 +140,11 @@
retval = readwrite(&(connection_attrs.remote_stream),
&(connection_attrs.local_stream));
+ if (is_flag_set(VERBOSE_MODE) == TRUE)
+ warn("connection closed (sent %d, rcvd %d)",
+ ios_bytes_sent(&(connection_attrs.remote_stream)),
+ ios_bytes_received(&(connection_attrs.remote_stream)));
+
/* cleanup */
connection_attributes_destroy(&connection_attrs);
Index: parser.c
===================================================================
RCS file: /cvs/nc6/src/parser.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- parser.c 30 Dec 2002 23:14:02 -0000 1.24
+++ parser.c 1 Jan 2003 10:05:32 -0000 1.25
@@ -51,35 +51,35 @@
/* long options */
static const struct option long_options[] = {
#define OPT_HELP 0
- {"help", FALSE, NULL, 'h'},
+ {"help", FALSE, NULL, 'h'},
#define OPT_LISTEN 1
- {"listen", FALSE, NULL, 'l'},
+ {"listen", FALSE, NULL, 'l'},
#define OPT_PORT 2
- {"port", TRUE, NULL, 'p'},
-#define OPT_HOLD_TIMEOUTS 3
- {"hold-timeouts", TRUE, NULL, 'q'},
+ {"port", TRUE, NULL, 'p'},
+#define OPT_HOLD_TIMEOUT 3
+ {"hold-timeout", TRUE, NULL, 'q'},
#define OPT_ADDRESS 4
- {"address", TRUE, NULL, 's'},
+ {"address", TRUE, NULL, 's'},
#define OPT_UDP 5
- {"udp", FALSE, NULL, 'u'},
+ {"udp", FALSE, NULL, 'u'},
#define OPT_TIMEOUT 6
- {"timeout", TRUE, NULL, 'w'},
+ {"timeout", TRUE, NULL, 'w'},
#define OPT_TRANSFER 7
- {"transfer", FALSE, NULL, 'x'},
+ {"transfer", FALSE, NULL, 'x'},
#define OPT_RECV_ONLY 8
- {"recv-only", FALSE, NULL, 0 },
+ {"recv-only", FALSE, NULL, 0 },
#define OPT_SEND_ONLY 9
- {"send-only", FALSE, NULL, 0 },
+ {"send-only", FALSE, NULL, 0 },
#define OPT_BUFFER_SIZE 10
- {"buffer-size", TRUE, NULL, 0 },
+ {"buffer-size", TRUE, NULL, 0 },
#define OPT_MTU 11
- {"mtu", TRUE, NULL, 0 },
+ {"mtu", TRUE, NULL, 0 },
#define OPT_NRU 12
- {"nru", TRUE, NULL, 0 },
+ {"nru", TRUE, NULL, 0 },
#define OPT_HALF_CLOSE 13
- {"half-close", FALSE, NULL, 0 },
+ {"half-close", FALSE, NULL, 0 },
#define OPT_DISABLE_NAGLE 14
- {"disable-nagle", FALSE, NULL, 0 },
+ {"disable-nagle", FALSE, NULL, 0 },
#define OPT_MAX 15
{0, 0, 0, 0}
};
@@ -130,8 +130,9 @@
remote_nru = safe_atoi(optarg);
break;
case OPT_HALF_CLOSE:
- set_flag(HALF_CLOSE_MODE);
/* keep remote open after half close */
+ ios_suppress_half_close(
+ &(attrs->remote_stream), FALSE);
ios_set_hold_timeout(
&(attrs->remote_stream), -1);
break;
@@ -324,8 +325,8 @@
" -l, --listen Listen mode, for inbound connects\n"
" -n Numeric-only IP addresses, no DNS\n"
" -p, --port=PORT Local source port\n"
-" -q, --hold-timeouts=SEC1[:SEC2]\n"
-" Set hold timeouts\n"
+" -q, --hold-timeout=SEC1[:SEC2]\n"
+" Set hold timeout(s)\n"
" -s, --address=ADDRESS\n"
" Local source address\n"
" -u, --udp Require use of UDP\n"
Index: parser.h
===================================================================
RCS file: /cvs/nc6/src/parser.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- parser.h 30 Dec 2002 22:35:47 -0000 1.10
+++ parser.h 1 Jan 2003 10:05:32 -0000 1.11
@@ -34,8 +34,7 @@
#define SEND_DATA_ONLY 0x00000040
#define VERBOSE_MODE 0x00000080
#define VERY_VERBOSE_MODE 0x00000100
-#define HALF_CLOSE_MODE 0x00000200
-#define DISABLE_NAGLE 0x00000400
+#define DISABLE_NAGLE 0x00000200
int parse_arguments(int argc, char **argv, connection_attributes *attrs);
bool is_flag_set(unsigned long mask);
Index: readwrite.c
===================================================================
RCS file: /cvs/nc6/src/readwrite.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- readwrite.c 30 Dec 2002 22:35:47 -0000 1.22
+++ readwrite.c 1 Jan 2003 10:05:32 -0000 1.23
@@ -48,11 +48,6 @@
struct timeval tv1, tv2;
struct timeval *tvp1, *tvp2, *tvp;
int retval = 0;
- size_t local_rcvd = 0;
- size_t net_rcvd = 0;
- size_t local_sent = 0;
- size_t net_sent = 0;
- bool half_close_mode = is_flag_set(HALF_CLOSE_MODE);
#ifndef NDEBUG
bool very_verbose_mode = is_flag_set(VERY_VERBOSE_MODE);
#endif
@@ -154,7 +149,6 @@
rr = ios_read(ios1);
if (rr > 0) {
- net_rcvd += rr;
#ifndef NDEBUG
if (very_verbose_mode == TRUE)
warn("read %d bytes from ios1", rr);
@@ -163,14 +157,11 @@
#ifndef NDEBUG
if (very_verbose_mode == TRUE) {
warn("closing read of ios1");
- if (half_close_mode == TRUE)
- warn("closing write of ios2");
+ warn("closing write of ios2");
}
#endif
ios_shutdown(ios1, SHUT_RD);
- /* send a half close to ios2 */
- if (half_close_mode == TRUE)
- ios_shutdown(ios2, SHUT_WR);
+ ios_shutdown(ios2, SHUT_WR);
} else if (rr < 0 && errno != EAGAIN) {
/* error while reading ios1:
* print an error message and exit. */
@@ -184,7 +175,6 @@
rr = ios_read(ios2);
if (rr > 0) {
- local_rcvd += rr;
#ifndef NDEBUG
if (very_verbose_mode == TRUE)
warn("read %d bytes from ios2", rr);
@@ -193,14 +183,11 @@
#ifndef NDEBUG
if (very_verbose_mode == TRUE) {
warn("closing read of ios2");
- if (half_close_mode == TRUE)
- warn("closing write of ios2");
+ warn("closing write of ios2");
}
#endif
ios_shutdown(ios2, SHUT_RD);
- /* send a half close to ios1 */
- if (half_close_mode == TRUE)
- ios_shutdown(ios1, SHUT_WR);
+ ios_shutdown(ios1, SHUT_WR);
} else if (rr < 0 && errno != EAGAIN) {
/* error while reading ios2:
* print an error message and exit. */
@@ -215,7 +202,6 @@
rr = ios_write(ios1);
if (rr > 0) {
- net_sent += rr;
#ifndef NDEBUG
if (very_verbose_mode == TRUE)
warn("wrote %d bytes to ios1", rr);
@@ -250,7 +236,6 @@
rr = ios_write(ios2);
if (rr > 0) {
- local_sent += rr;
#ifndef NDEBUG
if (very_verbose_mode == TRUE)
warn("wrote %d bytes to ios2", rr);
@@ -280,9 +265,5 @@
}
}
- if (is_flag_set(VERBOSE_MODE) == TRUE)
- warn("connection closed (sent %d, rcvd %d)",
- net_sent, net_rcvd);
-
return retval;
}
More information about the ds6-devel
mailing list