luasocket icon indicating copy to clipboard operation
luasocket copied to clipboard

Why luasocket `client:send` send 0 (zero) byte but return 1?

Open jakitliang opened this issue 1 year ago • 6 comments

If client:send sends 0 byte within buffer[i, j].

But it returns the last index between [i, j]. So return value is within [1, j]

Which describe in document:

If successful, the method returns the index of the last byte within [i, j] that has been sent.

And

In case of error, the method returns nil, followed by an error message, followed by the index of the last byte within [i, j] that has been sent.

But what if client:send had send 1 one byte.

How to destinct the return value of client:send after send 1 byte and send 0 byte?

For example,

buffer = "abcd".
client:send(buffer)

But network is not good. Or Linux socket queue is full. Or Windows socket buffer is full.

So It doesn't send anymore buffers.

jakitliang avatar Sep 23 '23 19:09 jakitliang