Attachment "noread_write_channel.patch2" to
ticket [496733ffff]
added by
mdejong
2002-01-26 07:30:58.
2002-01-25 Mo DeJong <[email protected]>
Make -eofchar and -translation options read only for
server sockets. [Bug 496733]
* generic/tclIO.c (Tcl_GetChannelOption, Tcl_SetChannelOption):
Instead of returning nothing for the -translation option
on a server socket, always return "auto". Return the empty
string enclosed in quotes for the -eofchar option on
a server socket. Fixup -eofchar usage message so that
it matches the implementation.
* tests/io.test: Add -eofchar tests and -translation tests
to ensure options are read only on server sockets.
* tests/socket.test: Update tests to account for -eofchar
and -translation option changes.
Index: generic/tclIO.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIO.c,v
retrieving revision 1.49
diff -u -r1.49 tclIO.c
--- generic/tclIO.c 2002/01/25 20:40:55 1.49
+++ generic/tclIO.c 2002/01/25 23:01:20
@@ -6096,6 +6096,10 @@
Tcl_DStringAppendElement(dsPtr, buf);
}
}
+ if ( !(flags & (TCL_READABLE|TCL_WRITABLE))) {
+ /* Not readable or writable (server socket) */
+ Tcl_DStringAppendElement(dsPtr, "");
+ }
if (((flags & (TCL_READABLE|TCL_WRITABLE)) ==
(TCL_READABLE|TCL_WRITABLE)) && (len == 0)) {
Tcl_DStringEndSublist(dsPtr);
@@ -6136,6 +6140,10 @@
Tcl_DStringAppendElement(dsPtr, "lf");
}
}
+ if ( !(flags & (TCL_READABLE|TCL_WRITABLE))) {
+ /* Not readable or writable (server socket) */
+ Tcl_DStringAppendElement(dsPtr, "auto");
+ }
if (((flags & (TCL_READABLE|TCL_WRITABLE)) ==
(TCL_READABLE|TCL_WRITABLE)) && (len == 0)) {
Tcl_DStringEndSublist(dsPtr);
@@ -6305,8 +6313,8 @@
} else if (argc != 2) {
if (interp) {
Tcl_AppendResult(interp,
- "bad value for -eofchar: should be a list of one or",
- " two elements", (char *) NULL);
+ "bad value for -eofchar: should be a list of zero,",
+ " one, or two elements", (char *) NULL);
}
ckfree((char *) argv);
return TCL_ERROR;
Index: tests/io.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/io.test,v
retrieving revision 1.23
diff -u -r1.23 io.test
--- tests/io.test 2002/01/21 20:38:06 1.23
+++ tests/io.test 2002/01/25 23:01:22
@@ -5028,6 +5028,37 @@
close $s2
set modes
} {auto crlf}
+test io-39.22 {Tcl_SetChannelOption, invariance} {
+ removeFile test1
+ set f1 [open test1 w+]
+ set l ""
+ lappend l [fconfigure $f1 -eofchar]
+ fconfigure $f1 -eofchar {ON GO}
+ lappend l [fconfigure $f1 -eofchar]
+ fconfigure $f1 -eofchar D
+ lappend l [fconfigure $f1 -eofchar]
+ lappend l [list [catch {fconfigure $f1 -eofchar {1 2 3}} msg] $msg]
+ close $f1
+ set l
+} {{{} {}} {O G} {D D}\
+{1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
+test io-39.23 {Tcl_GetChannelOption, server socket is not readable or
+ writeable, it should still have valid -eofchar and -translation options } {
+ set l [list]
+ set sock [socket -server accept 0]
+ lappend l [fconfigure $sock -eofchar] [fconfigure $sock -translation]
+ close $sock
+ set l
+} {{{}} auto}
+test io-39.24 {Tcl_SetChannelOption, server socket is not readable or
+ writable so we can't change -eofchar or -translation } {
+ set l [list]
+ set sock [socket -server accept 0]
+ fconfigure $sock -eofchar D -translation lf
+ lappend l [fconfigure $sock -eofchar] [fconfigure $sock -translation]
+ close $sock
+ set l
+} {{{}} auto}
test io-40.1 {POSIX open access modes: RDWR} {
removeFile test3
Index: tests/socket.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/socket.test,v
retrieving revision 1.20
diff -u -r1.20 socket.test
--- tests/socket.test 2001/10/12 19:45:08 1.20
+++ tests/socket.test 2002/01/25 23:01:23
@@ -847,7 +847,7 @@
close $s
update
llength $l
-} 12
+} 14
test socket-7.4 {testing socket specific options} {socket} {
set s [socket -server accept 0]
proc accept {s a p} {