From: patthoyts Date: Thu, 19 May 2005 15:41:05 +0000 (+0000) Subject: * generic/udp_tcl.c: fconfigure options were returning lists of X-Git-Tag: tcludp-1_0_7~5 X-Git-Url: http://privyetmir.co.uk/gitweb?a=commitdiff_plain;h=0a32bebf7b6f249be581d2e93638b5aa5e275c04;p=tcludp * generic/udp_tcl.c: fconfigure options were returning lists of lists. Fixed. --- diff --git a/ChangeLog b/ChangeLog index b1c3496..4059a76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * generic/udp_tcl.c: Deal with bug #1178996 by changing the code used to cleanup sockets under Windows. + * generic/udp_tcl.c: fconfigure options were returning lists of + lists. Fixed. 2005-05-17 Pat Thoyts diff --git a/demos/multicast.tcl b/demos/multicast.tcl index ff4414d..daec247 100644 --- a/demos/multicast.tcl +++ b/demos/multicast.tcl @@ -12,7 +12,8 @@ package require udp 1.0.6 proc udpEvent {chan} { set data [read $chan] set peer [fconfigure $chan -peer] - puts "$peer [string length $data] '$data'" + set group [lindex [fconfigure $chan -remote] 0] + puts "$peer ($group) [string length $data] '$data' {[fconfigure $chan]}" if {[string match "QUIT*" $data]} { close $chan set ::forever 1 @@ -21,13 +22,18 @@ proc udpEvent {chan} { } # Select a multicast group and the port number. -set group 224.5.1.21 -set port 7771 +# +# We have two groups here to show that it's possible. +# +set group1 224.5.1.21 +set group2 224.5.2.21 +set port 7771 # Create a listening socket and configure for sending too. set s [udp_open $port] fconfigure $s -buffering none -blocking 0 -fconfigure $s -mcastadd $group -remote [list $group $port] +fconfigure $s -mcastadd $group1 -remote [list $group1 $port] +fconfigure $s -mcastadd $group2 -remote [list $group2 $port] fileevent $s readable [list udpEvent $s] # Announce our presence and run diff --git a/generic/udp_tcl.c b/generic/udp_tcl.c index e427731..3c51bf2 100644 --- a/generic/udp_tcl.c +++ b/generic/udp_tcl.c @@ -1177,23 +1177,24 @@ udpGetOption(ClientData instanceData, Tcl_Interp *interp, CONST84 char *optionName, Tcl_DString *optionValue) { UdpState *statePtr = (UdpState *)instanceData; - CONST84 char * options = "myport remote peer mcastgroups broadcast ttl"; + const char * options[] = { "myport", "remote", "peer", "mcastgroups", "broadcast", "ttl", NULL}; int r = TCL_OK; if (optionName == NULL) { - - Tcl_DStringAppend(optionValue, " -myport ", -1); - udpGetOption(instanceData, interp, "-myport", optionValue); - Tcl_DStringAppend(optionValue, " -remote ", -1); - udpGetOption(instanceData, interp, "-remote", optionValue); - Tcl_DStringAppend(optionValue, " -peer ", -1); - udpGetOption(instanceData, interp, "-peer", optionValue); - Tcl_DStringAppend(optionValue, " -mcastgroups ", -1); - udpGetOption(instanceData, interp, "-mcastgroups", optionValue); - Tcl_DStringAppend(optionValue, " -broadcast ", -1); - udpGetOption(instanceData, interp, "-broadcast", optionValue); - Tcl_DStringAppend(optionValue, " -ttl ", -1); - udpGetOption(instanceData, interp, "-ttl", optionValue); + Tcl_DString ds; + const char **p; + + Tcl_DStringInit(&ds); + for (p = options; *p != NULL; p++) { + char op[16]; + sprintf(op, "-%s", *p); + Tcl_DStringSetLength(&ds, 0); + udpGetOption(instanceData, interp, op, &ds); + Tcl_DStringAppend(optionValue, " ", 1); + Tcl_DStringAppend(optionValue, op, -1); + Tcl_DStringAppend(optionValue, " ", 1); + Tcl_DStringAppendElement(optionValue, Tcl_DStringValue(&ds)); + } } else { @@ -1262,11 +1263,17 @@ udpGetOption(ClientData instanceData, Tcl_Interp *interp, } } else { - r = Tcl_BadChannelOption(interp, optionName, options); + CONST84 char **p; + Tcl_DString tmp; + Tcl_DStringInit(&tmp); + for (p = options; *p != NULL; p++) + Tcl_DStringAppendElement(&tmp, *p); + r = Tcl_BadChannelOption(interp, optionName, Tcl_DStringValue(&tmp)); + Tcl_DStringFree(&tmp); } if (r == TCL_OK) { - Tcl_DStringAppendElement(optionValue, Tcl_DStringValue(&ds)); + Tcl_DStringAppend(optionValue, Tcl_DStringValue(&ds), -1); } Tcl_DStringFree(&dsInt); Tcl_DStringFree(&ds); diff --git a/win/tcludp.dsp b/win/tcludp.dsp index 1d7ae3b..7f9d5e5 100644 --- a/win/tcludp.dsp +++ b/win/tcludp.dsp @@ -62,9 +62,9 @@ CFG=tcludp - Win32 Debug # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" -# PROP Cmd_Line "nmake /f makefile.vc INSTALLDIR=c:\opt\tcl OPTS=symbols all" -# PROP Rebuild_Opt "/a" -# PROP Target_File "Debug/udp106g.dll" +# PROP Cmd_Line "nmake /f makefile.vc INSTALLDIR=c:\opt\tcl\site-lib OPTS=symbols all" +# PROP Rebuild_Opt "realclean all" +# PROP Target_File "Debug/udp107g.dll" # PROP Bsc_Name "" # PROP Target_Dir ""