shithub: femtolisp

Download patch

ref: 738a6ef63e019cfd6262b4418f5aa9d8c7c3a1d9
parent: 93e8ec486116f772eef858ec35135e78d8ca1af6
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Nov 3 17:21:16 EST 2024

io-wait: timeout in seconds

--- a/ios.c
+++ b/ios.c
@@ -844,7 +844,7 @@
 }
 
 int
-ios_wait(ios_t *s, int us)
+ios_wait(ios_t *s, double ws)
 {
 	if(s->bpos < s->size)
 		return 1;
@@ -855,9 +855,9 @@
 	return 1; // FIXME(sigrid): wait for input, but not too much
 #else
 	struct timeval t, *pt = nil;
-	if(us >= 0){
-		t.tv_sec = us / 1000000;
-		t.tv_usec = us % 1000000;
+	if(ws >= 0){
+		t.tv_sec = ws;
+		t.tv_usec = (long)((ws - t.tv_sec) * 1000000.0) % 1000000;
 		pt = &t;
 	}
 	fd_set f;
--- a/ios.h
+++ b/ios.h
@@ -84,7 +84,7 @@
 // ensure at least n bytes are buffered if possible. returns # available.
 size_t ios_readprep(ios_t *from, size_t n);
 
-int ios_wait(ios_t *s, int us);
+int ios_wait(ios_t *s, double ws);
 
 /* stream creation */
 ios_t *ios_file(ios_t *s, char *fname, int rd, int wr, int create, int trunc);
--- a/iostream.c
+++ b/iostream.c
@@ -150,8 +150,7 @@
 	if(nargs > 2)
 		argcount(nargs, 2);
 	ios_t *s = toiostream(args[0]);
-	int us = nargs > 0 ? tooffset(args[1]) : -1;
-	int r = ios_wait(s, us);
+	int r = ios_wait(s, nargs > 1 ? todouble(args[1]) : -1);
 	if(r >= 0)
 		return r ? FL_T : FL_F;
 	if(r == IOS_EOF)