Tcl Source Code

Artifact [5f61143a66]
Login

Artifact 5f61143a6622ffd8f706aee627ef285a57971d0f:

Attachment "io.patch" to ticket [2901998fff] added by ferrieux 2009-12-01 08:14:52.
Index: tclIO.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIO.c,v
retrieving revision 1.168
diff -u -r1.168 tclIO.c
--- tclIO.c	18 Nov 2009 22:41:41 -0000	1.168
+++ tclIO.c	1 Dec 2009 01:11:05 -0000
@@ -3831,6 +3831,29 @@
     }
 }
 
+static void WillWrite(Channel *chanPtr)
+{
+    if ((chanPtr->typePtr->seekProc != NULL)
+        && (Tcl_InputBuffered((Tcl_Channel) chanPtr) > 0)) {
+        DiscardInputQueued(chanPtr->state, 0);
+    }
+}
+
+static int WillRead(Channel *chanPtr)
+{
+    if ((chanPtr->typePtr->seekProc != NULL)
+        && (Tcl_OutputBuffered((Tcl_Channel) chanPtr) > 0)) {
+        if ((chanPtr->state->curOutPtr != NULL)
+            && IsBufferReady(chanPtr->state->curOutPtr)) {
+            SetFlag(chanPtr->state, BUFFER_READY);
+        }
+        if (FlushChannel(NULL, chanPtr, 0) != 0) {
+            return -1;
+        }
+    }
+    return 0;
+}
+
 /*
  *----------------------------------------------------------------------
  *
@@ -3864,6 +3887,10 @@
     char *dst;
     int dstMax, sawLF, savedLF, total, dstLen, toWrite, translate;
 
+    if (srcLen) {
+        WillWrite(chanPtr);
+    }
+
     total = 0;
     sawLF = 0;
     savedLF = 0;
@@ -3965,6 +3992,10 @@
     Tcl_Encoding encoding;
     char safe[BUFFER_PADDING];
 
+    if (srcLen) {
+        WillWrite(chanPtr);
+    }
+
     total = 0;
     sawLF = 0;
     savedLF = 0;
@@ -5782,6 +5813,10 @@
     src = RemovePoint(bufPtr);
     srcLen = BytesLeft(bufPtr);
 
+    if (bytesToRead && (WillRead(statePtr->topChanPtr) < 0)) {
+        return -1;
+    }
+
     toRead = bytesToRead;
     if ((unsigned) toRead > (unsigned) srcLen) {
 	toRead = srcLen;
@@ -5894,6 +5929,10 @@
     src = RemovePoint(bufPtr);
     srcLen = BytesLeft(bufPtr);
 
+    if (WillRead(statePtr->topChanPtr) < 0) {
+        return -1;
+    }
+
     toRead = charsToRead;
     if ((unsigned) toRead > (unsigned) srcLen) {
 	toRead = srcLen;
@@ -7035,8 +7074,10 @@
      * pre-read input data.
      */
 
-    if (Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_CUR) == Tcl_LongAsWide(-1)) {
-	return TCL_ERROR;
+    WillWrite(chanPtr);
+
+    if (WillRead(chanPtr) < 0) {
+        return TCL_ERROR;
     }
 
     /*