summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-11-14 11:07:13 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-11-14 11:07:13 (GMT)
commit2e628b79d9fe0fe590cbab9bea27c1fdf11082f9 (patch)
treef376fc0202a8622822a1392fffc46b244e478c35 /generic
parentc12814c9d49023cf780dc0fc14cc749cd56e1d43 (diff)
downloadtcl-2e628b79d9fe0fe590cbab9bea27c1fdf11082f9.zip
tcl-2e628b79d9fe0fe590cbab9bea27c1fdf11082f9.tar.gz
tcl-2e628b79d9fe0fe590cbab9bea27c1fdf11082f9.tar.bz2
Add test for blocking mode
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIO.c29
-rw-r--r--generic/tclIOCmd.c12
-rw-r--r--generic/tclInt.h1
3 files changed, 35 insertions, 7 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index bc1b1c6..0047f0b 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -4934,7 +4934,7 @@ Tcl_GetsObj(
* two times, as gs.bytesWrote is not 0 on the first pass. This feels
* once to much, as the data is anyway not used.
*/
-
+
/* Set eol to the position that caused the encoding error, and then
* continue to gotEOL, which stores the data that was decoded
* without error to objPtr. This allows the caller to do something
@@ -7616,6 +7616,33 @@ Tcl_Eof(
return GotFlag(statePtr, CHANNEL_EOF) ? 1 : 0;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclChannelGetBlockingMode --
+ *
+ * Returns 1 if the channel is in blocking mode (default), 0 otherwise.
+ *
+ * Results:
+ * 1 or 0, always.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclChannelGetBlockingMode(
+ Tcl_Channel chan)
+{
+ ChannelState *statePtr = ((Channel *) chan)->state;
+ /* State of real channel structure. */
+
+ return GotFlag(statePtr, CHANNEL_NONBLOCKING) ? 0 : 1;
+}
+
/*
*----------------------------------------------------------------------
*
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index 0827858..9667419 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -459,11 +459,9 @@ Tcl_ReadObjCmd(
TclChannelPreserve(chan);
charactersRead = Tcl_ReadChars(chan, resultPtr, toRead, 0);
if (charactersRead == TCL_IO_FAILURE) {
-
- Tcl_Obj *returnOptsPtr = Tcl_NewDictObj();
- /* check for blocking and encoding error */
- /* TODO: check for blocking missing */
- if ( Tcl_GetErrno() == EILSEQ ) {
+ Tcl_Obj *returnOptsPtr = NULL;
+ if (TclChannelGetBlockingMode(chan)) {
+ returnOptsPtr = Tcl_NewDictObj();
Tcl_DictObjPut(NULL, returnOptsPtr, Tcl_NewStringObj("-data", -1),
resultPtr);
}
@@ -480,7 +478,9 @@ Tcl_ReadObjCmd(
TclGetString(chanObjPtr), Tcl_PosixError(interp)));
}
TclChannelRelease(chan);
- Tcl_SetReturnOptions(interp, returnOptsPtr);
+ if (returnOptsPtr) {
+ Tcl_SetReturnOptions(interp, returnOptsPtr);
+ }
return TCL_ERROR;
}
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 3d8a702..f696ad2 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3112,6 +3112,7 @@ MODULE_SCOPE int TclByteArrayMatch(const unsigned char *string,
MODULE_SCOPE double TclCeil(const void *a);
MODULE_SCOPE void TclChannelPreserve(Tcl_Channel chan);
MODULE_SCOPE void TclChannelRelease(Tcl_Channel chan);
+MODULE_SCOPE int TclChannelGetBlockingMode(Tcl_Channel chan);
MODULE_SCOPE int TclCheckArrayTraces(Tcl_Interp *interp, Var *varPtr,
Var *arrayPtr, Tcl_Obj *name, int index);
MODULE_SCOPE int TclCheckBadOctal(Tcl_Interp *interp,