From d978b281786e2e6cdc974a2b55cbe72bf06ba07d Mon Sep 17 00:00:00 2001 From: patthoyts Date: Tue, 10 Apr 2007 23:36:14 +0000 Subject: [PATCH] Use winsock2 so that mingw-gcc can get the correct values for multicast. --- demos/chat.tcl | 24 ++++++++++++++++++------ generic/udp_tcl.c | 4 ++-- generic/udp_tcl.h | 3 ++- win/makefile.vc | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/demos/chat.tcl b/demos/chat.tcl index acef698..4818058 100644 --- a/demos/chat.tcl +++ b/demos/chat.tcl @@ -2,8 +2,8 @@ # # This is a sample application from TclUDP. # -# This illustrates the use of multicast UDP messages to implement a primitive chat -# application. +# This illustrates the use of multicast UDP messages to implement a +# primitive chat application. # # $Id$ @@ -33,7 +33,8 @@ proc CreateGui {socket} { scrollbar .s -command {.t yview} frame .f -border 0 entry .f.e -textvariable ::_msg - button .f.ok -text Send -underline 0 -command "SendMessage $socket \$::_msg" + button .f.ok -text Send -underline 0 \ + -command "SendMessage $socket \$::_msg" button .f.ex -text Exit -underline 1 -command {destroy .} pack .f.ex .f.ok -side right pack .f.e -side left -expand 1 -fill x @@ -43,6 +44,7 @@ proc CreateGui {socket} { grid rowconfigure . 0 -weight 1 bind .f.e {.f.ok invoke} .t tag configure CLNT -foreground red + .t configure -tabs {90} } proc SendMessage {sock msg} { @@ -53,16 +55,26 @@ proc AddMessage {client msg} { set msg [string map [list "\r\n" "" "\r" "" "\n" ""] $msg] set client [lindex $client 0] if {[string length $msg] > 0} { - .t insert end "$client " CLNT "$msg\n" MSG + .t insert end "$client\t" CLNT "$msg\n" MSG + .t see end } } -if {!$tcl_interactive} { +proc Main {} { + variable Address + variable Port + variable sock set sock [Start $Address $Port] CreateGui $sock - after idle [list SendMessage $sock "$::tcl_platform(user)@[info hostname] connected"] + after idle [list SendMessage $sock \ + "$::tcl_platform(user)@[info hostname] connected"] tkwait window . close $sock +} + +if {!$tcl_interactive} { + set r [catch [linsert $argv 0 Main] err] + if {$r} {puts $::errorInfo} else {puts $err} exit 0 } diff --git a/generic/udp_tcl.c b/generic/udp_tcl.c index 44a82bc..3b2cb66 100644 --- a/generic/udp_tcl.c +++ b/generic/udp_tcl.c @@ -730,7 +730,7 @@ SocketThread(LPVOID arg) /* set each socket for select */ for (statePtr = sockList; statePtr != NULL; statePtr=statePtr->next) { - FD_SET(statePtr->sock, &readfds); + FD_SET((unsigned int)statePtr->sock, &readfds); UDPTRACE("SET sock %d\n", statePtr->sock); } @@ -1203,7 +1203,7 @@ UdpMulticast(ClientData instanceData, Tcl_Interp *interp, mreq.imr_interface.s_addr = INADDR_ANY; if (setsockopt(statePtr->sock, IPPROTO_IP, action, (const char*)&mreq, sizeof(mreq)) < 0) { - Tcl_SetObjResult(interp, ErrorToObj("error changing multicast group")); + Tcl_SetObjResult(interp, ErrorToObj("error changing multicast group")); return TCL_ERROR; } diff --git a/generic/udp_tcl.h b/generic/udp_tcl.h index ed14595..8359c7e 100644 --- a/generic/udp_tcl.h +++ b/generic/udp_tcl.h @@ -27,7 +27,8 @@ #endif #ifdef WIN32 -# include +# include +# include #else # if HAVE_UNISTD_H # include diff --git a/win/makefile.vc b/win/makefile.vc index a1e00c4..38fb04e 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -281,7 +281,7 @@ lflags = $(lflags) -ws:aggressive dlllflags = $(lflags) -dll conlflags = $(lflags) -subsystem:console guilflags = $(lflags) -subsystem:windows -baselibs = $(TCLSTUBLIB) wsock32.lib +baselibs = $(TCLSTUBLIB) ws2_32.lib #--------------------------------------------------------------------- # TclTest flags -- 2.23.0