From 89975c594f663fa730e70a1d45ba4e4aedb9aed8 Mon Sep 17 00:00:00 2001 From: andreas_kupries Date: Fri, 11 Apr 2003 17:35:30 +0000 Subject: * generic/tclIO.c (UpdateInterest): When dropping interest in TCL_READABLE now dropping interest in TCL_EXCEPTION too. This fixes a bug where Expect detects eof on a file prematurely on solaris 2.6 and higher. A much more complete explanation is in the code itself (40 lines of comments for a one-line change :) --- ChangeLog | 8 ++++++++ generic/tclIO.c | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index ecb0883..c48934e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-04-11 Andreas Kupries + + * generic/tclIO.c (UpdateInterest): When dropping interest in + TCL_READABLE now dropping interest in TCL_EXCEPTION too. This + fixes a bug where Expect detects eof on a file prematurely on + solaris 2.6 and higher. A much more complete explanation is in + the code itself (40 lines of comments for a one-line change :) + 2003-04-10 Donal K. Fellows * doc/binary.n: Fixed typo in [binary format w] desc. [Bug 718543] diff --git a/generic/tclIO.c b/generic/tclIO.c index d4177c1..6ef2b5e 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIO.c,v 1.61.2.1 2003/04/10 22:18:07 andreas_kupries Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.61.2.2 2003/04/11 17:35:33 andreas_kupries Exp $ */ #include "tclInt.h" @@ -6852,15 +6852,46 @@ UpdateInterest(chanPtr) mask &= ~TCL_READABLE; /* - * Andreas Kupries -- Experimental change + * Andreas Kupries, April 11, 2003 * - * Squash interest in exceptions too. Solaris may/will - * generate superfluous exceptions for plain text files, - * screwing up expect, which doesn't get the synthesized - * readable event, or to late. + * Some operating systems (Solaris 2.6 and higher (but not + * Solaris 2.5, go figure)) generate READABLE and + * EXCEPTION events when select()'ing [*] on a plain file, + * even if EOF was not yet reached. This is a problem in + * the following situation: + * + * - An extension asks to get both READABLE and EXCEPTION + * events. + * - It reads data into a buffer smaller than the buffer + * used by Tcl itself. + * - It does not process all events in the event queue, but + * only only one, at least in some situations. + * + * In that case we can get into a situation where + * + * - Tcl drops READABLE here, because it has data in its own + * buffers waiting to be read by the extension. + * - A READABLE event is syntesized via timer. + * - The OS still reports the EXCEPTION condition on the file. + * - And the extension gets the EXCPTION event first, and + * handles this as EOF. + * + * End result ==> Premature end of reading from a file. + * + * The concrete example is 'Expect', and its [expect] + * command (and at the C-level, deep in the bowels of + * Expect, 'exp_get_next_event'. See marker 'SunOS' for + * commentary in that function too). + * + * [*] As the Tcl notifier does. See also for marker + * 'SunOS' in file 'exp_event.c' of Expect. + * + * Our solution here is to drop the interest in the + * EXCEPTION events too. This compiles on all platforms, + * and also passes the testsuite on all of them. */ - mask &= ~TCL_EXCEPTION; + mask &= ~TCL_EXCEPTION; if (!statePtr->timer) { statePtr->timer = Tcl_CreateTimerHandler(0, ChannelTimerProc, -- cgit v0.12