1 Reply Latest reply on Apr 29, 2014 12:47 PM by JPMontero_Intel

    EthernetClient.flush() eats the response buffer

    Motarius

      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:

      EthernetClient ec;

       

      while(out_messages.waiting) {

          ec.write(out_messages.next);

         }

      ec.flush()

      if(ec.available()) {

          ec.read(buffer)

          }

       

      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?