Skip to content
Tcl Source Code History Of Ticket 1995063
Login

History Of Ticket 1995063

Artifacts Associated With Ticket 1995063

  1. Ticket change [784c3b8603] (rid 89937) by avl42 on 2008-06-16 12:06:40:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. 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.
      
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "avl42"
    10. subsystem initialized to: "24. Channel Commands"
    11. title initialized to: "Doc: example in fileevent manpage is bad."
    12. type initialized to: "Bug"
  2. Ticket change [833737e862] (rid 117355) by avl42 on 2008-06-16 19:07:28:

    1. priority changed to: "3 Low"
  3. Ticket change [1cb2f13de2] (rid 90651) by dkf on 2008-06-16 20:07:41:

    1. 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
           }
        }
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  4. Ticket change [f521161eb4] (rid 130054) by avl42 on 2008-06-16 20:38:10:

    1. 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.
      
      
      
      
    2. login: "avl42"
    3. mimetype: "text/plain"
    4. username: "avl42"
  5. Ticket change [f9ee3d0b1c] (rid 91781) by dkf on 2008-06-16 20:40:45:

    1. 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.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  6. Ticket change [af3405ddee] (rid 97767) by ferrieux on 2008-06-16 21:06:59:

    1. 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).
      
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  7. Ticket change [743012858d] (rid 105166) by avl42 on 2008-06-16 21:59:15:

    1. 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.
      
      
    2. login: "avl42"
    3. mimetype: "text/plain"
    4. username: "avl42"
  8. Ticket change [82921ec543] (rid 117260) by flatworm on 2008-06-16 22:32:22:

    1. 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.
      
      
    2. login: "flatworm"
    3. mimetype: "text/plain"
    4. username: "flatworm"
  9. Ticket change [aa9de8b077] (rid 100956) by patthoyts on 2008-06-24 21:44:09:

    1. closedate changed to: "2008-06-24T14:44:09"
    2. closer changed to: "patthoyts"
    3. 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.
      
      
    4. login: "patthoyts"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "patthoyts"