Tcl Library Source Code

Check-in [a0a2c6e9ca]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add end-of-file handling to halfpipe.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a0a2c6e9cac723e205f1b6f972b2be2425b4c0fc6b193ba2657c1074b313320c
User & Date: pooryorick 2022-01-25 16:49:04.753
Context
2022-03-09
21:35
sha1: Pass to the compiler the path to the local .h files. check-in: cecfc78bcd user: pooryorick tags: trunk
2022-03-06
16:06
Changes to accomodate an accelerated version. check-in: 1941af032d user: pooryorick tags: module-aes
2022-01-25
16:49
Add end-of-file handling to halfpipe. check-in: a0a2c6e9ca user: pooryorick tags: trunk
2022-01-18
07:43
coroutine: Reduce quoting and add procedure markers. check-in: cb716671f7 user: pooryorick tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to modules/virtchannel_base/halfpipe.tcl.
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
}

oo::class create ::tcl::chan::halfpipe::implementation {
    superclass ::tcl::chan::events ; # -> initialize, finalize, watch

    method initialize {args} {
	my allow write

	next {*}$args
    }

    method finalize {c} {
	my Call -close-command $c
	next $c
    }

    method read {c n} {
	set max  [string length $read]
	set last [expr {$at + $n - 1}]
	set result {}
	
	#    last+1 <= max
	# <=> at+n <= max
	# <=> n <= max-at

	if {$n <= ($max - $at)} {
	    # The request is less than what we have left in the read
	    # buffer, we take it, and move the read pointer forward.

	    append result [string range $read $at $last]
	    incr at $n
	    incr $size -$n
	} else {
	    # We need the whole remaining read buffer, and more. For
	    # the latter we make the write buffer the new read buffer,







>


















|
|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
}

oo::class create ::tcl::chan::halfpipe::implementation {
    superclass ::tcl::chan::events ; # -> initialize, finalize, watch

    method initialize {args} {
	my allow write
	set eof 0
	next {*}$args
    }

    method finalize {c} {
	my Call -close-command $c
	next $c
    }

    method read {c n} {
	set max  [string length $read]
	set last [expr {$at + $n - 1}]
	set result {}
	
	#    last+1 <= max
	# <=> at+n <= max
	# <=> n <= max-at

	if {$n <= ($max - $at)} {
	    # There is enough data in the buffer to fill the request, so take
	    # it from there and move the read pointer forward.

	    append result [string range $read $at $last]
	    incr at $n
	    incr $size -$n
	} else {
	    # We need the whole remaining read buffer, and more. For
	    # the latter we make the write buffer the new read buffer,
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121




122

123
124
125
126
127
128
129
130

131
132
133
134
135
136
137
		append result $read

		set at   0
		set read {}
		set size 0
	    }
	}

	my Readable

	if {$result eq {}} {
	    return -code error EAGAIN
	}

	return $result
    }

    method write {c bytes} {
	my Call -write-command $c $bytes
	return [string length $bytes]
    }

    # # ## ### ##### ######## #############

    method put {bytes} {
	append write $bytes
	set n [string length $bytes]




	incr size $n

	my Readable
	return $n
    }

    # # ## ### ##### ######## #############

    variable at read write size options
    # at      : first location in read buffer not yet read

    # read    : read buffer
    # write   : buffer for received data, i.e.
    #           written into the halfpipe from
    #           the other side.
    # size    : combined length of receive and read buffers
    #           == amount of stored data
    # options : configuration array







<

<
|


<










|


>
>
>
>
|
>






|

>







96
97
98
99
100
101
102

103

104
105
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
		append result $read

		set at   0
		set read {}
		set size 0
	    }
	}

	my Readable

	if {$result eq {} && !$eof} {
	    return -code error EAGAIN
	}

	return $result
    }

    method write {c bytes} {
	my Call -write-command $c $bytes
	return [string length $bytes]
    }

    # # ## ### ##### ######## #############

    method put bytes {
	append write $bytes
	set n [string length $bytes]
	if {$n == 0} {
	    my variable eof
	    set eof 1
	} else {
	    incr size $n
	}
	my Readable
	return $n
    }

    # # ## ### ##### ######## #############

    variable at eof read write size options
    # at      : first location in read buffer not yet read
    # eof     : indicates whether the end of the data has been reached 
    # read    : read buffer
    # write   : buffer for received data, i.e.
    #           written into the halfpipe from
    #           the other side.
    # size    : combined length of receive and read buffers
    #           == amount of stored data
    # options : configuration array
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	set read  {}
	set write {}
	set size  0
	next
    }

    method Readable {} {
	if {$size} {
	    my allow read
	} else {
	    my variable channel
	    my disallow read
	    my Call -empty-command $channel
	}
	return







|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
	set read  {}
	set write {}
	set size  0
	next
    }

    method Readable {} {
	if {$size || $eof} {
	    my allow read
	} else {
	    my variable channel
	    my disallow read
	    my Call -empty-command $channel
	}
	return