lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dear all,
while digging into the source code of LuaSocket, I found this
interesting piece of code:

/*-------------------------------------------------------------------------*\
* Sends a block of data (unbuffered)
\*-------------------------------------------------------------------------*/
#define STEPSIZE 8192
static int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent) {
    p_io io = buf->io;
    p_timeout tm = buf->tm;
    size_t total = 0;
    int err = IO_DONE;
    while (total < count && err == IO_DONE) {
        size_t done;
        size_t step = (count-total <= STEPSIZE)? count-total: STEPSIZE;
        err = io->send(io->ctx, data+total, step, &done, tm);
        total += done;
    }
    *sent = total;
    buf->sent += total;
    return err;
}

(see it at http://luasocket.sourcearchive.com/documentation/2.0.1-2/buffer_8c-source.html,
same for newer versions of LuaSocket).
After a brief discussion yesterday on the #lua irc channel, I still
remain with the doubt: what is the real purpose of the STEPSIZE
constant ?
Why isn't it enough to send the full block of data to the underlying
send() primitive, and simply leverage the OS's ability to do the rest?

Also: why exactly 8192 ?

Thanks,
Valerio