adafruit/Adafruit_CC3000_Library — pull request #30 by tdicola (2013-10-25 10:24:07+00:00)
Title: Server implementation with similar interface to the Arduino Ethernet library server class

This pull request is for changes to support a TCP server interface that's almost exactly the same as that exposed by the Arduino Ethernet library. The only difference with the Ethernet library is that this server class returns an instance of a new 'Adafruit_CC3000_ClientRef' class from the server's available() function, instead of an instance of Adafruit_CC3000_Client. This client ref class acts as a reference to a client instance so there aren't issues with buffers getting copied and going out of sync. From the perspective of a library user they don't need to know or worry how this client ref class is implemented and can use it just like a client class--there's no pointer or other indirection users need to work directly with. You can see examples of the server interface in the updated echo server example, and a new chat server example (which is meant to replicate the chat server example in the Ethernet library).

This pull request was made to make as few changes to the existing client class as possible (in particular, there are no changes to the tx and rx buffers). The only major change I found I had to make was adding explicit copy constructor and assignment operator functions. With avr-gcc 4.7.2 for some reason the automatically generated versions of these were causing problems and instability (no issues with avr-gcc 4.3 though).

I tested this by running the existing examples to verify they work, and running the new echo and chat server examples to test the server. Testing was done with Arduino 1.05 using both avr-gcc 4.3 (default version) and 4.7.2 (debian/ubuntu version) on an Arduino nano (atmega 328).