os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/remote.tcl
Update contrib.
1 # This file contains Tcl code to implement a remote server that can be
2 # used during testing of Tcl socket code. This server is used by some
3 # of the tests in socket.test.
5 # Source this file in the remote server you are using to test Tcl against.
7 # Copyright (c) 1995-1996 Sun Microsystems, Inc.
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 # RCS: @(#) $Id: remote.tcl,v 1.3 1999/04/16 00:47:33 stanton Exp $
14 # Initialize message delimitor
16 # Initialize command array
21 # Detect whether we should print out connection messages etc.
22 if {![info exists VERBOSE]} {
26 proc __doCommands__ {l s} {
27 global callerSocket VERBOSE
30 puts "--- Server executing the following for socket $s:"
35 if {[catch {uplevel #0 $l} msg]} {
42 proc __readAndExecute__ {s} {
43 global command VERBOSE
46 if {[string compare $l "--Marker--Marker--Marker--"] == 0} {
47 if {[info exists command($s)]} {
48 puts $s [list error incomplete_command]
50 puts $s "--Marker--Marker--Marker--"
53 if {[string compare $l ""] == 0} {
56 puts "Server closing $s, eof from client"
62 append command($s) $l "\n"
63 if {[info complete $command($s)]} {
66 puts $s [__doCommands__ $cmds $s]
70 puts "Server closing $s, eof from client"
76 proc __accept__ {s a p} {
80 puts "Server accepts new connection from $a:$p on $s"
82 fileevent $s readable [list __readAndExecute__ $s]
83 fconfigure $s -buffering line -translation crlf
87 for {set i 0} {$i < $argc} {incr i} {
88 if {[string compare -serverIsSilent [lindex $argv $i]] == 0} {
93 if {![info exists serverPort]} {
94 if {[info exists env(serverPort)]} {
95 set serverPort $env(serverPort)
98 if {![info exists serverPort]} {
99 for {set i 0} {$i < $argc} {incr i} {
100 if {[string compare -port [lindex $argv $i]] == 0} {
101 if {$i < [expr $argc - 1]} {
102 set serverPort [lindex $argv [expr $i + 1]]
108 if {![info exists serverPort]} {
112 if {![info exists serverAddress]} {
113 if {[info exists env(serverAddress)]} {
114 set serverAddress $env(serverAddress)
117 if {![info exists serverAddress]} {
118 for {set i 0} {$i < $argc} {incr i} {
119 if {[string compare -address [lindex $argv $i]] == 0} {
120 if {$i < [expr $argc - 1]} {
121 set serverAddress [lindex $argv [expr $i + 1]]
127 if {![info exists serverAddress]} {
128 set serverAddress 0.0.0.0
131 if {$serverIsSilent == 0} {
132 set l "Remote server listening on port $serverPort, IP $serverAddress."
135 for {set c [string length $l]} {$c > 0} {incr c -1} {puts -nonewline "-"}
138 puts "You have set the Tcl variables serverAddress to $serverAddress and"
139 puts "serverPort to $serverPort. You can set these with the -address and"
140 puts "-port command line options, or as environment variables in your"
143 puts "NOTE: The tests will not work properly if serverAddress is set to"
144 puts "\"localhost\" or 127.0.0.1."
146 puts "When you invoke tcltest to run the tests, set the variables"
147 puts "remoteServerPort to $serverPort and remoteServerIP to"
148 puts "[info hostname]. You can set these as environment variables"
149 puts "from the shell. The tests will not work properly if you set"
150 puts "remoteServerIP to \"localhost\" or 127.0.0.1."
152 puts -nonewline "Type Ctrl-C to terminate--> "
156 if {[catch {set serverSocket \
157 [socket -myaddr $serverAddress -server __accept__ $serverPort]} msg]} {
158 puts "Server on $serverAddress:$serverPort cannot start: $msg"
160 vwait __server_wait_variable__