connect.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 package require snit
00012
00013
00014
00015
00016 snit::type ::transfer::connect {
00017
00018
00019
00020
00021 option -host localhost
00022 option -port 0
00023 option -mode active
00024
00025 option -translation {}
00026 option -encoding {}
00027 option -eofchar {}
00028
00029 ret connect (type command) {}
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 ret connect (type command) {
00041 if {$options(-mode) eq "active"} {
00042
00043 set sock [socket $options(-host) $options(-port)]
00044 $self Setup $sock
00045
00046 lappend command $self $sock
00047 uplevel \#0 $command
00048 return
00049 } else {
00050 set server [socket -server [mymethod Start $command] \
00051 $options(-port)]
00052
00053 return [lindex [fconfigure $server -sockname] 2]
00054 }
00055 return
00056 }
00057
00058 ret Start (type command , type sock , type peerhost , type peerport) {
00059 close $server
00060 $self Setup $sock
00061
00062 lappend command $self $sock
00063 uplevel \#0 $command
00064 return
00065 }
00066
00067 ret Setup (type sock) {
00068 foreach o {-translation -encoding -eofchar} {
00069 if {$options($o) eq ""} continue
00070 fconfigure $sock $o $options($o)
00071 }
00072 return
00073 }
00074
00075
00076
00077
00078 onconfigure -mode {newvalue} {
00079 upvar 0 options(-mode) value
00080 if {$value eq $newvalue} return
00081 switch -exact -- $newvalue {
00082 passive - active {
00083 value = $newvalue
00084 }
00085 default {
00086 return -code error "Bad value \"$newvalue\", expected active, or passive"
00087 }
00088 }
00089 return
00090 }
00091
00092
00093
00094
00095 variable server {}
00096
00097
00098
00099
00100 }
00101
00102
00103
00104
00105 package provide transfer::connect 0.1
00106