So I'm having some issues here with efficiency on the socket / Ethernet library and TCP.
NOTE: This applies to the TCP operation mode.
Specifically, when you call the write() function on the client, it actually copies the buffer to the W5100, and then sends a packet. That's all fine and good if you want to send the packet right then, but frequently it is far more efficient to build up a buffer of what you want sent, and then send out full size packets as necessary. The worst case situation here would be to call write one byte at a time as you'll send out a packet for every single byte. That's horribly inefficient.
Now, of course I could build a buffer myself in RAM and do essentially the same thing, but that wastes RAM, and there's a perfectly good 2kB buffer on the W5100 that I could use. Ideally I'd like to send data to the 5100 buffer myself and then trigger a command to actually fire off the packet when I'm ready (or perhaps automatically if the buffer becomes full).
Has anyone done this already?
Incidentally, in the socket library it appears that there is already something like this setup for UDP sockets with the startUDP, bufferData and sendUDP functions.
Incidentally, most implementations of Berkeley Sockets implement something similar to what I'm commenting on through the Nagle algorithm (unless you set a sock option TCP_NODELAY...which will essentially mimic what the Arduino library currently does).
Here's what happens when you call EthernetClient::write().
EthernetClient::write() does some error checking and then calls send() from the socket.h library
send() will incrementally send each byte of the buffer through the SPI bus to the W5100 (through the W5100Class::send_data_processing_offset function). Once it's all there, it instructs the 5100 to send it right away, and then sits there and waits for the ACK response to come back from the remote host.
zimm0who0net:
The worst case situation here would be to call write one byte at a time as you'll send out a packet for every single byte. That's horribly inefficient.
Discovered this the hard way. I don't understand the internals of the W5100 or even TCP for that matter, but what you are proposing would seem to make a lot of sense.