Tcl Source Code

View Ticket
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA
Ticket UUID: 219159
Title: Need to split bidirectional channels (sockets; pipes or devi
Type: Patch Version: None
Submitter: nobody Created on: 2000-10-26 05:02:26
Subsystem: 25. Channel System Assigned To: andreas_kupries
Priority: 6 Severity:
Status: Open Last Modified: 2008-12-18 20:30:18
Resolution: None Closed By:
    Closed on:
OriginalBugID: 1429 RFE
Version: 8.0.4
SubmitDate: '1999-03-04'
LastModified: '2000-05-04'
Severity: SER
Status: Assigned
Submitter: pat
ChangedBy: hobbs
RelatedBugIDs: 5339
OS: Other
Machine: NA
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'

Alexandre FERRIEUX

    The Tcl Channel model is a useful abstraction, that effectively tries to
    wipe out many OS peculiarities. However, the particular case of
    "bidirectional" channels (e.g. pipes in "r+" mode) is somewhat tricky:
    in this case a single channel hides *two* OS-level descriptors/handles.
    The problem is that most configuration operations apply to both
    simultaneously, which is not always wanted.
     For example, [fconfigure -blocking 0] cannot be told to only the write
    side of an r+ pipe. Also, as already noted on clt, you cannot close only
    the write side, so that the child gets an EOF, then listen to its last
    words on the read side: both are closed at the same time. A slightly
    different case is that of sockets, which are indeed made of a single
    bidirectional descriptor. Still, it would be very useful (for the same
    reasons) to be able to issue a half-close, as is possible with the
    shutdown() syscall.
    Proposed unified syntax for this extension: a "-readside/-writeside"
    option to the [close] and [fconfigure] commands.

5339 discusses the separation of r/w for close. 
-- 05/04/2000 hobbs
User Comments: ferrieux added on 2008-12-18 20:30:18:
Thanks Donal, nice idiom.
Please rather followup on this issue in 2444274.

dkf added on 2008-12-18 18:50:42:
I've converted the 'if 0's into 'knownBug' constraints. (Can't chase Win problems further at the moment; away from my Win box...)

ferrieux added on 2008-12-18 08:18:59:
Committed to HEAD this patch augmented by appropriate additions in chan.n and chanio.test.
There still are two problems to fix quickly:
 (1) A half-close-write on unflushed data crashes. This is because we reset internal fields too quickly, and the flushing occurs with a NULL client data pointer. The workaround is to flush before [close w]. Used in the test.
 (2) On Windows the half-close test in chanio.test fails with ECONNRESET. So I wrapped it in an if {0}.

andreas_kupries added on 2008-12-10 03:45:42:
Ok. Thanks.

ferrieux added on 2008-12-09 23:40:43:
Now that the TIP has been accepted, starting from your halfclose-5.patch, I'll look at the doc & tests, aiming for a single-shot commit.

andreas_kupries added on 2008-12-02 03:59:11:

File Added - 303644: halfclose-5.patch

andreas_kupries added on 2008-12-02 00:17:22:
Thanks for the work Alexandre.

ferrieux added on 2008-12-01 22:44:29:

File Added - 303613: halfclose-4.patch

Attached halfclose-4.patch which now includes a close2proc for pipes in unix too.
Also tweaked a bit the error message when closing an already-closed half, to better distinguish from the "unsupported by channel type" case.
Would appreciate help for the tests and doc, busy at work now :-(

File Added: halfclose-4.patch

ferrieux added on 2008-12-01 21:22:07:
Attached a new version fixing all the known issues on the socket side:

 (1) The test on flags to detect a true half-close was buggy.
  (this explained the full-close)

 (2) Once we really decide to do the half-close, let's not forget to update the statePtr->flags ;-)
  (this explained why a [close $f w];[close $f r] did not close)

Now I've just noticed that Pipes don't have a close2proc on unix. Will do that now.

File Added: halfclosesock-3.patch

ferrieux added on 2008-12-01 21:22:06:

File Added - 303605: halfclosesock-3.patch

ferrieux added on 2008-12-01 20:44:24:
First a minor thing: replace objv[3] by objv[2] for the direction argument in Tcl_CloseObjCmd (segfault ;-)
Now, more worrisome: half-close (w) on a socket actually does a full close: the channel is de-registered:

    % set f [socket localhost 9999]
    % fconfigure $f -buffering line
    % puts $f rrr
    % gets $f
    % close $f w
    % gets $f
    can not find channel named "sock3"

and at the syscall level, the fd is close()d too, as shown by starce:

  Process 14165 attached - interrupt to quit
  read(0, "close $f w\n", 4096)           = 11
  close(3)                                = 0
  write(1, "% ", 2)                       = 2

andreas_kupries added on 2008-11-28 06:48:04:
updated patch with implementation for 'close' command, and Tcl_CloseEx glue code. Draft. Compiles on my test. No test at all. Likely to crash.

andreas_kupries added on 2008-11-28 06:47:12:

File Added - 303266: halfclosesock-2.patch

ferrieux added on 2008-11-17 05:10:56:

data_type - 310894

File Added - 301707: halfclosesock.patch

Switching this to Patch tracker, to hold beginning of implementation of the request, which is now TIP 332.

This first patch just brings the close2proc to the socket channel type.
The only other type-specific close2proc foreseen as useful for this TIP is for pipes, and already exists.
The next missing part is in the generic layer. Andreas, I'm counting on you there ;-)

File Added: halfclosesock.patch