I am writing a little lua script that read data from a FIFO.for this I use the classical:
f=assert(io.open("/tmp/myfifo")
f:read()
When the fifo is empty/not feeded, my script block. Is there a way to avoid this ?.
I am writing a little lua script that read data from a FIFO.for this I use the classical:
f=assert(io.open("/tmp/myfifo")
f:read()
When the fifo is empty/not feeded, my script block. Is there a way to avoid this ?.
 
    
    There is no straight forward Lua-only method I guess. With luajit http://luajit.org/ (which provides ffi) it is possible:
 local ffi = require'ffi'
 --- The libc functions used by this process.
 ffi.cdef[[
      int open(const char* pathname, int flags);
      int close(int fd);
      int read(int fd, void* buf, size_t count);
 ]]   
 local O_NONBLOCK = 2048
 local chunk_size = 4096
 local buffer = ffi.new('uint8_t[?]',chunk_size)
 local fd = ffi.C.open('mypipe',O_NONBLOCK)     
 local nbytes = ffi.C.read(fd,buffer,chunksize)
 -- .. process data
