ns_log Notice "In bgwrite/init.tcl" # try out tcl threads ns_ictl package require Thread # Variables to use to find threads: nsv_set thread count 0 nsv_set thread id [thread::create { global begin global done proc send_file {channel file method} { global begin set begin true set start [clock clicks -milliseconds] ns_log Notice "T start $channel for [file tail $file]" set contentLength [file size $file] set contentType [ns_guesstype $file] set lastModified [ns_httptime [file mtime $file]] set header "HTTP/1.1 200 OK Last-Modified: $lastModified MIME-Version: 1.0 Date: [ns_httptime [ns_time]] Server: AOLserver/4.5.0 Content-Type: $contentType Content-Length: $contentLength Connection: close " fconfigure $channel -translation binary if {"$method" eq "head"} { puts $channel $header close $channel ns_log Notice "Serviced Head Request on $channel for $file" return } set inFd [open $file r] fconfigure $inFd -translation binary puts $channel $header fcopy $inFd $channel -command [list logResult $file $channel $inFd] # vwait til done is written in logResult vwait done set end [clock clicks -milliseconds] ns_log Notice "T end $channel in [expr $end - $start] ms\n" } proc logResult {file channel inFd {bytes 0} {errorString ""}} { global done close $channel close $inFd if {"" eq "$errorString"} { ns_log Notice "T wrote $bytes B to $channel from [file tail $file]" } else { ns_log Error "T err writing to $channel from $file did $bytes" } set done done } # Required to wait for events: thread::wait }]