summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-03-16 18:11:08 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-03-16 18:11:08 (GMT)
commite7fc2e1e1d845b964cbf8c084865e83d1ced239f (patch)
treecbf743d53c85e2e497a9a02a5afdb5750d86c25b /generic/tclIO.c
parent527e79c3a8b0d8df5cce3676a94700785584ef06 (diff)
parent88f9f54d4c4e23a4d20b82b40b385c6d558013f9 (diff)
downloadtcl-e7fc2e1e1d845b964cbf8c084865e83d1ced239f.zip
tcl-e7fc2e1e1d845b964cbf8c084865e83d1ced239f.tar.gz
tcl-e7fc2e1e1d845b964cbf8c084865e83d1ced239f.tar.bz2
Merge 9.0
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 63579ee..bc891a2 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -165,6 +165,7 @@ static int CheckForDeadChannel(Tcl_Interp *interp,
static void CheckForStdChannelsBeingClosed(Tcl_Channel chan);
static void CleanupChannelHandlers(Tcl_Interp *interp,
Channel *chanPtr);
+static void CleanupTimerHandler(ChannelState *statePtr);
static int CloseChannel(Tcl_Interp *interp, Channel *chanPtr,
int errorCode);
static int CloseChannelPart(Tcl_Interp *interp, Channel *chanPtr,
@@ -172,6 +173,7 @@ static int CloseChannelPart(Tcl_Interp *interp, Channel *chanPtr,
static int CloseWrite(Tcl_Interp *interp, Channel *chanPtr);
static void CommonGetsCleanup(Channel *chanPtr);
static int CopyData(CopyState *csPtr, int mask);
+static void DeleteTimerHandler(ChannelState *statePtr);
static int MoveBytes(CopyState *csPtr);
static void MBCallback(CopyState *csPtr, Tcl_Obj *errObj);
@@ -1708,6 +1710,7 @@ Tcl_CreateChannel(
statePtr->scriptRecordPtr = NULL;
statePtr->bufSize = CHANNELBUFFER_DEFAULT_SIZE;
statePtr->timer = NULL;
+ statePtr->timerChanPtr = NULL;
statePtr->csPtrR = NULL;
statePtr->csPtrW = NULL;
statePtr->outputStage = NULL;
@@ -3153,8 +3156,8 @@ CloseChannel(
/*
* Cancel any outstanding timer.
*/
+ DeleteTimerHandler(statePtr);
- Tcl_DeleteTimerHandler(statePtr->timer);
/*
* Mark the channel as deleted by clearing the type structure.
@@ -3506,7 +3509,7 @@ TclClose(
/*
* Cancel any outstanding timer.
*/
- Tcl_DeleteTimerHandler(statePtr->timer);
+ DeleteTimerHandler(statePtr);
/*
* Invoke the registered close callbacks and delete their records.
@@ -3959,8 +3962,7 @@ Tcl_ClearChannelHandlers(
/*
* Cancel any outstanding timer.
*/
-
- Tcl_DeleteTimerHandler(statePtr->timer);
+ DeleteTimerHandler(statePtr);
/*
* Remove any references to channel handlers for this channel that may be
@@ -8641,8 +8643,9 @@ UpdateInterest(
if (!statePtr->timer) {
TclChannelPreserve((Tcl_Channel)chanPtr);
+ statePtr->timerChanPtr = chanPtr;
statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME,
- ChannelTimerProc, chanPtr);
+ ChannelTimerProc, chanPtr);
}
}
}
@@ -8652,6 +8655,7 @@ UpdateInterest(
&& GotFlag(statePtr, CHANNEL_NONBLOCKING)) {
TclChannelPreserve((Tcl_Channel)chanPtr);
+ statePtr->timerChanPtr = chanPtr;
statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME,
ChannelTimerProc,chanPtr);
}
@@ -8682,7 +8686,6 @@ ChannelTimerProc(
void *clientData)
{
Channel *chanPtr = (Channel *)clientData;
-
/* State info for channel */
ChannelState *statePtr = chanPtr->state;
@@ -8693,7 +8696,7 @@ ChannelTimerProc(
*/
if (chanPtr->typePtr == NULL) {
- TclChannelRelease((Tcl_Channel)chanPtr);
+ CleanupTimerHandler(statePtr);
} else {
Tcl_Preserve(statePtr);
statePtr->timer = NULL;
@@ -8706,35 +8709,52 @@ ChannelTimerProc(
* before UpdateInterest gets called by Tcl_NotifyChannel.
*/
statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME,
- ChannelTimerProc,chanPtr);
+ ChannelTimerProc,chanPtr);
Tcl_NotifyChannel((Tcl_Channel) chanPtr, TCL_WRITABLE);
} else {
/* The channel may have just been closed from within Tcl_NotifyChannel */
if (!GotFlag(statePtr, CHANNEL_INCLOSE)) {
if (!GotFlag(statePtr, CHANNEL_NEED_MORE_DATA)
- && (statePtr->interestMask & TCL_READABLE)
- && (statePtr->inQueueHead != NULL)
- && IsBufferReady(statePtr->inQueueHead)) {
+ && (statePtr->interestMask & TCL_READABLE)
+ && (statePtr->inQueueHead != NULL)
+ && IsBufferReady(statePtr->inQueueHead)) {
/*
* Restart the timer in case a channel handler reenters the event loop
* before UpdateInterest gets called by Tcl_NotifyChannel.
*/
statePtr->timer = Tcl_CreateTimerHandler(SYNTHETIC_EVENT_TIME,
- ChannelTimerProc,chanPtr);
+ ChannelTimerProc,chanPtr);
Tcl_NotifyChannel((Tcl_Channel) chanPtr, TCL_READABLE);
} else {
- TclChannelRelease((Tcl_Channel)chanPtr);
+ CleanupTimerHandler(statePtr);
UpdateInterest(chanPtr);
}
} else {
- TclChannelRelease((Tcl_Channel)chanPtr);
+ CleanupTimerHandler(statePtr);
}
}
-
Tcl_Release(statePtr);
}
-
+}
+
+static void
+DeleteTimerHandler(
+ ChannelState *statePtr
+)
+{
+ if (statePtr->timer != NULL) {
+ Tcl_DeleteTimerHandler(statePtr->timer);
+ CleanupTimerHandler(statePtr);
+ }
+}
+static void
+CleanupTimerHandler(
+ ChannelState *statePtr
+){
+ TclChannelRelease((Tcl_Channel)statePtr->timerChanPtr);
+ statePtr->timer = NULL;
+ statePtr->timerChanPtr = NULL;
}
/*