Std.io.poll pollTimeout() never timeouts?

Doing some testing with serial reads and trying to use std.io.poll and pollTimeout()

When creating std.io.poll with serial (like /dev/ttyACMx) and using the pollTimeout() on that the timeout newer timeouts… if there is data available on serialport pollTimeout() returns true if no data available it just blocks until data is available?

What I’m doing wrong?

some code here (not all…)

var poller = std.io.poll(std.heap.page_allocator, enum { serial }, .{
        .serial = ctx.file,  // <- this is File opened earlier
    });
    defer poller.deinit();

    while (ctx.running.load(.acquire)) {
        std.log.info("polling serial port", .{});
        const ready = poller.pollTimeout(100) catch {
            std.log.info("poll timeout", .{});
            continue;
        };
        
        if (ready) { do some processing... }

    };

This newer timeouts. Tried both Linux and MacOS

German by chance? I think you might mean never.

Have you checked whether you’re stuck in the actual syscall or in the code surrounding it? Most functions in std.posix retry on EINTR (#6193) so you might be in an infinite loop there because your poll keeps getting interrupted by a signal before it can time out.

(Side note: pollTimeout takes a timeout in ns, but a timeout of 100ns is ignored on posix systems as the poll syscall takes ms, so 100ns will be floored to 0ms)

3 Likes