summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIO.c46
-rw-r--r--generic/tclIO.h11
2 files changed, 55 insertions, 2 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 919dfef..295225c 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.76 2004/06/01 18:44:16 davygrvy Exp $
+ * RCS: @(#) $Id: tclIO.c,v 1.77 2004/07/15 20:46:49 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -807,6 +807,17 @@ Tcl_UnregisterChannel(interp, chan)
{
ChannelState *statePtr; /* State of the real channel. */
+ statePtr = ((Channel *) chan)->state->bottomChanPtr->state;
+
+ if (statePtr->flags & CHANNEL_INCLOSE) {
+ if (interp != (Tcl_Interp*) NULL) {
+ Tcl_AppendResult(interp,
+ "Illegal recursive call to close through close-handler of channel",
+ (char *) NULL);
+ }
+ return TCL_ERROR;
+ }
+
if (DetachChannel(interp, chan) != TCL_OK) {
return TCL_OK;
}
@@ -2529,6 +2540,14 @@ Tcl_Close(interp, chan)
Tcl_Panic("called Tcl_Close on channel with refCount > 0");
}
+ if (statePtr->flags & CHANNEL_INCLOSE) {
+ Tcl_AppendResult(interp,
+ "Illegal recursive call to close through close-handler of channel",
+ (char *) NULL);
+ return TCL_ERROR;
+ }
+ statePtr->flags |= CHANNEL_INCLOSE;
+
/*
* When the channel has an escape sequence driven encoding such as
* iso2022, the terminated escape sequence must write to the buffer.
@@ -2552,6 +2571,8 @@ Tcl_Close(interp, chan)
ckfree((char *) cbPtr);
}
+ statePtr->flags &= ~CHANNEL_INCLOSE;
+
/*
* Ensure that the last output buffer will be flushed.
*/
@@ -4237,6 +4258,7 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
statePtr->flags &= (~(CHANNEL_BLOCKED));
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* [SF Tcl Bug 943274]. Better emulation of non-blocking
* channels for channels without BlockModeProc, by keeping
* track of true fileevents generated by the OS == Data
@@ -4252,6 +4274,7 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
nread = -1;
result = EWOULDBLOCK;
} else {
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
/*
* Now go to the driver to get as much as is possible to
* fill the remaining request. Do all the error handling
@@ -4263,7 +4286,9 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
nread = (chanPtr->typePtr->inputProc)(chanPtr->instanceData,
bufPtr + copied, bytesToRead - copied, &result);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
if (nread > 0) {
/*
* If we get a short read, signal up that we may be
@@ -4277,11 +4302,13 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
statePtr->flags |= CHANNEL_BLOCKED;
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
if (nread <= (bytesToRead - copied)) {
/* [SF Tcl Bug 943274] We have read the available
* data, clear flag */
statePtr->flags &= ~CHANNEL_HAS_MORE_DATA;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
} else if (nread == 0) {
statePtr->flags |= CHANNEL_EOF;
statePtr->inputEncodingFlags |= TCL_ENCODING_END;
@@ -5323,6 +5350,7 @@ GetInput(chanPtr)
return 0;
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* [SF Tcl Bug 943274]. Better emulation of non-blocking channels
* for channels without BlockModeProc, by keeping track of true
* fileevents generated by the OS == Data waiting and reading if
@@ -5337,9 +5365,12 @@ GetInput(chanPtr)
nread = -1;
result = EWOULDBLOCK;
} else {
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
nread = (chanPtr->typePtr->inputProc)(chanPtr->instanceData,
bufPtr->buf + bufPtr->nextAdded, toRead, &result);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
if (nread > 0) {
bufPtr->nextAdded += nread;
@@ -5355,11 +5386,13 @@ GetInput(chanPtr)
statePtr->flags |= CHANNEL_BLOCKED;
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
if (nread <= toRead) {
/* [SF Tcl Bug 943274] We have read the available data,
* clear flag */
statePtr->flags &= ~CHANNEL_HAS_MORE_DATA;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
} else if (nread == 0) {
statePtr->flags |= CHANNEL_EOF;
@@ -6764,6 +6797,7 @@ Tcl_NotifyChannel(channel, mask)
Channel* upChanPtr;
Tcl_ChannelType* upTypePtr;
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* [SF Tcl Bug 943274]
* For a non-blocking channel without blockmodeproc we keep track
* of actual input coming from the OS so that we can do a credible
@@ -6777,6 +6811,7 @@ Tcl_NotifyChannel(channel, mask)
statePtr->flags |= CHANNEL_HAS_MORE_DATA;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
/*
* In contrast to the other API functions this procedure walks towards
@@ -7017,6 +7052,7 @@ ChannelTimerProc(clientData)
statePtr->timer = Tcl_CreateTimerHandler(0, ChannelTimerProc,
(ClientData) chanPtr);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* Set the TIMER flag to notify the higher levels that the
* driver might have no data for us. We do this only if we are
* in non-blocking mode and the driver has no BlockModeProc
@@ -7028,10 +7064,15 @@ ChannelTimerProc(clientData)
(Tcl_ChannelBlockModeProc(chanPtr->typePtr) == NULL)) {
statePtr->flags |= CHANNEL_TIMER_FEV;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+
Tcl_Preserve((ClientData) statePtr);
Tcl_NotifyChannel((Tcl_Channel)chanPtr, TCL_READABLE);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
statePtr->flags &= ~CHANNEL_TIMER_FEV;
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+
Tcl_Release((ClientData) statePtr);
} else {
statePtr->timer = NULL;
@@ -9263,8 +9304,11 @@ DumpFlags (str, flags)
if (flags & INPUT_NEED_NL) {buf[i] = '*';} else {buf [i]='_';}; i++;
if (flags & CHANNEL_DEAD) {buf[i] = 'D';} else {buf [i]='_';}; i++;
if (flags & CHANNEL_RAW_MODE) {buf[i] = 'R';} else {buf [i]='_';}; i++;
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
if (flags & CHANNEL_TIMER_FEV) {buf[i] = 'T';} else {buf [i]='_';}; i++;
if (flags & CHANNEL_HAS_MORE_DATA) {buf[i] = 'H';} else {buf [i]='_';}; i++;
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+ if (flags & CHANNEL_INCLOSE) {buf[i] = 'x';} else {buf [i]='_';}; i++;
buf [i] ='\0';
fprintf (stderr,"%s: %s\n", str, buf); fflush(stderr);
diff --git a/generic/tclIO.h b/generic/tclIO.h
index a4eefd3..c0abec2 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -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.h,v 1.6 2004/05/19 19:41:10 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclIO.h,v 1.7 2004/07/15 20:46:49 andreas_kupries Exp $
*/
/*
@@ -296,6 +296,7 @@ typedef struct ChannelState {
* the state of the channel changes. */
#define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is
* being used. */
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
#define CHANNEL_TIMER_FEV (1<<17) /* When set the event we are
* notified by is a fileevent
* generated by a timer. We
@@ -323,6 +324,14 @@ typedef struct ChannelState {
* will be performed if the
* flag is set. This will
* reset the flag as well. */
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+
+#define CHANNEL_INCLOSE (1<<19) /* Channel is currently being
+ * closed. Its structures are
+ * still live and usable, but
+ * it may not be closed again
+ * from within the close handler.
+ */
/*
* For each channel handler registered in a call to Tcl_CreateChannelHandler,