Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-12-18
20:30 • Ticket [219159ffff] Need to split bidirectional channels (sockets; pipes or devi... artifact: 555afce390 user: ferrieux
18:50 • Ticket [219159ffff]: 4 changes artifact: a87bbf98bc user: dkf
08:18 • Ticket [219159ffff]: 4 changes artifact: 40233dbbdd user: ferrieux
2008-12-10
03:45 • Ticket [219159ffff]: 4 changes artifact: bdf0eae690 user: andreas_kupries
2008-12-09
23:40 • Ticket [219159ffff]: 4 changes artifact: eef3dd4ea8 user: ferrieux
2008-12-02
03:59 • Add attachment halfclose-5.patch to ticket [219159ffffffffff|219159ffff... artifact: 054763c02b user: andreas_kupries
03:59 • Ticket [219159ffff] Need to split bidirectional channels (sockets; pipes or devi... artifact: 16028cb779 user: andreas_kupries
00:17 • Ticket [219159ffff]: 4 changes artifact: 2e76dd80e7 user: andreas_kupries
2008-12-01
22:44 • Add attachment halfclose-4.patch to ticket [219159ffffffffff|219159ffff... artifact: 935d9a7130 user: ferrieux
22:44 • Ticket [219159ffff] Need to split bidirectional channels (sockets; pipes or devi... artifact: c7fcaaec05 user: ferrieux
21:22 • Ticket [219159ffff]: 4 changes artifact: 31da01b5f9 user: ferrieux
21:22 • Add attachment halfclosesock-3.patch to ticket [219159ffffffffff|219159... artifact: c6d5fe3e9c user: ferrieux
21:22 • Ticket [219159ffff] Need to split bidirectional channels (sockets; pipes or devi... artifact: d4d975e06a user: ferrieux
20:44 • Ticket [219159ffff]: 4 changes artifact: b675a670a7 user: ferrieux
2008-11-28
06:48 • Ticket [219159ffff]: 4 changes artifact: 32be2b030c user: andreas_kupries
06:47 • Ticket [219159ffff]: 4 changes artifact: e19afe28ce user: andreas_kupries
06:47 • Add attachment halfclosesock-2.patch to ticket [219159ffffffffff|219159... artifact: 392890e828 user: andreas_kupries
2008-11-17
05:10 • Ticket [219159ffff] Need to split bidirectional channels (sockets; pipes or devi... artifact: 34baad6508 user: ferrieux
05:10 • Add attachment halfclosesock.patch to ticket [219159ffffffffff|219159ff... artifact: 69e536b8f2 user: ferrieux
2001-09-15
06:53 • Ticket [219159ffff] Need to split bidirectional channels (sockets; pipes or devi... artifact: 3ee8ed8c76 user: andreas_kupries
2001-04-04
03:45 • Ticket [219159ffff]: 1 change artifact: a2da075be3 user: dgp
2000-11-10
20:48 • Ticket [219159ffff]: 2 changes artifact: b4cdd5ad55 user: dkf
2000-10-26
05:02 • New ticket [219159ffff]. artifact: 30c0beff32 user: nobody

Need to split bidirectional channels (sockets; pipes or devi

Open219159ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 18 years ago
Descriptionplain2000-10-26 05:02:26
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'


Name:
Alexandre FERRIEUX

DesiredBehavior:
    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
dkf Ticket [219159ffff]: 2 changes [History diff]2000-11-10 20:48:30
dgp Ticket [219159ffff]: 1 change [History diff]2001-04-04 03:45:13
andreas_kupries Ticket [219159ffff]: 1 change [History diff]2001-09-15 06:53:53
ferrieuxplain2008-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
andreas_kupriesplain2008-11-28 06:47:12
File Added - 303266: halfclosesock-2.patch
andreas_kupriesplain2008-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.
ferrieuxplain2008-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]
    sock3
    % fconfigure $f -buffering line
    % puts $f rrr
    % gets $f
sdfsd
    % 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
ferrieuxplain2008-12-01 21:22:06
File Added - 303605: halfclosesock-3.patch
ferrieuxplain2008-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
ferrieuxplain2008-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
andreas_kupriesplain2008-12-02 00:17:22
Thanks for the work Alexandre.
andreas_kupriesplain2008-12-02 03:59:11
File Added - 303644: halfclose-5.patch
ferrieuxplain2008-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_kupriesplain2008-12-10 03:45:42
Ok. Thanks.
ferrieuxplain2008-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}.
dkfplain2008-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...)
ferrieuxplain2008-12-18 20:30:18
Thanks Donal, nice idiom.
Please rather followup on this issue in 2444274.
Log in (anonymous is fine) to add a comment.

Attachments: