The change was simple. The send() function used to return the number of
bytes LuaSocket managed to get rid of by passing them down to the
transport layer. When using non-blocking I/O, we send the data piece
by piece. So the send() function accepts the indices of the first and
last byte of
a string you want to send. This avoids the creation of temporary
strings
that would be created by string.sub. Now, if you look at your loop, you
had to advance the initial position by the number of bytes that send()
actually sent. Every time you use non-blocking I/O, you would have to
do
this. So now LuaSocket returns the index of the last byte that was
sent.
On the next call, you can simply use that index.