1 # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3 # $Id: Readdata.tcl,v 1.2 2002-09-07 05:21:42 mikeclarkson Exp $
5 ###### Readdata.tcl ######
6 ############################################################
7 # Netmath Copyright (C) 1998 William F. Schelter #
8 # For distribution under GNU public License. See COPYING. #
9 ############################################################
14 #-----------------------------------------------------------------
16 # readDataTilEof -- read data from CHANNEL appending to VAR
17 # allowing no more than TIMEOUT milliseconds between reads.
19 # Results: 1 on success, and -1 if it fails or times out.
21 # Side Effects: CHANNEL will be closed and the global variable VAR will
24 #----------------------------------------------------------------
26 proc readDataTilEof
{ channel var timeout
} {
27 global readDataDone_ _readDataData
34 set after_id
[after $timeout "set readDataDone_ -1"]
35 fconfigure $channel -blocking 0
36 fileevent $channel readable
\
37 [list readDataTilEof1
$channel _readDataData
$timeout $after_id]
40 after cancel
$after_id
41 catch { close $channel}
42 set res
$readDataDone_
43 if {$res > 0 } { append variable $_readDataData }
47 proc readDataTilEof1
{ channel var timeout after_id
} {
48 global readDataDone_
$var
50 set new
[read $channel]
53 if { [eof $channel] } {
57 after cancel
$after_id
58 after $timeout "set readDataDone_ -1"
63 ## endsource Readdata.tcl