my problem is as follows:
I'm coding (actually fixing a problem on a cusomer site) a program which receives a stream of input from a different program which I have absolutely no control over (and asking them to make a change will take a long time).
The program actually opens a thread for each connected client and each thread opens a buffer for the client's stream.
When a client is connected a thread is opened with a buffer for the stream, when a client is disconnecte the thread is closed including closing the buffer.
Opening the buffer is done with fdopen
Reading is done with fgets
and closing is done with fclose
The problem occurs when the client is not sending any input and the buffer is empty when the client is disconnected.
When trying to close with fclose, it just hangs and doesn't finish.
I assume this is because fclose flushes the buffer before closing and the flush is stuck (I also confirmed that by trying to use fflush which also got stuck).
I've searched books and have google'd to find ideas and solutions, I made several attempts. The functions that got "stuck" on me so far are: fclose, fflush, ftell and fseek
How can I close the buffer or determine that the buffer is empty?
I would appreciate any suggestion or idea
Thanks in advance