How to create an "endless" virtual device?

Hello

I have programmed a virtual device under /dev that gives some information to user who reads it. It works fine, except that after there is no more data, the connection is being closed. Or at least this happens when I try to read it using cat.

Is it possible to create a virtual device that does not close the connection but instead keeps waiting until there is again data to be read?
 
I think one solution would be to wait for condition in read function, but the main problem is that if I don't fill the whole given buffer in read function, the system thinks that there will not be any more data and makes EOF.
 
I think you should find something that reads your file one character at a time. But then you need some sort of code to find out where to stop reading since there will be no EOF.
 
When I code a program in the future to read the device, it does not matter how many character it tries to read. The important thing is that there should not be EOF and currently I don't know how to do this.
 
I got it working!

I was just about to give up and I though that I just put some condition stuff to the reading operation so that it would block until there is something to read. If it gives EOF, then I just reopen it. Atleast it wouldn't consume any CPU resources when there is no stuff.

But after I made that condition thingy, it magically stopped giving EOF, even that I didn't fill the whole read vector. Now I'm happy :)
 
Back
Top