Overview
| Artifact ID: | 400771fad18b6664648d7a3fad42deef7fe6c06d |
|---|---|
| Ticket: | 2827000fffffffffffffffffffffffffffffffff
tcl incorrectly reports eof to application |
| User & Date: | andreas_kupries on 2009-07-28 10:01:09 |
Changes
- icomment:
Behaviour of testRefChan.tcl ... NOTE: The implementation of 'watch' was missing. This is crucical. You have to look at the watch calls to see if _you_ (The rc channel implementation) is expected to generate events, or not. See steps 3, 7, and 15. NOTE 2: The handling of eof in getter/reader fell through to regular read, I added exit commands there. NOTE 3: The modified test script is attached. (.1) Create channel RC (.2) Set channel RC to blocking --> (.3) Set up a fileevent receiver for RC -> getter. This invokes rc::watch, asking for read events, this posts a readable event. (.4) The readable event is received and 'getter' called. (.5) The 'gets' command in 'getter' finds empty buffers and calls the channel's inputProc -> ReflectInput -> procedure rc::read. (.6) rc::read returns 221 bytes, 10 lines of '111...', an empty line, 10 lines of '222...'. (.7) As part of the inputProc processing interest in read-events from the channel is disabled. We have data in the Tcl buffers, these will get flushed first. No need to ask for events from the OS (=== the reflected channel). (.8) The IO core returns the first '111...' line as result of 'gets'. (.9) The IO core generates its own fileevents, based on timers, to flush the data left over in the Tcl buffers (remaining '111...' etc. lines. (10) Per (.9) 'getter' is called, the cycle repeats. (11) At the 11th call 'gets' returns an empty line, and the event receiver switches to 'reader'. This doesn't change that data in the buffers is flushed via timer-based fileevents, there are still the '222...' lines etc. (12) 'reader' is called, for the first of the events after the switch-over. (13) It tries to [read 10000]. As only less bytes than that are left in the Tcl buffers the channel's inputProc is called to sdee that we fill it up with more data => ReflectInput => rc::read. This is the so-called bogus call, and it is not bogus, but completely correct. (14) This call returns 0 bytes, and the EOF flag in the channel is set. (15) The IO core now __re-enables__ interest in the 'readable' events because all data in the Tcl buffers will be delivered to the script, and any more data will have to come from the channel itself. <=> Any more events have to come from the channel as well, the timer-based events are stopped. (16) The read call returns the remaining bytes from the Tcl buffers. At this point the script stops for me with can't wait for variable "forever": would wait forever because the RC channel implementation did not set things up to produce its own events, despite being asked to in step 15, via rc::watch. The moment we do this the posted event causes another call of 'reader' sa step (17), which then handles the eof condition by closing the channel, which disables events, finalizes, and exits. The last is something I added to the script. Now, what does that mean for the identity refchan ? It has to keep track of when the Tcl IO core wants events from it or not. If it receives a fileevent from the socket it is connected to at a time the core is not interested in identity events, then this event has to be remembered in flags (one per read and write), but not be acted on, i.e no posting forward to the core. Only when events are enabled again for the identity chan the flags have to be checked, and if we got events from the socket we post _one_ event forward. - login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"