summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-07-27 22:53:01 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-07-27 22:53:01 (GMT)
commitcf106cdda63ef90e183b7c2bc638b768b0a2f156 (patch)
tree4acc8e1356a3c489a8bce7ce949beefef42f14c0 /generic/tclIO.c
parent3eb6318d9ba66cdb78f777a81c8b2be175b6a341 (diff)
downloadtcl-cf106cdda63ef90e183b7c2bc638b768b0a2f156.zip
tcl-cf106cdda63ef90e183b7c2bc638b768b0a2f156.tar.gz
tcl-cf106cdda63ef90e183b7c2bc638b768b0a2f156.tar.bz2
Push MBWrite() differences out to callers.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 907a070..73e1274 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -8969,9 +8969,20 @@ MBEvent(
int mask)
{
CopyState *csPtr = (CopyState *) clientData;
+ Tcl_Channel inChan = (Tcl_Channel) csPtr->readPtr;
+ Tcl_Channel outChan = (Tcl_Channel) csPtr->writePtr;
if (mask & TCL_WRITABLE) {
- (void) MBWrite(csPtr, mask);
+ Tcl_DeleteChannelHandler(inChan, MBRead, csPtr);
+ Tcl_DeleteChannelHandler(outChan, MBEvent, csPtr);
+ switch (MBWrite(csPtr, mask)) {
+ case TCL_OK:
+ MBCallback(csPtr, NULL);
+ break;
+ case TCL_CONTINUE:
+ Tcl_CreateChannelHandler(inChan, TCL_READABLE, MBRead, csPtr);
+ break;
+ }
} else if (mask & TCL_READABLE) {
(void) MBRead(clientData, mask);
}
@@ -9013,19 +9024,12 @@ MBWrite(
{
ChannelState *inStatePtr = csPtr->readPtr->state;
ChannelState *outStatePtr = csPtr->writePtr->state;
-
- Tcl_Channel inChan = (Tcl_Channel) csPtr->readPtr;
- Tcl_Channel outChan = (Tcl_Channel) csPtr->writePtr;
-
ChannelBuffer *bufPtr = inStatePtr->inQueueHead;
ChannelBuffer *tail = NULL;
int code, inBytes = 0;
assert (mask & TCL_WRITABLE);
- Tcl_DeleteChannelHandler(inChan, MBRead, csPtr);
- Tcl_DeleteChannelHandler(outChan, MBEvent, csPtr);
-
/* Count up number of bytes waiting in the input queue */
while (bufPtr) {
inBytes += BytesLeft(bufPtr);
@@ -9070,24 +9074,14 @@ MBWrite(
}
code = FlushChannel(csPtr->interp, outStatePtr->topChanPtr, 0);
- if (code == 0) {
- if (csPtr->toRead == 0 || Tcl_Eof(inChan)) {
- if (csPtr->cmdPtr) {
- MBCallback(csPtr, NULL);
- } else {
- Tcl_SetObjResult(csPtr->interp,
- Tcl_NewWideIntObj(csPtr->total));
- StopCopy(csPtr);
- }
- return TCL_OK;
- } else if (csPtr->cmdPtr) {
- Tcl_CreateChannelHandler(inChan, TCL_READABLE, MBRead, csPtr);
- }
- return TCL_CONTINUE;
- } else {
+ if (code) {
MBError(csPtr, mask, code);
return TCL_ERROR;
}
+ if (csPtr->toRead == 0 || GotFlag(inStatePtr, CHANNEL_EOF)) {
+ return TCL_OK;
+ }
+ return TCL_CONTINUE;
}
static int
@@ -9131,14 +9125,15 @@ MoveBytes(
bufPtr = inStatePtr->inQueueHead;
}
code = MBWrite(csPtr, TCL_WRITABLE);
- if (code == TCL_CONTINUE) {
- continue;
- }
if (code == TCL_OK) {
+ Tcl_SetObjResult(csPtr->interp, Tcl_NewWideIntObj(csPtr->total));
+ StopCopy(csPtr);
return TCL_OK;
- } else {
+ }
+ if (code == TCL_ERROR) {
return TCL_ERROR;
}
+ /* code == TCL_CONTINUE --> continue the loop */
}
return TCL_OK; /* Silence compiler warnings */
}