diff options
author | Steve Bennett <steveb@workware.net.au> | 2023-05-28 11:22:12 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2023-07-04 09:23:43 +1000 |
commit | 41f431f30cc6118ef982c6374914810cd07a8106 (patch) | |
tree | 036384d2c7e90a0236642ebf65686601c92656d5 /jim-exec.c | |
parent | ad720049ec1ae3536d64fbb4c80a79e65ba5af39 (diff) | |
download | jimtcl-41f431f30cc6118ef982c6374914810cd07a8106.zip jimtcl-41f431f30cc6118ef982c6374914810cd07a8106.tar.gz jimtcl-41f431f30cc6118ef982c6374914810cd07a8106.tar.bz2 |
aio: change to use unix io, not stdio
This changes especially makes buffered I/O work
with non-blocking channels.
- separate read and write buffering
- support for timeout on blocking read
- read/write on same channel in event loop with buffering
- read buffer is the same across read, gets, copyto
- autoflush non-blocking writes via event loop
- copyto can now copy to any filehandle-like command
- add some copyto tests
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-exec.c')
-rw-r--r-- | jim-exec.c | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -129,24 +129,19 @@ static void Jim_RemoveTrailingNewline(Jim_Obj *objPtr) static int JimAppendStreamToString(Jim_Interp *interp, int fd, Jim_Obj *strObj) { char buf[256]; - FILE *fh = fdopen(fd, "r"); int ret = 0; - if (fh == NULL) { - return -1; - } - while (1) { - int retval = fread(buf, 1, sizeof(buf), fh); + int retval = read(fd, buf, sizeof(buf)); if (retval > 0) { ret = 1; Jim_AppendString(interp, strObj, buf, retval); } - if (retval != sizeof(buf)) { + if (retval <= 0) { break; } } - fclose(fh); + close(fd); return ret; } @@ -441,7 +436,7 @@ static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) */ if (errorId != -1) { int ret; - lseek(errorId, 0, SEEK_SET); + Jim_Lseek(errorId, 0, SEEK_SET); ret = JimAppendStreamToString(interp, errorId, errStrObj); if (ret < 0) { Jim_SetResultErrno(interp, "error reading from error pipe"); @@ -872,7 +867,7 @@ badargs: close(inputId); goto error; } - lseek(inputId, 0L, SEEK_SET); + Jim_Lseek(inputId, 0L, SEEK_SET); } else if (inputFile == FILE_HANDLE) { int fd = JimGetChannelFd(interp, input); |