[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: STEPSIZE in LuaSocket's buffer.c
- From: Marc Balmer <marc@...>
- Date: Fri, 11 May 2012 09:26:48 +0200
Am 10.05.12 13:55, schrieb Valerio Schiavoni:
> 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 ?
Indeed 8192 does not make sense. That is not even the MTU of a typical
ethernet connection.
Maybe some form of non-obvious (and maybe not-necessary) optimization?