I just ran into this problem and it took me a few hours to figure out. This was done in the Arduino environment on the Galileo. I have a situation where my code calls EthernetClient.write() n number of times then will call EthernetClient.flush() and finally EthernetClient.available() which would call EthernetClient.read() if there were bytes waiting. This is all done in a library so the following example is expressed in psuedo code:
The problem is that EthernetClient.flush() would read all characters in the buffer and dispose of them, which means that when I called to available() it would always return 0 and nothing would be in the buffer. This seems counter to the functionality of flush() on other platforms where it's job is to write all remaining chars to the outgoing stream. Is this a bug? or is this an Arduino idiosyncrasy?
I’ve checked the EthernetClient.cpp, and the procedure for the flush function is the same for the one used in Arduino, they should have the same behaviour. You can find the definition of the flush function of the Stream class in this link http://arduino.cc/en/Reference/ClientFlush#.U1_tlfldVHU.