liv2hak
liv2hak

Reputation: 14980

read one byte at a time using poll/select

I am trying to read off a file descriptior of a device.with the following code using poll/select.I am able to read the bytes of the device.I want to know when would be the right time to exit the loop.I am reading one character at a time.once it has read all the bytes I need to exit from the loop.how do I accomplish that.

while (continue_reading) 
{   n = read(radioFd, &rc, 1);
        if(rc == START_OF_FRAME)
        {
             start_buffering = 1;
             printf("SOF found \n");
        }
        if(1 == start_buffering)
        {
             read_buffer[read_count] = rc;
             read_count += n;
        } 
}

Upvotes: 0

Views: 177

Answers (1)

tsug303
tsug303

Reputation: 59

If your device behave like a file, you have to test read return value (n) for 0 (end of file). And you also need to test it for -1, to identify error and check errno.

Upvotes: 1

Related Questions