Artifacts Associated With Ticket 1995063
Ticket change [784c3b8603] (rid 89937) by avl42 on 2008-06-16 12:06:40:
- assignee initialized to: "andreas_kupries"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The example event-handler procedure does check for eof on the channel, but doesn't close the channel, and would therefore cause a busy loop on eof. Suggestion: proc GetData {chan} { if {[eof $chan]} { close $chan; return } puts [gets $chan] } might be a more typical example. - foundin initialized to: "None"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "avl42"
- subsystem initialized to: "24. Channel Commands"
- title initialized to: "Doc: example in fileevent manpage is bad."
- type initialized to: "Bug"
Ticket change [833737e862] (rid 117355) by avl42 on 2008-06-16 19:07:28:
- priority changed to: "3 Low"
Ticket change [1cb2f13de2] (rid 90651) by dkf on 2008-06-16 20:07:41:
- icomment:
Logged In: YES user_id=79902 Originator: NO [eof] shouldn't be used until after the [gets] anyway. Better would be this: proc GetData {chan} { if {[gets $chan line] >= 0} { puts $line } elseif {[eof $chan]} { close $chan } } - login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [f521161eb4] (rid 130054) by avl42 on 2008-06-16 20:38:10:
- icomment:
Logged In: YES user_id=830354 Originator: YES ad dkf: huh? This "checking eof only after reading" is appropriate for while loops, where it's usually the reading command that causes the eof to be reached in the first place. fileevent-callbacks are also fired when previous gets returned with no eof-condition, but the channel died afterwards on peer's behalf. At that point, the eof- status for the channel is already set on entry of the handler, so no *need* to try a "gets", first. Of course, you can put another eof-check after the gets but that's redundant, because if eof occurred through "gets", then the handler is immediately called again, anyway, and that time eof is true already. Finally, if it's a writeable event, reading isn't a good idea either, nor is trying to "puts" something, when eof was already true before.
- login: "avl42"
- mimetype: "text/plain"
- username: "avl42"
- icomment:
Ticket change [f9ee3d0b1c] (rid 91781) by dkf on 2008-06-16 20:40:45:
- icomment:
Logged In: YES user_id=79902 Originator: NO Your proposal will add an extra blank line at the end, and this is an example of readable events.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [af3405ddee] (rid 97767) by ferrieux on 2008-06-16 21:06:59:
- icomment:
Logged In: YES user_id=496139 Originator: NO ad Andreas: huh ? > fileevent-callbacks are also fired when previous gets > returned with no eof-condition, but the channel died > afterwards on peer's behalf This is just plain wrong. [eof] is not updated until a read operation has been tried. To convince yourself of this: set n [open /dev/null r] ;# works with NUL: on Windows too fileevent $n readable {puts stderr EOF:[eof $n];close $n} => EOF:0 Hence the idiom proposed by Donal which is minimal, accurate (no extra empty line), and syscall-efficient ([eof] only reads memory). - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [743012858d] (rid 105166) by avl42 on 2008-06-16 21:59:15:
- icomment:
Logged In: YES user_id=830354 Originator: YES Oups. ok, you're right. Let's use Donal's version instead of the one currently in the manpage (which was even worse than my original correction attempt) Sorry for my previous wrong statement.
- login: "avl42"
- mimetype: "text/plain"
- username: "avl42"
- icomment:
Ticket change [82921ec543] (rid 117260) by flatworm on 2008-06-16 22:32:22:
- icomment:
Logged In: YES user_id=1350198 Originator: NO While the statement regarding EOF made by Donal and Alexander is correct, since [fileevent readable] handler is *necessarily* called on a non-blocking channel when a EOF condition is encountered, the whole problem just has no meaning: when I have proc Read chan { if {[eof $chan]} { close $chan ... } else { set data [read $chan] } } ... fileevent $chan readable [list Read $chan] in my code, [Read] will be called on EOF anyway. Just the event subsystem will make one extra invocation of the callback script. For instance, reading from a file of length 0 using a proc similar to that shown above will result in two invocations of the proc -- one for [read] which will return an empty string and one resulting from hitting EOF. So in fact it's not a big deal where checking for EOF is performed. - login: "flatworm"
- mimetype: "text/plain"
- username: "flatworm"
- icomment:
Ticket change [aa9de8b077] (rid 100956) by patthoyts on 2008-06-24 21:44:09:
- closedate changed to: "2008-06-24T14:44:09"
- closer changed to: "patthoyts"
- icomment:
Logged In: YES user_id=202636 Originator: NO flatworm: some channel implementations do not issue another round through the loop. iocpsock is one such. It's rather unfortunate and should be spelled out more strongly - read, then eof check. I've modified the fileevent.n page to provide better samples and commented on the eof testing.
- login: "patthoyts"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "patthoyts"