summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-05-13 18:24:23 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-05-13 18:24:23 (GMT)
commitc3df58587ce6e9f21b652b23eb7f56f852a326f7 (patch)
tree81226f84539ab6e3a92f516d5fc4d2b196ef09c0 /generic
parent3d7a8d7f99f6c4c1678cfedf68d673edf5c28e4f (diff)
downloadtcl-c3df58587ce6e9f21b652b23eb7f56f852a326f7.zip
tcl-c3df58587ce6e9f21b652b23eb7f56f852a326f7.tar.gz
tcl-c3df58587ce6e9f21b652b23eb7f56f852a326f7.tar.bz2
Rework Tcl_ReadRaw() mostly taking things out of the loop that never repeat.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIO.c56
1 files changed, 20 insertions, 36 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 41f555b..a82c36b 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -4985,7 +4985,7 @@ Tcl_ReadRaw(
Channel *chanPtr = (Channel *) chan;
ChannelState *statePtr = chanPtr->state;
/* State info for channel */
- int nread, copied, copiedNow;
+ int nread, copied, copiedNow = INT_MAX;
/*
* The check below does too much because it will reject a call to this
@@ -5010,44 +5010,28 @@ Tcl_ReadRaw(
*/
Tcl_Preserve(chanPtr);
- for (copied = 0; copied < bytesToRead; copied += copiedNow) {
- copiedNow = CopyBuffer(chanPtr, bufPtr + copied,
- bytesToRead - copied);
- if (copiedNow == 0) {
- if (GotFlag(statePtr, CHANNEL_EOF)) {
- break;
- }
- if (GotFlag(statePtr, CHANNEL_BLOCKED)) {
- if (GotFlag(statePtr, CHANNEL_NONBLOCKING)) {
- break;
- }
- ResetFlag(statePtr, CHANNEL_BLOCKED);
- }
-
- /*
- * Now go to the driver to get as much as is possible to
- * fill the remaining request. Do all the error handling by
- * ourselves. The code was stolen from 'GetInput' and
- * slightly adapted (different return value here).
- *
- * The case of 'bytesToRead == 0' at this point cannot
- * happen.
- */
+ for (copied = 0; bytesToRead > 0 && copiedNow > 0;
+ bufPtr+=copiedNow, bytesToRead-=copiedNow, copied+=copiedNow) {
+ copiedNow = CopyBuffer(chanPtr, bufPtr, bytesToRead);
+ }
- nread = ChanRead(chanPtr, bufPtr + copied,
- bytesToRead - copied);
+ if (bytesToRead > 0) {
+ /*
+ * Now go to the driver to get as much as is possible to
+ * fill the remaining request. Since we're directly filling
+ * the caller's buffer, retain the blocked flag.
+ */
- if (nread < 0) {
- if (GotFlag(statePtr, CHANNEL_BLOCKED) && copied > 0) {
-/* TODO: comment out? */
-// ResetFlag(statePtr, CHANNEL_BLOCKED);
- } else {
- copied = -1;
- }
- } else {
- copied += nread;
+ nread = ChanRead(chanPtr, bufPtr, bytesToRead);
+ if (nread < 0) {
+ if (!GotFlag(statePtr, CHANNEL_BLOCKED) || copied == 0) {
+ copied = -1;
}
- break;
+ } else {
+ copied += nread;
+ }
+ if (copied != 0) {
+ ResetFlag(statePtr, CHANNEL_EOF);
}
}