Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Decent makefiles!

  • Loading branch information...
commit bce60be30fe8e9c1b0eb33128c23c93d7bca5303 1 parent d1a7243
@diegonehab diegonehab authored
Showing with 850 additions and 544 deletions.
  1. +16 −10 NEW
  2. +0 −60 config
  3. +4 −4 doc/dns.html
  4. +4 −4 doc/ftp.html
  5. +4 −4 doc/http.html
  6. +30 −47 doc/index.html
  7. +4 −4 doc/installation.html
  8. +4 −4 doc/introduction.html
  9. +4 −4 doc/ltn12.html
  10. +4 −4 doc/mime.html
  11. +5 −4 doc/reference.html
  12. +4 −4 doc/smtp.html
  13. +38 −18 doc/socket.html
  14. +8 −8 doc/tcp.html
  15. +4 −4 doc/udp.html
  16. +4 −4 doc/url.html
  17. +1 −1  etc/dispatch.lua
  18. +16 −28 luasocket.sln
  19. +14 −42 makefile
  20. +5 −2 makefile.dist
  21. +121 −55 mime.vcproj
  22. +1 −1  samples/cddb.lua
  23. +147 −70 socket.vcproj
  24. +0 −2  src/auxiliar.h
  25. +1 −1  src/buffer.c
  26. +0 −2  src/buffer.h
  27. +0 −2  src/except.h
  28. +6 −4 src/http.lua
  29. +0 −2  src/inet.h
  30. +0 −2  src/io.h
  31. +0 −2  src/luasocket.c
  32. +2 −4 src/luasocket.h
  33. +122 −34 src/makefile
  34. +8 −2 src/mime.c
  35. +2 −4 src/mime.h
  36. +74 −12 src/options.c
  37. +21 −15 src/options.h
  38. +25 −14 src/select.c
  39. +0 −2  src/select.h
  40. +5 −3 src/smtp.lua
  41. +0 −2  src/socket.h
  42. +6 −6 src/tcp.c
  43. +0 −2  src/tcp.h
  44. +15 −3 src/timeout.c
  45. +0 −2  src/timeout.h
  46. +1 −0  src/tp.lua
  47. +30 −11 src/udp.c
  48. +0 −2  src/udp.h
  49. +5 −5 src/unix.c
  50. +1 −3 src/unix.h
  51. +4 −2 src/usocket.h
  52. +6 −3 src/wsocket.h
  53. +2 −0  test/README
  54. +3 −0  test/hello.lua
  55. +5 −5 test/httptest.lua
  56. +24 −0 test/mimetest.lua
  57. +38 −5 test/testclnt.lua
  58. +2 −0  test/testmesg.lua
