CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Location
    USA
    Posts
    91

    [RESOLVED] select() returns "ready" even after producer is done (FIFO)

    Hello,

    I have a producer application that writes data into a FIFO, and I have a consumer application that reads data from FIFO utilizing select() and read() functions inside of a while(true) loop.

    After producer is done (it closes and unlinks FIFO) select() on the consumer side keeps endlessly returning "ready" state, and read() returns 0 bytes. I've expected select() to return -1 once the FIFO was closed but it's not the case.

    How do I catch that FIFO was closed on the producer side?

    Thank you.

    P.S. I should post my code but it's a large application, it would take me time to make it into a small prototype. I'd appreciate if someone knows the answer without me having to post the code.

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: select() returns "ready" even after producer is done (FIFO)

    Quote Originally Posted by vincegata View Post
    it would take me time to make it into a small prototype.
    You're talking about your problem as if people were clairvoyant. At least I'm not but what's pretty clear without any psychic powers is that you haven't applied a very basic and important design principle, namely encapsulation.

    Since the FIFO functionality seems to be spread out all over the application you now have a hard time pinpointing the problem. I suggest you redesign the FIFO making it a class so you can test it in isolation (and post it here if you need help). Then integrate it with the application.
    Last edited by nuzzle; September 29th, 2012 at 03:59 AM.

  3. #3
    Join Date
    Jan 2012
    Location
    USA
    Posts
    91

    Re: select() returns "ready" even after producer is done (FIFO)

    My FIFO is a class, it is the producer and consumer applications use select() to monitor sockets and stdin besides the FIFO so the loop is quite involved.

    Anyways, select() is not supposed to return any error when the app on the write side is closed. Read() returns 0 for bytes read for an indication of EOF which also happens when writer is shutdown - that's is the explanation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured