[ds6-devel] nc6/src main.c,1.4,1.5 parser.c,1.9,1.10 parser.h,1.6,1.7
readwrite.c,1.12,1.13
chris@deepspace6.net
chris@deepspace6.net
Fri Dec 20 23:06:07 2002
- Previous message: [ds6-devel] nc6/src parser.h,1.5,1.6 parser.c,1.8,1.9
- Next message: [ds6-devel]
nc6 nc6.spec.in,NONE,1.1 configure.ac,1.2,1.3 nc6.spec,1.5,NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvs/nc6/src
Modified Files:
main.c parser.c parser.h readwrite.c
Log Message:
Reworked file transfer mode - to use RECV_DATA_ONLY or SEND_DATA_ONLY instead
of FILE_TRANSFER_MODE. This is a bit more obvious as to whats going on.
Also moved the setup of transfer mode out of readwrite, so it has no
'mode specific' code (it's just a bit mover).
Index: main.c
===================================================================
RCS file: /cvs/nc6/src/main.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- main.c 15 Dec 2002 17:27:08 -0000 1.4
+++ main.c 20 Dec 2002 23:05:56 -0000 1.5
@@ -25,6 +25,7 @@
#include <signal.h>
#include <string.h>
#include <stdlib.h>
+#include <assert.h>
/* program name */
static char *program_name = NULL;
@@ -66,10 +67,50 @@
break;
}
+ /* setup unidirectional data transfers (if requested) */
+ assert(!(is_flag_set(RECV_DATA_ONLY) && is_flag_set(SEND_DATA_ONLY)));
+
+ if (is_flag_set(RECV_DATA_ONLY) == TRUE) {
+ /* reading only from the remote stream */
+
+ /* close the remote stream for writing */
+ ios_shutdown(&(connection_attrs.remote_stream), SHUT_WR);
+
+ /* close the local stream for reading */
+ ios_shutdown(&(connection_attrs.local_stream), SHUT_RD);
+
+ /* don't stop because the read is closed */
+ ios_set_hold_timeout(&(connection_attrs.local_stream), -1);
+
+#ifndef NDEBUG
+ if (is_flag_set(VERY_VERBOSE_MODE) == TRUE)
+ warn("File xfer mode: reading remote only");
+#endif
+ }
+
+ if (is_flag_set(SEND_DATA_ONLY) == TRUE) {
+ /* reading only from the local stream */
+
+ /* close the remote stream for reading */
+ ios_shutdown(&(connection_attrs.remote_stream), SHUT_RD);
+
+ /* don't stop because the read is closed */
+ ios_set_hold_timeout(&(connection_attrs.remote_stream), -1);
+
+ /* close the local stream for writing */
+ ios_shutdown(&(connection_attrs.local_stream), SHUT_WR);
+
+#ifndef NDEBUG
+ if (is_flag_set(VERY_VERBOSE_MODE) == TRUE)
+ warn("File xfer mode: reading local only");
+#endif
+ }
+
/* run the main read/write loop */
retval = readwrite(&(connection_attrs.remote_stream),
&(connection_attrs.local_stream));
+ /* cleanup */
connection_attributes_destroy(&connection_attrs);
return (retval)? EXIT_FAILURE : EXIT_SUCCESS;
Index: parser.c
===================================================================
RCS file: /cvs/nc6/src/parser.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- parser.c 20 Dec 2002 21:48:22 -0000 1.9
+++ parser.c 20 Dec 2002 23:05:56 -0000 1.10
@@ -43,6 +43,8 @@
int parse_arguments(int argc, char **argv, connection_attributes *attrs)
{
int c, verbosity_level = 0;
+ bool listen_mode = FALSE;
+ bool file_transfer = FALSE;
/* set socket types to default values */
attrs->proto = PROTO_UNSPECIFIED;
@@ -72,7 +74,7 @@
print_usage(stdout);
exit(EXIT_SUCCESS);
case 'l':
- set_flag(LISTEN_MODE);
+ listen_mode = TRUE;
break;
case 'n':
set_flag(NUMERIC_MODE);
@@ -100,7 +102,7 @@
set_flag(VERBOSE_MODE);
break;
case 'x':
- set_flag(FILE_TRANSFER_MODE);
+ file_transfer = TRUE;
break;
default:
print_usage(stderr);
@@ -111,6 +113,14 @@
argv += optind;
argc -= optind;
+ /* set mode flags */
+ set_flag((listen_mode)? LISTEN_MODE : CONNECT_MODE);
+
+ /* setup file transfer depending on the mode */
+ if (file_transfer == TRUE) {
+ set_flag((listen_mode)? RECV_DATA_ONLY : SEND_DATA_ONLY);
+ }
+
/* additional arguments are the remote address/service */
switch(argc) {
case 0:
@@ -143,7 +153,7 @@
attrs->remote_address.service = NULL;
}
- if (is_flag_set(LISTEN_MODE) == TRUE) {
+ if (listen_mode) {
if (attrs->local_address.service == NULL) {
warn("in listen mode you must specify a port with the -p switch");
print_usage(stderr);
Index: parser.h
===================================================================
RCS file: /cvs/nc6/src/parser.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- parser.h 20 Dec 2002 21:48:22 -0000 1.6
+++ parser.h 20 Dec 2002 23:05:56 -0000 1.7
@@ -27,11 +27,12 @@
#define NUMERIC_MODE 0x00000001
#define STRICT_IPV6 0x00000002
#define DONT_REUSE_ADDR 0x00000004
-#define FILE_TRANSFER_MODE 0x00000008
-#define LISTEN_MODE 0x00000010
-#define CONNECT_MODE 0x00000020
-#define VERBOSE_MODE 0x00000040
-#define VERY_VERBOSE_MODE 0x00000080
+#define LISTEN_MODE 0x00000008
+#define CONNECT_MODE 0x00000010
+#define RECV_DATA_ONLY 0x00000020
+#define SEND_DATA_ONLY 0x00000040
+#define VERBOSE_MODE 0x00000080
+#define VERY_VERBOSE_MODE 0x00000100
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.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- readwrite.c 20 Dec 2002 21:47:23 -0000 1.12
+++ readwrite.c 20 Dec 2002 23:05:56 -0000 1.13
@@ -48,9 +48,7 @@
/* ios1 is the remote stream, ios2 the local one */
int readwrite(io_stream *ios1, io_stream *ios2)
{
- int rr, max_fd;
- bool file_xfer_mode;
- bool listen_mode;
+ int rr, max_fd = -1;
fd_set read_fdset, tmp_rd_fdset, write_fdset, tmp_wr_fdset;
circ_buf *buf1 = NULL;
uint8_t *tbuf1 = NULL;
@@ -84,68 +82,27 @@
local_sent = 0;
net_sent = 0;
- file_xfer_mode = is_flag_set(FILE_TRANSFER_MODE);
- listen_mode = is_flag_set(LISTEN_MODE);
-
/* setup all the stuff for the select loop */
FD_ZERO(&read_fdset);
FD_ZERO(&write_fdset);
- if (file_xfer_mode == TRUE) {
- /* if we are in file transfer mode, setup unidirectional
- * data transfers */
- if (listen_mode == TRUE) {
- /* reading only from the remote stream */
- FD_SET(ios_readfd(ios1), &read_fdset);
-
- /* close the remote stream for writing */
- ios_shutdown(ios1, SHUT_WR);
-
- /* close the local stream for reading */
- ios_shutdown(ios2, SHUT_RD);
-
- /* don't stop because the read is closed */
- ios_set_hold_timeout(ios2, -1);
-
- max_fd = MAX(ios_readfd(ios1), ios_writefd(ios2));
-
-#ifndef NDEBUG
- if (is_flag_set(VERY_VERBOSE_MODE) == TRUE)
- warn("File xfter mode: reading ios1 (remote) only");
-#endif
- } else {
- /* reading only from the local stream */
- FD_SET(ios_readfd(ios2), &read_fdset);
-
- /* close the remote stream for reading */
- ios_shutdown(ios1, SHUT_RD);
-
- /* don't stop because the read is closed */
- ios_set_hold_timeout(ios1, -1);
-
- /* close the local stream for writing */
- ios_shutdown(ios2, SHUT_WR);
-
- max_fd = MAX(ios_writefd(ios1), ios_readfd(ios2));
-
-#ifndef NDEBUG
- if (is_flag_set(VERY_VERBOSE_MODE) == TRUE)
- warn("File xfter mode: reading ios2 (local) only");
-#endif
- }
- } else {
- int temp;
-
- /* if we are not in file transfer mode, setup bidirectional
- * data transfers */
+ /* calculate max_fd and add initial fd's to be read from to read_fdset */
+ if (is_read_open(ios1)) {
+ /* read from ios1 */
FD_SET(ios_readfd(ios1), &read_fdset);
- FD_SET(ios_readfd(ios2), &read_fdset);
+ max_fd = MAX(ios_readfd(ios1), max_fd);
+ }
+ if (is_write_open(ios1))
+ max_fd = MAX(ios_writefd(ios1), max_fd);
- max_fd = MAX(ios_readfd(ios1), ios_writefd(ios1));
- temp = MAX(ios_readfd(ios2), ios_writefd(ios2));
- if (temp > max_fd) max_fd = temp;
+ if (is_read_open(ios2)) {
+ /* read from ios2 */
+ FD_SET(ios_readfd(ios2), &read_fdset);
+ max_fd = MAX(ios_readfd(ios2), max_fd);
}
-
+ if (is_write_open(ios2))
+ max_fd = MAX(ios_writefd(ios2), max_fd);
+
if (max_fd > FD_SETSIZE) {
[...2 lines suppressed...]
- Previous message: [ds6-devel] nc6/src parser.h,1.5,1.6 parser.c,1.8,1.9
- Next message: [ds6-devel]
nc6 nc6.spec.in,NONE,1.1 configure.ac,1.2,1.3 nc6.spec,1.5,NONE
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the ds6-devel
mailing list