tlsAuto.tcl at [f1e28695f2]

File tests/tlsAuto.tcl artifact 2f26c4f54d part of check-in f1e28695f2


#
# Copyright (C) 1997-2000 Matt Newman <[email protected]>
#
# $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tests/Attic/tlsAuto.tcl,v 1.2 2000/01/20 01:56:18 aborr Exp $
#

set dir [file dirname [info script]]
cd $dir
source tls.tcl

proc fromServer {chan} {
    if {[catch {read $chan 10} data]} {
	catch {close $chan}
	tclLog "EOF ($data)"
	set ::/Exit 1
	return
    }
    if {[eof $chan]} {
	close $chan
	set ::/Exit 1
    }
    if {$data != ""} {
	puts -nonewline stderr "$data"
    }
}
proc doit {chan count {delay 1000}} {
    if {$count == 0} {
	close $chan
	set ::/Exit 0
	return
    }
    puts $chan line$count
    flush $chan

    incr count -1
    after $delay doit $chan $count $delay
}
array set opts {
    -port	1234
    -host	localhost
}
array set opts $argv
#
# Initialize context
#
#tls::init -certfile client.pem -cafile server.pem ;#-cipher RC4-MD5
tls::init
#
# Create socket and import SSL layer
#
#set chan [tls::socket -async -request 0 $opts(-host) $opts(-port)]
set chan [tls::socket -request 0 $opts(-host) $opts(-port)]

fconfigure $chan -buffering none -blocking 0 -translation binary
fileevent $chan readable [list fromServer $chan]

doit $chan 1000 100
vwait /Exit