summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2013-11-28 22:35:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2013-11-28 22:35:50 -0800
commit2e104e2d490dc02eb527b5e17f14e4ea39275161 (patch)
treea6281926153bc7e3a29304b7160506dd16f504bc /stream.c
parent0be7721c52cf2978114de43e391c04437d8d875e (diff)
downloadtxr-2e104e2d490dc02eb527b5e17f14e4ea39275161.tar.gz
txr-2e104e2d490dc02eb527b5e17f14e4ea39275161.tar.bz2
txr-2e104e2d490dc02eb527b5e17f14e4ea39275161.zip
* stream.c (tail_calc): New function
(tail_strategy): Handle the situation when the file disappears. We cannot throw an error, but must poll the filesystem for the file to reappear.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/stream.c b/stream.c
index 41876d85..a74705ab 100644
--- a/stream.c
+++ b/stream.c
@@ -322,20 +322,22 @@ static struct strm_ops stdio_ops = {
stdio_seek
};
-static void tail_strategy(val stream, unsigned long *state)
+static void tail_calc(unsigned long *state, int *sec, int *mod)
{
unsigned long count = (*state)++;
- int sec, mod;
- (void) stream;
-
if (count > 32)
count = 32;
+ *sec = 1 << (count / 8);
+ *mod = 8 >> (count / 8);
+ if (*mod == 0)
+ *mod = 1;
+}
- sec = 1 << (count / 8);
- mod = 8 >> (count / 8);
+static void tail_strategy(val stream, unsigned long *state)
+{
+ int sec, mod;
- if (mod == 0)
- mod = 1;
+ tail_calc(state, &sec, &mod);
sleep(sec);
@@ -346,9 +348,16 @@ static void tail_strategy(val stream, unsigned long *state)
if ((save_pos = ftell(h->f)) == -1)
return;
- if (!(h->f = w_freopen(c_str(h->descr), c_str(h->mode), h->f)))
- uw_throwf(file_error_s, lit("error opening ~a: ~a/~s"),
- h->descr, num(errno), string_utf8(strerror(errno)), nao);
+ for (;;) {
+ FILE *newf;
+ if (!(newf = w_freopen(c_str(h->descr), c_str(h->mode), h->f))) {
+ tail_calc(state, &sec, &mod);
+ sleep(sec);
+ continue;
+ }
+ h->f = newf;
+ break;
+ }
utf8_decoder_init(&h->ud);