From: David G. <dav...@po...> - 2006-02-16 23:16:14
|
David Gravereaux wrote: > I want to do some experiments with sending an unending page and I need > to send parts of it at a time delaying through the event loop. I looked > at Httpd_ReturnFile and it's similar to what I want to do, but I won't > be using [fcopy], of course. > > Is there such a procedure that I missed spotting? Success of the DIY kind.. Attached are some procedures to do chunked data sending for domain handlers in replace of Httpd_ReturnData. It works: http://www.pobox.com/~davygrvy/chat That plays back an IRC log at triple speed and takes a few minutes to complete. A short example of its use would be the following. Notice that I use Httpd_ReturnDataChunkHeader in replace of Httpd_ReturnFile and that the callback script [ChatChunkHandler] sends a "chunk" at a time delaying through the event loop (non-blocking delay) until finished. Url_PrefixInstall /chat [list Chat /chat] -thread 1 set ChatDir [file dirname [info script]] proc Chat {prefix sock suffix} { global ChatDir upvar #0 Httpd$sock data # open the replay file and store it in the connection object. set f [open [file join $ChatDir datanew.txt]] fconfigure $f -encoding utf-8 set raw [read $f] close $f set data(chatLines) [split $raw \n] # get page html <head> block with opening <body> set firstChunk [ChatGetHeadStuff] # process first chat line foreach {delay line} [split [lindex $data(chatLines) 0] \t] {} set data(chatLines) [lreplace $data(chatLines) 0 0] append firstChunk $line Httpd_ReturnDataChunkHeader $sock text/html $firstChunk ChatChunkHandler } proc ChatChunkHandler {sock} { upvar #0 Httpd$sock data set delay 0 set line "" # process next chat line foreach {delay line} [split [lindex $data(chatLines) 0] \t] {} set data(chatLines) [lreplace $data(chatLines) 0 0] set delay [expr {int($delay/3.0)}] if {[llength $data(chatLines)] != 0} { after $delay [list Httpd_ReturnDataChunkBody $sock $line ChatChunkHandler] } else { unset data(chatLines) after $delay [list Httpd_ReturnDataChunkLast $sock $line] } } proc ChatGetHeadStuff {} { return {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <META NAME="Generator" CONTENT="IRC_Engine"> <TITLE>Live on Internet Relay Chat</TITLE> <style type="text/css"> ..... </style> </head> <body text="#C0C0C0" bgcolor="#000000"> } } |