Changed buffer-per-socket to buffer-per-operation.

This is a difficult tradeoff to measure. I think large
datagrams won't be used very frequently. So it is better to
not lock a large buffer to each socket object and instead
allocate and deallocate for each operation receiving a
datagram larger than UDP_DATAGRAMSIZE.
This commit is contained in:
Diego Nehab 2015-10-06 11:33:50 +08:00
parent fd729b32a8
commit be67f63f4e
7 changed files with 64 additions and 62 deletions

View file

@ -147,6 +147,7 @@ Support, Manual">
<a href="socket.html#connect">connect</a>,
<a href="socket.html#connect">connect4</a>,
<a href="socket.html#connect">connect6</a>,
<a href="socket.html#datagramsize">_DATAGRAMSIZE</a>,
<a href="socket.html#debug">_DEBUG</a>,
<a href="dns.html#dns">dns</a>,
<a href="socket.html#gettime">gettime</a>,
@ -158,6 +159,7 @@ Support, Manual">
<a href="socket.html#skip">skip</a>,
<a href="socket.html#sleep">sleep</a>,
<a href="socket.html#setsize">_SETSIZE</a>,
<a href="socket.html#socketinvalid">_SOCKETINVALID</a>,
<a href="socket.html#source">source</a>,
<a href="tcp.html#socket.tcp">tcp</a>,
<a href="tcp.html#socket.tcp4">tcp4</a>,

View file

@ -90,7 +90,7 @@ of connect are defined as simple helper functions that restrict the
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=debug>
<p class=name id=debug>
socket.<b>_DEBUG</b>
</p>
@ -99,6 +99,19 @@ This constant is set to <tt><b>true</b></tt> if the library was compiled
with debug support.
</p>
<!-- datagramsize +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=debug>
socket.<b>_DATAGRAMSIZE</b>
</p>
<p class=description>
Default datagram size used by calls to
<a href="udp.html#receive"<tt>receive</tt></a> and
<a href="udp.html#receivefrom"><tt>receivefrom</tt></a>.
(Unless changed in compile time, the value is 8192.)
</p>
<!-- get time +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=gettime>
@ -393,6 +406,16 @@ The maximum number of sockets that the <a
href=#select><tt>select</tt></a> function can handle.
</p>
<!-- socketinvalid ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=socketinvalid>
socket.<b>_SOCKETINVALID</b>
</p>
<p class=description>
The OS value for an invalid socket.
</p>
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=try>

View file

@ -42,7 +42,7 @@
<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class="name" id="socket.udp">
socket.<b>udp(</b>[buffersize]<b>)</b>
socket.<b>udp()</b>
</p>
<p class="description">
@ -62,13 +62,6 @@ The <a href="#setpeername"><tt>setpeername</tt></a>
is used to connect the object.
</p>
<p class="parameters">
The optional <tt>buffersize</tt> parameter
specifies the size of the largest datagram that will
ever be received by the UDP object. The default value is
8192.
</p>
<p class="return">
In case of success, a new unconnected UDP object
returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
@ -92,7 +85,7 @@ href=#setoption><tt>setoption</tt></a> will fail.
<!-- socket.udp4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class="name" id="socket.udp">
socket.<b>udp4(</b>[buffersize]<b>)</b>
socket.<b>udp4()</b>
</p>
<p class="description">
@ -112,13 +105,6 @@ The <a href="#setpeername"><tt>setpeername</tt></a>
is used to connect the object.
</p>
<p class="parameters">
The optional <tt>buffersize</tt> parameter
specifies the size of the largest datagram that will
ever be received by the UDP object. The default value is
8192.
</p>
<p class="return">
In case of success, a new unconnected UDP object
returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
@ -128,7 +114,7 @@ an error message.
<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class="name" id="socket.udp6">
socket.<b>udp6(</b>[buffersize]<b>)</b>
socket.<b>udp6()</b>
</p>
<p class="description">
@ -148,13 +134,6 @@ The <a href="#setpeername"><tt>setpeername</tt></a>
is used to connect the object.
</p>
<p class="parameters">
The optional <tt>buffersize</tt> parameter
specifies the size of the largest datagram that will
ever be received by the UDP object. The default value is
8192.
</p>
<p class="return">
In case of success, a new unconnected UDP object
returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
@ -261,8 +240,10 @@ the excess bytes are discarded. If there are less then
<tt>size</tt> bytes available in the current datagram, the
available bytes are returned.
If <tt>size</tt> is omitted, the
<tt>buffersize</tt> argument at creation time is used
(which defaults to 8192 bytes).
compile-time constant <a
href=socket.html#datagramsize><tt>socket._DATAGRAMSIZE</tt></a> is used
(it defaults to 8192 bytes). Larger sizes will cause a
temporary buffer to be allocated for the operation.
</p>
<p class="return">