View
26 NEW
@@ -2,13 +2,19 @@ What's New
This is just a bug-fix/update release.
- * Improved: http.request() now supports deprecated HTTP/0.9
- servers (Florian Berger)
- * Fixed: could return "timedout" instead of "timeout" (Leo Leo)
- * Fixed: crash when reading '*a' on closed socket (Paul Ducklin);
- * Fixed: return values are consistent when reading from closed sockets;
- * Fixed: case sensitivity in headers of multipart messages in
- smtp.message() (Graham Henstridge);
- * Fixed a couple instances of error() being called instead of base.error(). These would cause an error when an error was reported. :) (Ketmar Dark);
- * Fixed: test script now uses pairs() iterator instead of the old
- Lua syntax (Robert Dodier).
+ * Fixed: manual links to home.html changed to index.html (Robert Hahn)
+ * Fixed: mime.unb64() returns empty string on results that start
+ with a null character (Robert Raschke)
+ * Fixed: HTTP now automatically redirecting on 303 and 307 (Jonathan Gray)
+ * Fixed: sleep(-1) could sleep forever wasting CPU. Now it
+ returns immediately (MPB);
+
+ * Improved: FTP commands are now sent in upper case to
+ help buggy servers (Anders Eurenius)
+ * Improved: known headers now sent in canonic
+ capitalization to help buggy servers (Joseph Stewart);
+ * Improved: Clarified tcp:receive() in the manual (MPB);
+
+ * Fixed: multicast didn't work on Windows (Herbert Leuwer, Adrian Sietsma)
+ * Fixed: select() reports an error when called with more
+ sockets than FD_SETSIZE (Lorenzo Leonini)
View
60 config
@@ -1,60 +0,0 @@
-#------
-# LuaSocket makefile configuration
-#
-
-#------
-# Output file names
-#
-EXT=so
-SOCKET_V=2.0.2
-MIME_V=1.0.2
-SOCKET_SO=socket.$(EXT).$(SOCKET_V)
-MIME_SO=mime.$(EXT).$(MIME_V)
-UNIX_SO=unix.$(EXT)
-
-#------
-# Lua includes and libraries
-#
-#LUAINC=-I/usr/local/include/lua50
-#LUAINC=-I/usr/local/include/lua5.1
-#LUAINC=-Ilua-5.1.1/src
-
-#------
-# Compat-5.1 directory
-#
-#COMPAT=compat-5.1r5
-
-#------
-# Top of your Lua installation
-# Relative paths will be inside the src tree
-#
-#INSTALL_TOP_SHARE=/usr/local/share/lua/5.0
-#INSTALL_TOP_LIB=/usr/local/lib/lua/5.0
-INSTALL_TOP_SHARE=/usr/local/share/lua/5.1
-INSTALL_TOP_LIB=/usr/local/lib/lua/5.1
-
-INSTALL_DATA=cp
-INSTALL_EXEC=cp
-
-#------
-# Compiler and linker settings
-# for Mac OS X
-#
-#CC=gcc
-#DEF= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN
-#CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common
-#LDFLAGS=-bundle -undefined dynamic_lookup
-#LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
-
-#------
-# Compiler and linker settings
-# for Linux
-CC=gcc
-DEF=-DLUASOCKET_DEBUG
-CFLAGS= $(LUAINC) $(DEF) -pedantic -Wall -O2 -fpic
-LDFLAGS=-O -shared -fpic
-LD=gcc
-
-#------
-# End of makefile configuration
-#
View
8 doc/dns.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -113,8 +113,8 @@ <h2 id=dns>DNS</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/ftp.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -270,8 +270,8 @@ <h2 id=ftp>FTP</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/http.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -314,8 +314,8 @@ <h2 id=http>HTTP</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
77 doc/index.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -87,7 +87,7 @@ <h2 id=whatis>What is LuaSocket?</h2>
<h2 id=download>Download</h2>
<p>
-LuaSocket version 2.0.2 is now available for download! It is
+LuaSocket version 2.0.3 is now available for download! It is
compatible with Lua&nbsp;5.1, and has
been tested on Windows&nbsp;XP, Linux, and Mac OS X. Chances
are it works well on most UNIX distributions and Windows flavors.
@@ -118,14 +118,15 @@ <h2 id=download>Download</h2>
<h2 id=thanks>Special thanks</h2>
<p>
-Throughout LuaSocket's history, many people gave suggestions that helped
-improve it. For that, I thank the Lua community.
-Special thanks go to
-David Burgess, who has helped push the library to a new level of quality and
-from whom I have learned a lot of stuff that doesn't show up in RFCs.
-Special thanks also to Carlos Cassino, who played a big part in the
-extensible design seen in the C core of LuaSocket 2.0. Mike Pall
-has been helping a lot too! Thanks to you all!
+Throughout LuaSocket's history, many people gave suggestions
+that helped improve it. For that, I thank the Lua community.
+Special thanks go to David Burgess, who has helped push the
+library to a new level of quality and from whom I have
+learned a lot of stuff that doesn't show up in RFCs.
+Special thanks also to Carlos Cassino, who played a big part
+in the extensible design seen in the C core of LuaSocket
+2.0. Mike Pall has been helping a lot too! Thanks to you
+all!
</p>
<!-- whatsnew +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -133,44 +134,26 @@ <h2 id=thanks>Special thanks</h2>
<h2 id=new>What's New</h2>
<p>
-2.0.2 is just a bug-fix/update release.
+2.0.3 is just a bug-fix/update release.
</p>
<ul>
-<li> Improved: http.request() now supports deprecated
-HTTP/0.9 servers (Florian Berger);
-<li> Fixed: could return "timedout" instead of "timeout" (Leo Leo);
-<li> Fixed: crash when reading '*a' on closed socket (Paul Ducklin);
-<li> Fixed: return values are consistent when reading from closed sockets;
-<li> Fixed: case sensitivity in headers of multipart
-messages in smtp.message() (Graham Henstridge);
-<li> Fixed a couple instances of error() being called instead of
-base.error(). These would cause an error when an error was
-reported :) (Ketmar Dark);
-<li> Fixed: test script now uses pairs() iterator instead
-of the old Lua syntax (Robert Dodier).
-</ul>
-
-<p>
-2.0.1 is just a bug-fix/update release.
-</p>
-
-<ul>
-<li> Updated: now using <tt>compat-5.1r5</tt>;
-<li> Improved: <tt>http.request</tt> is more robust to
-malformed URLs (Adrian Sietsma);
-<li> Improved: the simple <tt>http.request</tt> interface sends a
-"<tt>Content-type: application/x-www-form-urlencoded</tt>"
-header (William Trenker);
-<li> Improved: <tt>http.request</tt> is robust to evil
-servers that send inappropriate 100-continue messages
-(David Burgess);
-<li> Fixed: <tt>http.request</tt> was using the old host header during
-redirects (Florian Berger);
-<li> Fixed: sample <tt>unix.c</tt> had fallen through the
-cracks during development (Matthew Percival);
-<li> Fixed: error code was not being propagated correctly in
-ftp.lua (David Burgess).
+<li> Fixed: multicast didn't work on Windows, or anywhere
+ else for that matter (Herbert Leuwer, Adrian Sietsma)
+<li> Fixed: select() now reports an error when called with more
+ sockets than FD_SETSIZE (Lorenzo Leonini)
+<li> Fixed: manual links to home.html changed to index.html (Robert Hahn)
+<li> Fixed: mime.unb64() would return an empty string on results that started
+ with a null character (Robert Raschke)
+<li> Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray)
+<li> Fixed: calling sleep() with negative numbers could
+ block forever, wasting CPU. Now it returns immediately (MPB);
+<li> Improved: FTP commands are now sent in upper case to
+ help buggy servers (Anders Eurenius)
+<li> Improved: known headers now sent in canonic
+ capitalization to help buggy servers (Joseph Stewart);
+<li> Improved: Clarified tcp:receive() in the manual (MPB);
+<li> Improved: Decent makefiles (LHF).
</ul>
<!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -190,7 +173,7 @@ <h2 id=old>Old Versions</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html#download">download</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/installation.html
@@ -25,8 +25,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -144,8 +144,8 @@
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/introduction.html
@@ -25,8 +25,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -314,8 +314,8 @@ <h3 id=more>Support modules</h3>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/ltn12.html
@@ -25,8 +25,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -411,8 +411,8 @@ <h3 id="source">Sources</h3>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/mime.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -457,8 +457,8 @@ <h3 id=low>Low-level filters</h3>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
9 doc/reference.html
@@ -25,8 +25,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -151,6 +151,7 @@
<a href="socket.html#sink">sink</a>,
<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#source">source</a>,
<a href="tcp.html#tcp">tcp</a>,
<a href="socket.html#try">try</a>,
@@ -220,8 +221,8 @@
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/smtp.html
@@ -25,8 +25,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -398,8 +398,8 @@ <h2 id=smtp>SMTP</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
56 doc/socket.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -94,6 +94,24 @@ <h2 id=socket>The socket namespace</h2>
with debug support.
</p>
+<!-- get time +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
+
+<p class=name id=gettime>
+socket.<b>gettime()</b>
+</p>
+
+<p class=description>
+Returns the time in seconds, relative to the origin of the
+universe. You should subtract the values returned by this function
+to get meaningful values.
+</p>
+
+<pre class=example>
+t = socket.gettime()
+-- do stuff
+print(socket.gettime() - t .. " seconds elapsed")
+</pre>
+
<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=newtry>
@@ -200,6 +218,15 @@ <h2 id=socket>The socket namespace</h2>
</p>
<p class=note>
+<b>Note: </b>: <tt>select</tt> can monitor a limited number
+of sockets, as defined by the constant <tt>socket._SETSIZE</tt>. This
+number may be as high as 1024 or as low as 64 by default,
+depending on the system. It is usually possible to change this
+at compile time. Invoking <tt>select</tt> with a larger
+number of sockets will raise an error.
+</p>
+
+<p class=note>
<b>Important note</b>: a known bug in WinSock causes <tt>select</tt> to fail
on non-blocking TCP sockets. The function may return a socket as
writable even though the socket is <em>not</em> ready for sending.
@@ -288,8 +315,8 @@ <h2 id=socket>The socket namespace</h2>
</p>
<p class=parameters>
-<tt>Time</tt> is the number of seconds to sleep for.
-The function truncates <tt>time</tt> down to the nearest integer.
+<tt>Time</tt> is the number of seconds to sleep for. If
+<tt>time</tt> is negative, the function returns immediately.
</p>
<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -324,24 +351,17 @@ <h2 id=socket>The socket namespace</h2>
The function returns a source with the appropriate behavior.
</p>
-<!-- time ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
+<!-- setsize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
-<p class=name id=gettime>
-socket.<b>gettime()</b>
+<p class=name id=setsize>
+socket.<b>_SETSIZE</b>
</p>
<p class=description>
-Returns the time in seconds, relative to the origin of the
-universe. You should subtract the values returned by this function
-to get meaningful values.
+The maximum number of sockets that the <a
+href=#select><tt>select</tt></a> function can handle.
</p>
-<pre class=example>
-t = socket.gettime()
--- do stuff
-print(socket.gettime() - t .. " seconds elapsed")
-</pre>
-
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=try>
@@ -386,8 +406,8 @@ <h2 id=socket>The socket namespace</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
16 doc/tcp.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -297,12 +297,12 @@ <h2 id=tcp>TCP</h2>
<p class=return>
If successful, the method returns the received pattern. In case of error,
-the method returns <tt><b>nil</b></tt> followed by an error message which
-can be the string '<tt>closed</tt>' in case the connection was
+the method returns <tt><b>nil</b></tt> followed by an error
+message, followed by a (possibly empty) string containing
+the partial that was received. The error message can be
+the string '<tt>closed</tt>' in case the connection was
closed before the transmission was completed or the string
'<tt>timeout</tt>' in case there was a timeout during the operation.
-Also, after the error message, the function returns the partial result of
-the transmission.
</p>
<p class=note>
@@ -514,8 +514,8 @@ <h2 id=tcp>TCP</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/udp.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -397,8 +397,8 @@ <h2 id=udp>UDP</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
8 doc/url.html
@@ -24,8 +24,8 @@
</td></tr>
</table>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#download">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#download">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
@@ -310,8 +310,8 @@ <h2 id=url>URL</h2>
<hr>
<center>
<p class=bar>
-<a href="home.html">home</a> &middot;
-<a href="home.html#down">download</a> &middot;
+<a href="index.html">home</a> &middot;
+<a href="index.html#down">download</a> &middot;
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
View
2  etc/dispatch.lua
@@ -54,7 +54,7 @@ function socket.protect(f)
local results = {coroutine.resume(co, base.unpack(arg))}
local status = table.remove(results, 1)
if not status then
- if type(results[1]) == 'table' then
+ if base.type(results[1]) == 'table' then
return nil, results[1][1]
else base.error(results[1]) end
end
View
44 luasocket.sln
@@ -1,37 +1,25 @@
-Microsoft Visual Studio Solution File, Format Version 8.00
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "socket", "socket.vcproj", "{66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}"
- ProjectSection(ProjectDependencies) = postProject
- EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mime", "mime.vcproj", "{128E8BD0-174A-48F0-8771-92B1E8D18713}"
- ProjectSection(ProjectDependencies) = postProject
- EndProjectSection
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libluasocket", "libluasocket.vcproj", "{599EAD40-60EE-4043-9C14-AE090A8A092D}"
- ProjectSection(ProjectDependencies) = postProject
- EndProjectSection
EndProject
Global
- GlobalSection(SolutionConfiguration) = preSolution
- Debug = Debug
- Release = Release
- EndGlobalSection
- GlobalSection(ProjectConfiguration) = postSolution
- {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Debug.ActiveCfg = Debug|Win32
- {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Debug.Build.0 = Debug|Win32
- {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Release.ActiveCfg = Release|Win32
- {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Release.Build.0 = Release|Win32
- {128E8BD0-174A-48F0-8771-92B1E8D18713}.Debug.ActiveCfg = Debug|Win32
- {128E8BD0-174A-48F0-8771-92B1E8D18713}.Debug.Build.0 = Debug|Win32
- {128E8BD0-174A-48F0-8771-92B1E8D18713}.Release.ActiveCfg = Release|Win32
- {128E8BD0-174A-48F0-8771-92B1E8D18713}.Release.Build.0 = Release|Win32
- {599EAD40-60EE-4043-9C14-AE090A8A092D}.Debug.ActiveCfg = Debug|Win32
- {599EAD40-60EE-4043-9C14-AE090A8A092D}.Debug.Build.0 = Debug|Win32
- {599EAD40-60EE-4043-9C14-AE090A8A092D}.Release.ActiveCfg = Release|Win32
- {599EAD40-60EE-4043-9C14-AE090A8A092D}.Release.Build.0 = Release|Win32
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Debug|Win32.ActiveCfg = Debug|Win32
+ {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Debug|Win32.Build.0 = Debug|Win32
+ {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Release|Win32.ActiveCfg = Release|Win32
+ {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}.Release|Win32.Build.0 = Release|Win32
+ {128E8BD0-174A-48F0-8771-92B1E8D18713}.Debug|Win32.ActiveCfg = Debug|Win32
+ {128E8BD0-174A-48F0-8771-92B1E8D18713}.Debug|Win32.Build.0 = Debug|Win32
+ {128E8BD0-174A-48F0-8771-92B1E8D18713}.Release|Win32.ActiveCfg = Release|Win32
+ {128E8BD0-174A-48F0-8771-92B1E8D18713}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
- GlobalSection(ExtensibilityAddIns) = postSolution
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
View
56 makefile
@@ -1,51 +1,23 @@
-#------
-# Load configuration
-#
-include config
+PLAT= none
+PLATS= macosx linux
#------
# Hopefully no need to change anything below this line
#
-INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket
-INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket
-INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime
-INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime
-
-all clean:
- cd src; $(MAKE) $@
+all: $(PLAT)
-#------
-# Files to install
-#
-TO_SOCKET_SHARE:= \
- http.lua \
- url.lua \
- tp.lua \
- ftp.lua \
- smtp.lua
+none:
+ @echo "Please run"
+ @echo " make PLATFORM"
+ @echo "where PLATFORM is one of these:"
+ @echo " $(PLATS)"
-TO_TOP_SHARE:= \
- ltn12.lua \
- socket.lua \
- mime.lua
+$(PLATS) install local clean:
+ cd src; $(MAKE) $@
-TO_MIME_SHARE:=
+dummy:
-#------
-# Install LuaSocket according to recommendation
-#
-install: all
- cd src; mkdir -p $(INSTALL_TOP_SHARE)
- cd src; $(INSTALL_DATA) $(TO_TOP_SHARE) $(INSTALL_TOP_SHARE)
- cd src; mkdir -p $(INSTALL_SOCKET_SHARE)
- cd src; $(INSTALL_DATA) $(TO_SOCKET_SHARE) $(INSTALL_SOCKET_SHARE)
- cd src; mkdir -p $(INSTALL_SOCKET_LIB)
- cd src; $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_LIB)/core.$(EXT)
- #cd src; mkdir -p $(INSTALL_MIME_SHARE)
- #cd src; $(INSTALL_DATA) $(TO_MIME_SHARE) $(INSTALL_MIME_SHARE)
- cd src; mkdir -p $(INSTALL_MIME_LIB)
- cd src; $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_LIB)/core.$(EXT)
+test: dummy
+ lua test/hello.lua
-#------
-# End of makefile
-#
+.PHONY: dummy
View
7 makefile.dist
@@ -1,10 +1,11 @@
#--------------------------------------------------------------------------
# Distribution makefile
#--------------------------------------------------------------------------
-DIST = luasocket-2.0.2
+DIST = luasocket-2.0.3
TEST = \
test/README \
+ test/hello.lua \
test/testclnt.lua \
test/testsrvr.lua \
test/testsupport.lua
@@ -15,6 +16,8 @@ SAMPLES = \
samples/daytimeclnt.lua \
samples/echoclnt.lua \
samples/echosrvr.lua \
+ samples/mclisten.lua \
+ samples/mcsend.lua \
samples/listener.lua \
samples/lpr.lua \
samples/talker.lua \
@@ -73,12 +76,12 @@ SRC = \
src/mime.lua \
src/smtp.lua \
src/socket.lua \
+ src/headers.lua \
src/tp.lua \
src/url.lua
MAKE = \
makefile \
- config \
luasocket.sln \
socket.vcproj \
mime.vcproj
View
176 mime.vcproj
@@ -1,114 +1,179 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="7.10"
+ Version="9.00"
Name="mime"
ProjectGUID="{128E8BD0-174A-48F0-8771-92B1E8D18713}"
- Keyword="Win32Proj">
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
<Platforms>
<Platform
- Name="Win32"/>
+ Name="Win32"
+ />
</Platforms>
+ <ToolFiles>
+ </ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="src"
IntermediateDirectory="src"
ConfigurationType="2"
- CharacterSet="2">
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="h:\include\lua5.1"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_EXPORTS;MIME_API=__declspec(dllexport)"
- MinimalRebuild="TRUE"
+ AdditionalIncludeDirectories="..\lua-5.1.4\src"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_EXPORTS;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS"
+ MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"/>
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="4"
+ />
<Tool
- Name="VCCustomBuildTool"/>
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
<Tool
Name="VCLinkerTool"
+ AdditionalDependencies="lua5.1.lib"
OutputFile="$(OutDir)/mime.dll"
LinkIncremental="2"
- AdditionalLibraryDirectories="h:\lib"
- GenerateDebugInformation="TRUE"
+ AdditionalLibraryDirectories="..\lua-5.1.4"
+ GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/mime.pdb"
SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/mime.lib"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
+ TargetMachine="1"
+ />
<Tool
- Name="VCPreLinkEventTool"/>
+ Name="VCALinkTool"
+ />
<Tool
- Name="VCResourceCompilerTool"/>
+ Name="VCManifestTool"
+ />
<Tool
- Name="VCWebServiceProxyGeneratorTool"/>
+ Name="VCXDCMakeTool"
+ />
<Tool
- Name="VCXMLDataGeneratorTool"/>
+ Name="VCBscMakeTool"
+ />
<Tool
- Name="VCWebDeploymentTool"/>
+ Name="VCFxCopTool"
+ />
<Tool
- Name="VCManagedWrapperGeneratorTool"/>
+ Name="VCAppVerifierTool"
+ />
<Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ Name="VCPostBuildEventTool"
+ />
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="src"
IntermediateDirectory="src"
ConfigurationType="2"
- CharacterSet="2">
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="h:\include\lua5.1"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_EXPORTS; MIME_API=__declspec(dllexport)"
+ AdditionalIncludeDirectories="..\lua-5.1.4\src"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_EXPORTS; MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="4"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="0"/>
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="0"
+ />
<Tool
- Name="VCCustomBuildTool"/>
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
<Tool
Name="VCLinkerTool"
+ AdditionalDependencies="lua5.1.lib"
OutputFile="$(OutDir)/mime.dll"
LinkIncremental="1"
- AdditionalLibraryDirectories="h:\lib"
- GenerateDebugInformation="TRUE"
+ AdditionalLibraryDirectories="..\lua-5.1.4"
+ GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/mime.lib"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
+ TargetMachine="1"
+ />
<Tool
- Name="VCPreLinkEventTool"/>
+ Name="VCALinkTool"
+ />
<Tool
- Name="VCResourceCompilerTool"/>
+ Name="VCManifestTool"
+ />
<Tool
- Name="VCWebServiceProxyGeneratorTool"/>
+ Name="VCXDCMakeTool"
+ />
<Tool
- Name="VCXMLDataGeneratorTool"/>
+ Name="VCBscMakeTool"
+ />
<Tool
- Name="VCWebDeploymentTool"/>
+ Name="VCFxCopTool"
+ />
<Tool
- Name="VCManagedWrapperGeneratorTool"/>
+ Name="VCAppVerifierTool"
+ />
<Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ Name="VCPostBuildEventTool"
+ />
</Configuration>
</Configurations>
<References>
@@ -117,24 +182,25 @@
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
<File
- RelativePath="src\mime.c">
+ RelativePath="src\mime.c"
+ >
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
</Filter>
- <File
- RelativePath="..\..\lib\lua5.1.dll.lib">
- </File>
</Files>
<Globals>
</Globals>
View
2  samples/cddb.lua
@@ -32,7 +32,7 @@ end
local host = socket.dns.gethostname()
local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6"
local url = string.format(query, server, arg[1], arg[2], host)
-local body, headers, code = http.get(url)
+local body, headers, code = http.request(url)
if code == 200 then
local data, code, error = parse(body)
View
217 socket.vcproj
@@ -1,116 +1,179 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="7.10"
+ Version="9.00"
Name="socket"
ProjectGUID="{66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A}"
- Keyword="Win32Proj">
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
<Platforms>
<Platform
- Name="Win32"/>
+ Name="Win32"
+ />
</Platforms>
+ <ToolFiles>
+ </ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="src"
IntermediateDirectory="src"
ConfigurationType="2"
- CharacterSet="2">
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="h:\include\lua5.1"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_EXPORTS;LUASOCKET_API=__declspec(dllexport)"
- MinimalRebuild="TRUE"
+ AdditionalIncludeDirectories="..\lua-5.1.4\src"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_EXPORTS;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS"
+ MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"/>
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="4"
+ />
<Tool
- Name="VCCustomBuildTool"/>
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="ws2_32.lib"
+ AdditionalDependencies="ws2_32.lib lua5.1.lib"
OutputFile="$(OutDir)/socket.dll"
LinkIncremental="2"
- AdditionalLibraryDirectories="h:\lib"
- GenerateDebugInformation="TRUE"
+ AdditionalLibraryDirectories="..\lua-5.1.4"
+ GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/socket.pdb"
SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/socket.lib"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
+ TargetMachine="1"
+ />
<Tool
- Name="VCPreLinkEventTool"/>
+ Name="VCALinkTool"
+ />
<Tool
- Name="VCResourceCompilerTool"/>
+ Name="VCManifestTool"
+ />
<Tool
- Name="VCWebServiceProxyGeneratorTool"/>
+ Name="VCXDCMakeTool"
+ />
<Tool
- Name="VCXMLDataGeneratorTool"/>
+ Name="VCBscMakeTool"
+ />
<Tool
- Name="VCWebDeploymentTool"/>
+ Name="VCFxCopTool"
+ />
<Tool
- Name="VCManagedWrapperGeneratorTool"/>
+ Name="VCAppVerifierTool"
+ />
<Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ Name="VCPostBuildEventTool"
+ />
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="./src"
IntermediateDirectory="./src"
ConfigurationType="2"
- CharacterSet="2">
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="h:\include\lua5.1"
- PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_EXPORTS;LUASOCKET_API=__declspec(dllexport); LUASOCKET_DEBUG"
+ AdditionalIncludeDirectories="..\lua-5.1.4\src"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_EXPORTS;LUASOCKET_API=__declspec(dllexport); LUASOCKET_DEBUG; _CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="0"/>
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="0"
+ />
<Tool
- Name="VCCustomBuildTool"/>
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="ws2_32.lib"
+ AdditionalDependencies="ws2_32.lib lua5.1.lib"
OutputFile="$(OutDir)/socket.dll"
LinkIncremental="1"
- AdditionalLibraryDirectories="h:\lib"
- GenerateDebugInformation="TRUE"
+ AdditionalLibraryDirectories="..\lua-5.1.4"
+ GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/socket.lib"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
+ TargetMachine="1"
+ />
<Tool
- Name="VCPreLinkEventTool"/>
+ Name="VCALinkTool"
+ />
<Tool
- Name="VCResourceCompilerTool"/>
+ Name="VCManifestTool"
+ />
<Tool
- Name="VCWebServiceProxyGeneratorTool"/>
+ Name="VCXDCMakeTool"
+ />
<Tool
- Name="VCXMLDataGeneratorTool"/>
+ Name="VCBscMakeTool"
+ />
<Tool
- Name="VCWebDeploymentTool"/>
+ Name="VCFxCopTool"
+ />
<Tool
- Name="VCManagedWrapperGeneratorTool"/>
+ Name="VCAppVerifierTool"
+ />
<Tool
- Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ Name="VCPostBuildEventTool"
+ />
</Configuration>
</Configurations>
<References>
@@ -119,63 +182,77 @@
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
- UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
<File
- RelativePath="src\auxiliar.c">
+ RelativePath="src\auxiliar.c"
+ >
</File>
<File
- RelativePath="src\buffer.c">
+ RelativePath="src\buffer.c"
+ >
</File>
<File
- RelativePath="src\except.c">
+ RelativePath="src\except.c"
+ >
</File>
<File
- RelativePath="src\inet.c">
+ RelativePath="src\inet.c"
+ >
</File>
<File
- RelativePath="src\io.c">
+ RelativePath="src\io.c"
+ >
</File>
<File
- RelativePath="src\luasocket.c">
+ RelativePath="src\luasocket.c"
+ >
</File>
<File
- RelativePath="src\options.c">
+ RelativePath="src\options.c"
+ >
</File>
<File
- RelativePath="src\select.c">
+ RelativePath="src\select.c"
+ >
</File>
<File
- RelativePath="src\tcp.c">
+ RelativePath="src\tcp.c"
+ >
</File>
<File
- RelativePath="src\timeout.c">
+ RelativePath="src\timeout.c"
+ >
</File>
<File
- RelativePath="src\udp.c">
+ RelativePath="src\udp.c"
+ >
</File>
<File
- RelativePath="src\wsocket.c">
+ RelativePath="src\wsocket.c"
+ >
<FileConfiguration
- Name="Release|Win32">
+ Name="Release|Win32"
+ >
<Tool
Name="VCCLCompilerTool"
- GeneratePreprocessedFile="0"/>
+ GeneratePreprocessedFile="0"
+ />
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
- UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
- UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
</Filter>
- <File
- RelativePath="..\..\lib\lua5.1.dll.lib">
- </File>
</Files>
<Globals>
</Globals>
View
2  src/auxiliar.h
@@ -27,8 +27,6 @@
*
* The mapping from class name to the corresponding metatable and the
* reverse mapping are done using lauxlib.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
View
2  src/buffer.c
@@ -166,7 +166,7 @@ static int sendraw(p_buffer buf, const char *data, size_t count, size_t *sent) {
size_t total = 0;
int err = IO_DONE;
while (total < count && err == IO_DONE) {
- size_t done;
+ size_t done = 0;
size_t step = (count-total <= STEPSIZE)? count-total: STEPSIZE;
err = io->send(io->ctx, data+total, step, &done, tm);
total += done;
View
2  src/buffer.h
@@ -14,8 +14,6 @@
*
* The module is built on top of the I/O abstraction defined in io.h and the
* timeout management is done with the timeout.h interface.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
View
2  src/except.h
@@ -24,8 +24,6 @@
*
* With these two function, it's easy to write functions that throw
* exceptions on error, but that don't interrupt the user script.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
View
10 src/http.lua
@@ -13,6 +13,7 @@ local url = require("socket.url")
local ltn12 = require("ltn12")
local mime = require("mime")
local string = require("string")
+local headers = require("socket.headers")
local base = _G
local table = require("table")
module("socket.http")
@@ -123,10 +124,11 @@ function metat.__index:sendrequestline(method, uri)
return self.try(self.c:send(reqline))
end
-function metat.__index:sendheaders(headers)
+function metat.__index:sendheaders(tosend)
+ local canonic = headers.canonic
local h = "\r\n"
- for i, v in base.pairs(headers) do
- h = i .. ": " .. v .. "\r\n" .. h
+ for f, v in base.pairs(tosend) do
+ h = (canonic[f] or f) .. ": " .. v .. "\r\n" .. h
end
self.try(self.c:send(h))
return 1
@@ -254,7 +256,7 @@ local function shouldredirect(reqt, code, headers)
return headers.location and
string.gsub(headers.location, "%s", "") ~= "" and
(reqt.redirect ~= false) and
- (code == 301 or code == 302) and
+ (code == 301 or code == 302 or code == 303 or code == 307) and
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
and (not reqt.nredirects or reqt.nredirects < 5)
end
View
2  src/inet.h
@@ -13,8 +13,6 @@
* getpeername and getsockname functions as seen by Lua programs.
*
* The Lua functions toip and tohostname are also implemented here.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
#include "socket.h"
View
2  src/io.h
@@ -11,8 +11,6 @@
*
* The module socket.h implements this interface, and thus the module tcp.h
* is very simple.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include <stdio.h>
#include "lua.h"
View
2  src/luasocket.c
@@ -10,8 +10,6 @@
* involved in setting up both client and server connections. The provided
* IO routines, however, follow the Lua style, being very similar to the
* standard Lua read and write functions.
-*
-* RCS ID: $Id$
\*=========================================================================*/
/*=========================================================================*\
View
6 src/luasocket.h
@@ -5,16 +5,14 @@
* Networking support for the Lua language
* Diego Nehab
* 9/11/1999
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
/*-------------------------------------------------------------------------*\
* Current socket library version
\*-------------------------------------------------------------------------*/
-#define LUASOCKET_VERSION "LuaSocket 2.0.2"
-#define LUASOCKET_COPYRIGHT "Copyright (C) 2004-2007 Diego Nehab"
+#define LUASOCKET_VERSION "LuaSocket 2.0.3"
+#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2009 Diego Nehab"
#define LUASOCKET_AUTHORS "Diego Nehab"
/*-------------------------------------------------------------------------*\
View
156 src/makefile
@@ -1,39 +1,86 @@
+PLAT = none
+INSTALL_DATA=cp
+INSTALL_EXEC=cp
+INSTALL_TOP= /opt/local
+LUAINC= $(LUAINC_$(PLAT))
+
#------
-# Load configuration
+# Install directories
#
-include ../config
+INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/5.1
+INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/5.1
+INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket
+INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket
+INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime
+INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime
#------
-# Hopefully no need to change anything below this line
+# Output file names
#
+EXT=so
+SOCKET_V=2.0.3
+MIME_V=1.0.3
+SOCKET_SO=socket.$(EXT).$(SOCKET_V)
+MIME_SO=mime.$(EXT).$(MIME_V)
+UNIX_SO=unix.$(EXT)
#------
-# Modules belonging to socket-core
-#
+# Compiler and linker settings
+# for Mac OS X
+LUAINC_macosx= -I/opt/local/include
+CC_macosx=gcc
+DEF_macosx= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN \
+ -DLUASOCKET_API='__attribute__((visibility("default")))' \
+ -DMIME_API='__attribute__((visibility("default")))'
+CFLAGS_macosx= $(LUAINC) $(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common \
+ -fvisibility=hidden
+LDFLAGS_macosx= -bundle -undefined dynamic_lookup
+LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
-#$(COMPAT)/compat-5.1.o \
+#------
+# Compiler and linker settings
+# for Linux
+LUAINC_linux= -I/usr/local/include/lua5.1
+CC_linux=gcc
+DEF_linux=-DLUASOCKET_DEBUG \
+ -DLUASOCKET_API='__attribute__((visibility("default")))' \
+ -DMIME_API='__attribute__((visibility("default")))'
+CFLAGS_linux= $(LUAINC) $(DEF) -pedantic -Wall -O2 -fpic \
+ -fvisibility=hidden
+LDFLAGS_linux=-O -shared -fpic
+LD_linux= gcc
-SOCKET_OBJS:= \
+#------
+# Settings selected for platform
+#
+CC=$(CC_$(PLAT))
+DEF=$(DEF_$(PLAT))
+CFLAGS=$(CFLAGS_$(PLAT))
+LDFLAGS=$(LDFLAGS_$(PLAT))
+LD=$(LD_$(PLAT))
+
+#------
+# Modules belonging to socket-core
+#
+SOCKET_OBJS= \
luasocket.o \
timeout.o \
buffer.o \
io.o \
- auxiliar.o \
+ auxiliar.o \
options.o \
inet.o \
- tcp.o \
- udp.o \
+ usocket.o \
except.o \
select.o \
- usocket.o
+ tcp.o \
+ udp.o
#------
# Modules belonging mime-core
#
-#$(COMPAT)/compat-5.1.o \
-
-MIME_OBJS:=\
- mime.o
+MIME_OBJS= \
+ mime.o
#------
# Modules belonging unix (local domain sockets)
@@ -47,7 +94,35 @@ UNIX_OBJS:=\
usocket.o \
unix.o
-all: $(SOCKET_SO) $(MIME_SO)
+#------
+# Files to install
+#
+TO_SOCKET_SHARE:= \
+ http.lua \
+ url.lua \
+ tp.lua \
+ ftp.lua \
+ headers.lua \
+ smtp.lua
+
+TO_TOP_SHARE:= \
+ ltn12.lua \
+ socket.lua \
+ mime.lua
+
+default: $(PLAT)
+
+macosx:
+ $(MAKE) all PLAT=macosx
+
+linux:
+ $(MAKE) all PLAT=linux
+
+none:
+ @echo "Please choose a platform:"
+ @echo " $(PLATS)"
+
+all: $(SOCKET_SO) $(MIME_SO)
$(SOCKET_SO): $(SOCKET_OBJS)
$(LD) $(LDFLAGS) -o $@ $(SOCKET_OBJS)
@@ -58,6 +133,25 @@ $(MIME_SO): $(MIME_OBJS)
$(UNIX_SO): $(UNIX_OBJS)
$(LD) $(LDFLAGS) -o $@ $(UNIX_OBJS)
+install:
+ mkdir -p $(INSTALL_TOP_SHARE)
+ $(INSTALL_DATA) $(TO_TOP_SHARE) $(INSTALL_TOP_SHARE)
+ mkdir -p $(INSTALL_SOCKET_SHARE)
+ $(INSTALL_DATA) $(TO_SOCKET_SHARE) $(INSTALL_SOCKET_SHARE)
+ mkdir -p $(INSTALL_SOCKET_LIB)
+ $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_LIB)/core.$(EXT)
+ mkdir -p $(INSTALL_MIME_LIB)
+ $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_LIB)/core.$(EXT)
+
+local:
+ $(MAKE) install INSTALL_TOP_LIB=.. INSTALL_TOP_SHARE=..
+
+clean:
+ rm -f $(SOCKET_SO) $(SOCKET_OBJS)
+ rm -f $(MIME_SO) $(UNIX_SO) $(MIME_OBJS) $(UNIX_OBJS)
+
+.PHONY: all $(PLATS) default clean echo none
+
#------
# List of dependencies
#
@@ -66,25 +160,19 @@ buffer.o: buffer.c buffer.h io.h timeout.h
except.o: except.c except.h
inet.o: inet.c inet.h socket.h io.h timeout.h usocket.h
io.o: io.c io.h timeout.h
-luasocket.o: luasocket.c luasocket.h auxiliar.h except.h timeout.h \
- buffer.h io.h inet.h socket.h usocket.h tcp.h udp.h select.h
+luasocket.o: luasocket.c luasocket.h auxiliar.h except.h \
+ timeout.h buffer.h io.h inet.h socket.h usocket.h tcp.h \
+ udp.h select.h
mime.o: mime.c mime.h
-options.o: options.c auxiliar.h options.h socket.h io.h timeout.h \
- usocket.h inet.h
+options.o: options.c auxiliar.h options.h socket.h io.h \
+ timeout.h usocket.h inet.h
select.o: select.c socket.h io.h timeout.h usocket.h select.h
-tcp.o: tcp.c auxiliar.h socket.h io.h timeout.h usocket.h inet.h \
- options.h tcp.h buffer.h
+tcp.o: tcp.c auxiliar.h socket.h io.h timeout.h usocket.h \
+ inet.h options.h tcp.h buffer.h
timeout.o: timeout.c auxiliar.h timeout.h
-udp.o: udp.c auxiliar.h socket.h io.h timeout.h usocket.h inet.h \
- options.h udp.h
-unix.o: unix.c auxiliar.h socket.h io.h timeout.h usocket.h options.h \
- unix.h buffer.h
+udp.o: udp.c auxiliar.h socket.h io.h timeout.h usocket.h \
+ inet.h options.h udp.h
+unix.o: unix.c auxiliar.h socket.h io.h timeout.h usocket.h \
+ options.h unix.h buffer.h
usocket.o: usocket.c socket.h io.h timeout.h usocket.h
-
-clean:
- rm -f $(SOCKET_SO) $(SOCKET_OBJS)
- rm -f $(MIME_SO) $(UNIX_SO) $(MIME_OBJS) $(UNIX_OBJS)
-
-#------
-# End of makefile configuration
-#
+wsocket.o: wsocket.c socket.h io.h timeout.h usocket.h
View
10 src/mime.c
@@ -272,9 +272,12 @@ static int mime_global_b64(lua_State *L)
input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
/* if second part is nil, we are done */
if (!input) {
+ size_t osize = 0;
asize = b64pad(atom, asize, &buffer);
luaL_pushresult(&buffer);
- if (!(*lua_tostring(L, -1))) lua_pushnil(L);
+ /* if the output is empty and the input is nil, return nil */
+ lua_tolstring(L, -1, &osize);
+ if (osize == 0) lua_pushnil(L);
lua_pushnil(L);
return 2;
}
@@ -313,8 +316,11 @@ static int mime_global_unb64(lua_State *L)
input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
/* if second is nil, we are done */
if (!input) {
+ size_t osize = 0;
luaL_pushresult(&buffer);
- if (!(*lua_tostring(L, -1))) lua_pushnil(L);
+ /* if the output is empty and the input is nil, return nil */
+ lua_tolstring(L, -1, &osize);
+ if (osize == 0) lua_pushnil(L);
lua_pushnil(L);
return 2;
}
View
6 src/mime.h
@@ -7,16 +7,14 @@
* This module provides functions to implement transfer content encodings
* and formatting conforming to RFC 2045. It is used by mime.lua, which
* provide a higher level interface to this functionality.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
/*-------------------------------------------------------------------------*\
* Current MIME library version
\*-------------------------------------------------------------------------*/
-#define MIME_VERSION "MIME 1.0.2"
-#define MIME_COPYRIGHT "Copyright (C) 2004-2007 Diego Nehab"
+#define MIME_VERSION "MIME 1.0.3"
+#define MIME_COPYRIGHT "Copyright (C) 2004-2009 Diego Nehab"
#define MIME_AUTHORS "Diego Nehab"
/*-------------------------------------------------------------------------*\
View
86 src/options.c
@@ -12,12 +12,12 @@
#include "options.h"
#include "inet.h"
-
/*=========================================================================*\
* Internal functions prototypes
\*=========================================================================*/
static int opt_setmembership(lua_State *L, p_socket ps, int level, int name);
static int opt_setboolean(lua_State *L, p_socket ps, int level, int name);
+static int opt_getboolean(lua_State *L, p_socket ps, int level, int name);
static int opt_set(lua_State *L, p_socket ps, int level, int name,
void *val, int len);
@@ -40,39 +40,63 @@ int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps)
return opt->func(L, ps);
}
+int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
+{
+ const char *name = luaL_checkstring(L, 2); /* obj, name, ... */
+ while (opt->name && strcmp(name, opt->name))
+ opt++;
+ if (!opt->func) {
+ char msg[45];
+ sprintf(msg, "unsupported option `%.35s'", name);
+ luaL_argerror(L, 2, msg);
+ }
+ return opt->func(L, ps);
+}
+
/* enables reuse of local address */
-int opt_reuseaddr(lua_State *L, p_socket ps)
+int opt_set_reuseaddr(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR);
}
+/* enables reuse of local port */
+int opt_set_reuseport(lua_State *L, p_socket ps)
+{
+ return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT);
+}
+
/* disables the Naggle algorithm */
-int opt_tcp_nodelay(lua_State *L, p_socket ps)
+int opt_set_tcp_nodelay(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY);
}
-int opt_keepalive(lua_State *L, p_socket ps)
+int opt_set_keepalive(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE);
}
-int opt_dontroute(lua_State *L, p_socket ps)
+int opt_set_dontroute(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE);
}
-int opt_broadcast(lua_State *L, p_socket ps)
+int opt_set_broadcast(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST);
}
-int opt_ip_multicast_loop(lua_State *L, p_socket ps)
+int opt_set_ip_multicast_loop(lua_State *L, p_socket ps)
{
return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
}
-int opt_linger(lua_State *L, p_socket ps)
+int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
+{
+ return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP);
+}
+
+int opt_set_linger(lua_State *L, p_socket ps)
{
struct linger li; /* obj, name, table */
if (!lua_istable(L, 3)) luaL_typerror(L, 3, lua_typename(L, LUA_TTABLE));
@@ -89,18 +113,43 @@ int opt_linger(lua_State *L, p_socket ps)
return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));
}
-int opt_ip_multicast_ttl(lua_State *L, p_socket ps)
+int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps)
{
int val = (int) luaL_checknumber(L, 3); /* obj, name, int */
- return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &val, sizeof(val));
+ return opt_set(L, ps, IPPROTO_IP, IP_MULTICAST_TTL,
+ (char *) &val, sizeof(val));
+}
+
+int opt_set_ip_multicast_if(lua_State *L, p_socket ps)
+{
+ const char *address = luaL_checkstring(L, 3); /* obj, name, ip */
+ struct in_addr val;
+ val.s_addr = htonl(INADDR_ANY);
+ if (strcmp(address, "*") && !inet_aton(address, &val))
+ luaL_argerror(L, 3, "ip expected");
+ return opt_set(L, ps, IPPROTO_IP, IP_MULTICAST_IF,
+ (char *) &val, sizeof(val));
+}
+
+int opt_get_ip_multicast_if(lua_State *L, p_socket ps)
+{
+ struct in_addr val;
+ socklen_t len = sizeof(val);
+ if (getsockopt(*ps, IPPROTO_IP, IP_MULTICAST_IF, (char *) &val, &len) < 0) {
+ lua_pushnil(L);
+ lua_pushstring(L, "getsockopt failed");
+ return 2;
+ }
+ lua_pushstring(L, inet_ntoa(val));
+ return 1;
}
-int opt_ip_add_membership(lua_State *L, p_socket ps)
+int opt_set_ip_add_membership(lua_State *L, p_socket ps)
{
return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP);
}
-int opt_ip_drop_membersip(lua_State *L, p_socket ps)
+int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
{
return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP);
}
@@ -141,6 +190,19 @@ int opt_set(lua_State *L, p_socket ps, int level, int name, void *val, int len)
return 1;
}
+static int opt_getboolean(lua_State *L, p_socket ps, int level, int name)
+{
+ int val = 0;
+ socklen_t len = sizeof(val);
+ if (getsockopt(*ps, level, name, (char *) &val, &len) < 0) {
+ lua_pushnil(L);
+ lua_pushstring(L, "getsockopt failed");
+ return 2;
+ }
+ lua_pushboolean(L, val);
+ return 1;
+}
+
static int opt_setboolean(lua_State *L, p_socket ps, int level, int name)
{
int val = auxiliar_checkboolean(L, 3); /* obj, name, bool */
View
36 src/options.h
@@ -6,8 +6,6 @@
*
* This module provides a common interface to socket options, used mainly by
* modules UDP and TCP.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "lua.h"
@@ -20,20 +18,28 @@ typedef struct t_opt {
} t_opt;
typedef t_opt *p_opt;
-/* supported options */
-int opt_dontroute(lua_State *L, p_socket ps);
-int opt_broadcast(lua_State *L, p_socket ps);
-int opt_reuseaddr(lua_State *L, p_socket ps);
-int opt_tcp_nodelay(lua_State *L, p_socket ps);
-int opt_keepalive(lua_State *L, p_socket ps);
-int opt_linger(lua_State *L, p_socket ps);
-int opt_reuseaddr(lua_State *L, p_socket ps);
-int opt_ip_multicast_ttl(lua_State *L, p_socket ps);
-int opt_ip_multicast_loop(lua_State *L, p_socket ps);
-int opt_ip_add_membership(lua_State *L, p_socket ps);
-int opt_ip_drop_membersip(lua_State *L, p_socket ps);
-
+/* supported options for setoption */
+int opt_set_dontroute(lua_State *L, p_socket ps);
+int opt_set_broadcast(lua_State *L, p_socket ps);
+int opt_set_reuseaddr(lua_State *L, p_socket ps);
+int opt_set_tcp_nodelay(lua_State *L, p_socket ps);
+int opt_set_keepalive(lua_State *L, p_socket ps);
+int opt_set_linger(lua_State *L, p_socket ps);
+int opt_set_reuseaddr(lua_State *L, p_socket ps);
+int opt_set_reuseport(lua_State *L, p_socket ps);
+int opt_set_ip_multicast_if(lua_State *L, p_socket ps);
+int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps);
+int opt_set_ip_multicast_loop(lua_State *L, p_socket ps);
+int opt_set_ip_add_membership(lua_State *L, p_socket ps);
+int opt_set_ip_drop_membersip(lua_State *L, p_socket ps);
/* invokes the appropriate option handler */
int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps);
+/* supported options for getoption */
+int opt_get_ip_multicast_loop(lua_State *L, p_socket ps);
+int opt_get_ip_multicast_if(lua_State *L, p_socket ps);
+/* invokes the appropriate option handler */
+int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps);
+
+
#endif
View
39 src/select.c
@@ -18,8 +18,8 @@
\*=========================================================================*/
static t_socket getfd(lua_State *L);
static int dirty(lua_State *L);
-static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd,
- int itab, fd_set *set);
+static void collect_fd(lua_State *L, int tab, int itab,
+ fd_set *set, t_socket *max_fd);
static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set);
static void return_fd(lua_State *L, fd_set *set, t_socket max_fd,
int itab, int tab, int start);
@@ -39,6 +39,9 @@ static luaL_reg func[] = {
* Initializes module
\*-------------------------------------------------------------------------*/
int select_open(lua_State *L) {
+ lua_pushstring(L, "_SETSIZE");
+ lua_pushnumber(L, FD_SETSIZE);
+ lua_rawset(L, -3);
luaL_openlib(L, NULL, func, 0);
return 0;
}
@@ -51,7 +54,7 @@ int select_open(lua_State *L) {
\*-------------------------------------------------------------------------*/
static int global_select(lua_State *L) {
int rtab, wtab, itab, ret, ndirty;
- t_socket max_fd;
+ t_socket max_fd = SOCKET_INVALID;
fd_set rset, wset;
t_timeout tm;
double t = luaL_optnumber(L, 3, -1);
@@ -60,12 +63,12 @@ static int global_select(lua_State *L) {
lua_newtable(L); itab = lua_gettop(L);
lua_newtable(L); rtab = lua_gettop(L);
lua_newtable(L); wtab = lua_gettop(L);
- max_fd = collect_fd(L, 1, SOCKET_INVALID, itab, &rset);
+ collect_fd(L, 1, itab, &rset, &max_fd);
+ collect_fd(L, 2, itab, &wset, &max_fd);
ndirty = check_dirty(L, 1, rtab, &rset);
t = ndirty > 0? 0.0: t;
timeout_init(&tm, t, -1);
timeout_markstart(&tm);
- max_fd = collect_fd(L, 2, max_fd, itab, &wset);
ret = socket_select(max_fd+1, &rset, &wset, NULL, &tm);
if (ret > 0 || ndirty > 0) {
return_fd(L, &rset, max_fd+1, itab, rtab, ndirty);
@@ -77,7 +80,7 @@ static int global_select(lua_State *L) {
lua_pushstring(L, "timeout");
return 3;
} else {
- lua_pushstring(L, "error");
+ luaL_error(L, "select failed");
return 3;
}
}
@@ -112,11 +115,13 @@ static int dirty(lua_State *L) {
return is;
}
-static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd,
- int itab, fd_set *set) {
- int i = 1;
- if (lua_isnil(L, tab))
- return max_fd;
+static void collect_fd(lua_State *L, int tab, int itab,
+ fd_set *set, t_socket *max_fd) {
+ int i = 1, n = 0;
+ /* nil is the same as an empty table */
+ if (lua_isnil(L, tab)) return;
+ /* otherwise we need it to be a table */
+ luaL_checktype(L, tab, LUA_TTABLE);
while (1) {
t_socket fd;
lua_pushnumber(L, i);
@@ -125,11 +130,18 @@ static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd,
lua_pop(L, 1);
break;
}
+ /* getfd figures out if this is a socket */
fd = getfd(L);
if (fd != SOCKET_INVALID) {
+ /* make sure we don't overflow the fd_set */
+ if (n >= FD_SETSIZE)
+ luaL_argerror(L, tab, "too many sockets");
FD_SET(fd, set);
- if (max_fd == SOCKET_INVALID || max_fd < fd)
- max_fd = fd;
+ n++;
+ /* keep track of the largest descriptor so far */
+ if (*max_fd == SOCKET_INVALID || *max_fd < fd)
+ *max_fd = fd;
+ /* make sure we can map back from descriptor to the object */
lua_pushnumber(L, fd);
lua_pushvalue(L, -2);
lua_settable(L, itab);
@@ -137,7 +149,6 @@ static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd,
lua_pop(L, 1);
i = i + 1;
}
- return max_fd;
}
static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) {
View
2  src/select.h
@@ -8,8 +8,6 @@
* method getfd() which returns the descriptor to be passed to the
* underlying select function. Another method, dirty(), should return
* true if there is data ready for reading (required for buffered input).
-*
-* RCS ID: $Id$
\*=========================================================================*/
int select_open(lua_State *L);
View
8 src/smtp.lua
@@ -16,6 +16,7 @@ local os = require("os")
local socket = require("socket")
local tp = require("socket.tp")
local ltn12 = require("ltn12")
+local headers = require("socket.headers")
local mime = require("mime")
module("socket.smtp")
@@ -146,10 +147,11 @@ end
local send_message
-- yield the headers all at once, it's faster
-local function send_headers(headers)
+local function send_headers(tosend)
+ local canonic = headers.canonic
local h = "\r\n"
- for i,v in base.pairs(headers) do
- h = i .. ': ' .. v .. "\r\n" .. h
+ for f,v in base.pairs(tosend) do
+ h = (canonic[f] or f) .. ': ' .. v .. "\r\n" .. h
end
coroutine.yield(h)
end
View
2  src/socket.h
@@ -8,8 +8,6 @@
* differences. Also, not all *nix platforms behave the same. This module
* (and the associated usocket.h and wsocket.h) factor these differences and
* creates a interface compatible with the io.h module.
-*
-* RCS ID: $Id$
\*=========================================================================*/
#include "io.h"
View
12 src/tcp.c
@@ -64,11 +64,11 @@ static luaL_reg tcp[] = {
};
/* socket option handlers */
-static t_opt opt[] = {
- {"keepalive", opt_keepalive},
- {"reuseaddr", opt_reuseaddr},
- {"tcp-nodelay", opt_tcp_nodelay},
- {"linger", opt_linger},
+static t_opt optset[] = {
+ {"keepalive", opt_set_keepalive},
+ {"reuseaddr", opt_set_reuseaddr},
+ {"tcp-nodelay", opt_set_tcp_nodelay},
+ {"linger", opt_set_linger},
{NULL, NULL}
};
@@ -128,7 +128,7 @@ static int meth_setstats(lua_State *L) {
static int meth_setoption(lua_State *L)