Giter Club home page Giter Club logo

luasocket's People

Contributors

alerque avatar bytefire avatar catwell avatar chastabor avatar darkrain42 avatar daurnimator avatar diegonehab avatar dmail00 avatar enginix avatar ewestbrook avatar florob avatar gatzka avatar jonaskunze avatar leso-kn avatar lord-helmchen avatar mascarenhas avatar moteus avatar mpeterv avatar mwild1 avatar ncopa avatar pdgendt avatar pingbird avatar pkulchenko avatar robert-scheck avatar sam-github avatar siffiejoe avatar tieske avatar tst2005 avatar zash avatar zhaozg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luasocket's Issues

Source code for luasocket-2.0.2-lua-5.1.2-Win32-vc8.zip

HI,

I am a user of Koneki LDT and use luasocket library. Can you please point me to the source files for the mime/core.dll and socket/core.dll in the zip folder mentioned above. The luaforge.net mentions that the source files are available but I haven't seen them in the zip folder.
I have the above mentioned zip folder from:
http://files.luaforge.net/releases/luasocket/luasocket/luasocket-2.0.2
I would really appreciate your prompt response regarding pointers to this since this is blocking further progress in my project.

Thanks,
Anu

IPV6_V6ONLY is undefined in mingw

Hello,

I am trying to compile luasocket-unstable for lua5.2 with mingw but
IPV6_V6ONLY is undefined.
It seems that a definition was added by may be in other branch

Best
Victor Bombi

automated test without spawning server

Running the automated test suite (utestclnt.lua) is complicated by the need to spawn a separate process (utestsrvr.lua). In the CMake build for LuaDist (CMakeLists.txt), we currently have the test suite disabled because of this. I could make it run some way, but writing it in a cross-platform manner would be ugly, and if a test fails, it might leave the server running in the background. It would be preferable if there somehow were an option to run tests within the same process or even Lua state so that I can just invoke "lua test.lua" in the usual way and be done with it.

detect mingw in source file

Hi,

if you compile luasocket without makefile, you must define LUASOCKET_INET_PTON, so why not we make things easier? this is my patch:

diff --git a/src/inet.h b/src/inet.h
index 1f1a96a..55cf61c 100644
--- a/src/inet.h
+++ b/src/inet.h
@@ -22,6 +22,10 @@
 #define LUASOCKET_INET_ATON
 #endif

+#ifdef __MINGW32__
+#define LUASOCKET_INET_PTON
+#endif
+
 int inet_open(lua_State *L);

 const char *inet_trycreate(p_socket ps, int family, int type);

this makes compile easier.

btw, it's better to add a .def file to export all symbols in windows, thus we needn't define __declspec(export) anymore.

it does not work with the mod_lua freeswitch

I want to use redis-lua,and it de depends on luasocket. The lua Version is 5.2,so I edit the src/makefile and make && make install. but when i require "socket" in the script,it report the error like below:
2013-12-27 12:00:54.498651 [ERR] mod_lua.cpp:199 error loading module 'socket.core' from file '/usr/local/lib/lua/5.2/socket/core.so':
/usr/local/lib/lua/5.2/socket/core.so: undefined symbol: lua_gettop
stack traceback:
[C]: in ?
[C]: in function 'require'
/usr/local/share/lua/5.2/socket.lua:12: in main chunk
[C]: in function 'require'
/home/yazi/work/10086china/esl/test.lua:10: in main chunk

-ERR Cannot execute script

why ?

invalid escape sequence

? and . are invalid escape sequences (and raise errors in Lua 5.2)
https://github.com/diegonehab/luasocket/blob/d55a5826e81136a9ecf65c4cd407152a56684dc2/samples/lpr.lua#L31

diff --git a/samples/lpr.lua b/samples/lpr.lua
index 2b059b1..3463f62 100644
--- a/samples/lpr.lua
+++ b/samples/lpr.lua
@@ -28,7 +28,7 @@ end

 do
     local opt = {}
-    local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]\?\.?)"
+    local pat = "[%s%c%p]*([%w]*)=([\"]?[%w%s_!@#$%%^&*()<>:;]+[\"]?.?)"
     for i = 2, table.getn(arg), 1 do
       string.gsub(arg[i], pat, function(name, value) opt[name] = value end)
     end

udp_sok:setpeername('*') always return error

Test :

local s = assert(socket.udp())
assert(tostring(s):find("udp{unconnected}"))
assert(s:setpeername("127.0.0.1", 5061))
assert(tostring(s):find("udp{connected}"))
assert(s:setpeername("*"))
assert(tostring(s):find("udp{unconnected}"))
s:close()

LUASOCKET_API macro definition

Instead of having -D flags passed around
you could define the visibility of symbols by having a .h file that does so, like in
http://gcc.gnu.org/wiki/Visibility

It's not radically different from your perspective (you move the idfefs
from the makefile to this .h) but makes things way simpler if one wants
to compile the sources with another build system.
In particular most of the files compile fine, since there are
default-value #ifndef for LUASOCKET_API etc, but not for all of them in
all files (like in serial.c), and even if they compile
-fvisibility=hidden + "extern" (the default value for LUASOCKET_API)
does not work well (i.e. no exported symbols in socket.so for example).

Update README

I commented out the untested OSs a couple of years ago, this was merged into unstable and is still present.

compilation problem with 2.0.2 (not git-clone)

Hello,
trying to compile 2.0.2 (latest released archive) on Mac OSX 10.9 on MBP Core i7, I get the following error:

make
cd src; /Applications/Xcode.app/Contents/Developer/usr/bin/make all
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o luasocket.o luasocket.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o timeout.o timeout.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o buffer.o buffer.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o io.o io.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o auxiliar.o auxiliar.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o options.o options.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o inet.o inet.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o tcp.o tcp.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o udp.o udp.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o except.o except.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o select.o select.c
gcc  -DLUASOCKET_DEBUG  -pedantic -Wall -O2 -fpic   -c -o usocket.o usocket.c
gcc  -O -shared -fpic -o socket.so.2.0.2 luasocket.o timeout.o buffer.o io.o auxiliar.o options.o inet.o tcp.o udp.o except.o select.o usocket.o 
Undefined symbols for architecture x86_64:
  "_luaL_addlstring", referenced from:
      _buffer_meth_receive in buffer.o
  "_luaL_argerror", referenced from:
      _timeout_meth_settimeout in timeout.o
      _buffer_meth_receive in buffer.o
      _auxiliar_checkclass in auxiliar.o
      _auxiliar_checkgroup in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
      _opt_meth_setoption in options.o
      _opt_linger in options.o
      ...
  "_luaL_buffinit", referenced from:
      _buffer_meth_receive in buffer.o
  "_luaL_checkinteger", referenced from:
      _global_skip in luasocket.o
  "_luaL_checklstring", referenced from:
      _buffer_meth_send in buffer.o
      _opt_meth_setoption in options.o
      _inet_global_tohostname in inet.o
      _inet_global_toip in inet.o
      _meth_connect in tcp.o
      _meth_bind in tcp.o
      _meth_setsockname in udp.o
      ...
  "_luaL_checknumber", referenced from:
      _timeout_lua_sleep in timeout.o
      _opt_ip_multicast_ttl in options.o
      _meth_setfd in tcp.o
      _meth_connect in tcp.o
      _meth_bind in tcp.o
      _meth_setfd in udp.o
      _meth_setsockname in udp.o
      ...
  "_luaL_checkudata", referenced from:
      _auxiliar_checkclass in auxiliar.o
      _auxiliar_getclassudata in auxiliar.o
  "_luaL_newmetatable", referenced from:
      _auxiliar_newclass in auxiliar.o
  "_luaL_openlib", referenced from:
      _luaopen_socket_core in luasocket.o
      _timeout_open in timeout.o
      _inet_open in inet.o
      _tcp_open in tcp.o
      _udp_open in udp.o
      _except_open in except.o
      _select_open in select.o
      ...
  "_luaL_optlstring", referenced from:
      _timeout_meth_settimeout in timeout.o
      _buffer_meth_receive in buffer.o
      _meth_shutdown in tcp.o
  "_luaL_optnumber", referenced from:
      _timeout_meth_settimeout in timeout.o
      _buffer_meth_setstats in buffer.o
      _buffer_meth_send in buffer.o
      _meth_listen in tcp.o
      _meth_setpeername in udp.o
      _meth_receivefrom in udp.o
      _meth_receive in udp.o
      ...
  "_luaL_prepbuffer", referenced from:
      _buffer_meth_receive in buffer.o
  "_luaL_pushresult", referenced from:
      _buffer_meth_receive in buffer.o
  "_luaL_typerror", referenced from:
      _auxiliar_checkboolean in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
      _opt_linger in options.o
  "_lua_call", referenced from:
      _getfd in select.o
      _global_select in select.o
  "_lua_createtable", referenced from:
      _auxiliar_newclass in auxiliar.o
      _inet_pushresolved in inet.o
      _inet_open in inet.o
      _finalize in except.o
      _make_assoc in select.o
      _global_select in select.o
  "_lua_error", referenced from:
      _luaopen_socket_core in luasocket.o
      _auxiliar_tostring in auxiliar.o
      _protected_ in except.o
      _finalize in except.o
  "_lua_getfield", referenced from:
      _auxiliar_add2group in auxiliar.o
      _auxiliar_setclass in auxiliar.o
  "_lua_getmetatable", referenced from:
      _auxiliar_tostring in auxiliar.o
      _auxiliar_getgroupudata in auxiliar.o
  "_lua_gettable", referenced from:
      _auxiliar_tostring in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
      _opt_linger in options.o
      _protected_ in except.o
      _return_fd in select.o
      _make_assoc in select.o
      _getfd in select.o
      ...
  "_lua_gettop", referenced from:
      _global_skip in luasocket.o
      _buffer_meth_send in buffer.o
      _buffer_meth_receive in buffer.o
      _inet_pushresolved in inet.o
      _protected_ in except.o
      _finalize in except.o
      _make_assoc in select.o
      ...
  "_lua_insert", referenced from:
      _protected_ in except.o
      _finalize in except.o
  "_lua_isnumber", referenced from:
      _buffer_meth_setstats in buffer.o
      _buffer_meth_receive in buffer.o
      _opt_linger in options.o
      _getfd in select.o
  "_lua_isstring", referenced from:
      _auxiliar_tostring in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
  "_lua_newuserdata", referenced from:
      _global_create in tcp.o
      _meth_accept in tcp.o
      _global_create in udp.o
  "_lua_pcall", referenced from:
      _protected_ in except.o
      _finalize in except.o
  "_lua_pushboolean", referenced from:
      _luaopen_socket_core in luasocket.o
      _auxiliar_add2group in auxiliar.o
      _meth_dirty in tcp.o
      _meth_dirty in udp.o
  "_lua_pushcclosure", referenced from:
      _auxiliar_newclass in auxiliar.o
      _global_protect in except.o
      _global_newtry in except.o
  "_lua_pushfstring", referenced from:
      _auxiliar_tostring in auxiliar.o
  "_lua_pushlstring", referenced from:
      _meth_receivefrom in udp.o
      _meth_receive in udp.o
  "_lua_pushnil", referenced from:
      _buffer_meth_send in buffer.o
      _buffer_meth_receive in buffer.o
      _opt_set.isra.0 in options.o
      _inet_global_tohostname in inet.o
      _inet_global_toip in inet.o
      _inet_global_gethostname in inet.o
      _inet_meth_getpeername in inet.o
      ...
  "_lua_pushnumber", referenced from:
      _timeout_lua_gettime in timeout.o
      _timeout_meth_settimeout in timeout.o
      _buffer_meth_getstats in buffer.o
      _buffer_meth_setstats in buffer.o
      _buffer_meth_send in buffer.o
      _buffer_meth_receive in buffer.o
      _opt_set.isra.0 in options.o
      ...
  "_lua_pushstring", referenced from:
      _luaopen_socket_core in luasocket.o
      _buffer_meth_send in buffer.o
      _buffer_meth_receive in buffer.o
      _auxiliar_newclass in auxiliar.o
      _auxiliar_tostring in auxiliar.o
      _auxiliar_add2group in auxiliar.o
      _auxiliar_getgroupudata in auxiliar.o
      ...
  "_lua_pushvalue", referenced from:
      _buffer_meth_receive in buffer.o
      _protected_ in except.o
      _finalize in except.o
      _make_assoc in select.o
      _getfd in select.o
      _collect_fd.part.0 in select.o
      _global_select in select.o
      ...
  "_lua_rawget", referenced from:
      _auxiliar_getgroupudata in auxiliar.o
  "_lua_rawset", referenced from:
      _luaopen_socket_core in luasocket.o
      _auxiliar_newclass in auxiliar.o
      _auxiliar_add2group in auxiliar.o
  "_lua_replace", referenced from:
      _buffer_meth_receive in buffer.o
  "_lua_setmetatable", referenced from:
      _auxiliar_setclass in auxiliar.o
  "_lua_settable", referenced from:
      _inet_pushresolved in inet.o
      _inet_open in inet.o
      _finalize in except.o
      _return_fd in select.o
      _make_assoc in select.o
      _collect_fd.part.0 in select.o
      _global_select in select.o
      ...
  "_lua_settop", referenced from:
      _auxiliar_newclass in auxiliar.o
      _auxiliar_add2group in auxiliar.o
      _auxiliar_getgroupudata in auxiliar.o
      _global_newtry in except.o
      _finalize in except.o
      _make_assoc in select.o
      _getfd in select.o
      ...
  "_lua_toboolean", referenced from:
      _auxiliar_checkboolean in auxiliar.o
      _opt_linger in options.o
      _finalize in except.o
      _global_select in select.o
  "_lua_tolstring", referenced from:
      _auxiliar_tostring in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
  "_lua_tonumber", referenced from:
      _buffer_meth_setstats in buffer.o
      _buffer_meth_receive in buffer.o
      _opt_linger in options.o
      _getfd in select.o
  "_lua_touserdata", referenced from:
      _auxiliar_tostring in auxiliar.o
      _auxiliar_getgroupudata in auxiliar.o
  "_lua_type", referenced from:
      _auxiliar_tostring in auxiliar.o
      _auxiliar_checkboolean in auxiliar.o
      _auxiliar_getgroupudata in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
      _opt_linger in options.o
      _global_newtry in except.o
      _protected_ in except.o
      ...
  "_lua_typename", referenced from:
      _auxiliar_checkboolean in auxiliar.o
      _opt_setmembership.constprop.2 in options.o
      _opt_linger in options.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [socket.so.2.0.2] Error 1
make: *** [all] Error 2

This is my gcc:

%gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.6.3/lto-wrapper
Target: x86_64-apple-darwin12
Configured with: ../gcc-4.6.3/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran --libdir=/opt/local/lib/gcc46 --includedir=/opt/local/include/gcc46 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.6 --with-local-prefix=/opt/local --with-libiconv-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.6 --with-gxx-include-dir=/opt/local/include/gcc46/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check --with-pkgversion='MacPorts gcc46 4.6.3_9'
Thread model: posix
gcc version 4.6.3 (MacPorts gcc46 4.6.3_9)

b64/qp encode error

luaL_addlstring can change stack top.
so code in mime.c do not correct.

static int mime_global_unb64(lua_State *L)
{
    UC atom[4];
    size_t isize = 0, asize = 0;
    const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize);
    ....
    luaL_buffinit(L, &buffer);
    while (input < last)
        asize = b64decode(*input++, atom, asize, &buffer); // THIS FUNCTION CAN CHANGE TOP
     input = (UC *) luaL_optlstring(L, 2, NULL, &isize);  // input can point on buffer's stuff

test :

n = 4096; assert(n == #mime.unb64(mime.b64(('1'):rep(n))))

Fix. version in rockspec file

Version field in reockspec file have to include reockspec version as well.

package = "LuaSocket"
version = "scm-0"

Makefile Install with Lua5.2

Hi, I edited my Makefile on a couple lines.

LUAV?=5.2
COMPAT?=LUA_COMPAT_MODULE

and I think that my current error is maybe with specifying the CDIR/LDIR directories or that they're okay as default and its just core.so, socket.so and a few other files don't install in /usr/local/share/lua/5.2/. As @moteus describes, I should have core.so somewhere, and if necessary move my src/*.lua files manually possibly.

$ sudo make install-unix
make -C src install-unix
make[1]: Entering directory `/home/tom/projects/luasocket/src'
install -d /usr/local/share/lua/5.2
install -m644 ltn12.lua socket.lua mime.lua /usr/local/share/lua/5.2
install -d /usr/local/share/lua/5.2/socket
install -m644 http.lua url.lua tp.lua ftp.lua headers.lua smtp.lua /usr/local/share/lua/5.2/socket
install -d /usr/local/lib/lua/5.2/socket
install socket.so.3.0-rc1 /usr/local/lib/lua/5.2/socket/core.so
install: cannot stat ‘socket.so.3.0-rc1’: No such file or directory
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/tom/projects/luasocket/src'
make: *** [install-unix] Error 2

Doing a test like

lua
> socket = require("socket")

returns

/usr/local/share/lua/5.2/socket.lua:12: module 'socket.core' not found:
    no field package.preload['socket.core']
    no file '/usr/local/share/lua/5.2/socket/core.lua'
    no file '/usr/local/share/lua/5.2/socket/core/init.lua'
    no file '/usr/local/lib/lua/5.2/socket/core.lua'
    no file '/usr/local/lib/lua/5.2/socket/core/init.lua'
    no file './socket/core.lua'
    no file '/usr/share/lua/5.2/socket/core.lua'
    no file '/usr/share/lua/5.2/socket/core/init.lua'
    no file './socket/core.lua'
    no file '/usr/local/lib/lua/5.2/socket/core.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket/core.so'
    no file '/usr/lib/lua/5.2/socket/core.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './socket/core.so'
    no file '/usr/local/lib/lua/5.2/socket.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket.so'
    no file '/usr/lib/lua/5.2/socket.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './socket.so'
stack traceback:
    [C]: in function 'require'
    /usr/local/share/lua/5.2/socket.lua:12: in main chunk
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: in ?

Just for clarity, make install gives same result.

$ sudo make install
make -C src install
make[1]: Entering directory `/home/tom/projects/luasocket/src'
install -d /usr/local/share/lua/5.2
install -m644 ltn12.lua socket.lua mime.lua /usr/local/share/lua/5.2
install -d /usr/local/share/lua/5.2/socket
install -m644 http.lua url.lua tp.lua ftp.lua headers.lua smtp.lua /usr/local/share/lua/5.2/socket
install -d /usr/local/lib/lua/5.2/socket
install socket.so.3.0-rc1 /usr/local/lib/lua/5.2/socket/core.so
install: cannot stat ‘socket.so.3.0-rc1’: No such file or directory
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/tom/projects/luasocket/src'
make: *** [install] Error 2

Advice?

Thanks!

UPDATE:
After luarocks install luasocket-scm-0.rockspec noticed core.so in my 5.1 folder (although possibly could have been there from my previous trial and error.. was just checking 5.2).

lua5.1
> socket = require("socket")
> print(socket._VERSION)
LuaSocket 3.0-rc1

How do I install for 5.2? I'll use 5.1 in the interim.. cheers, Tom

Broken timeout handling when sending/receiving on a socket

Hi,

I would like to hear some explanation for commit e81a6ff.

Because of this, timeout_markstart() is no longer called when sending and receiving on a socket which means that the last markstart call (likely from connect() / accept()) will always be used as the time for the start of the operation.

So if you have a timeout setting of 5 and a lua tcp socket which was created 10 seconds ago, all operations will use a timeout of 0 (which hopefully is wrong for obvious reasons).

I noticed this because I send requests on a tcp socket and then wait for the replies and this only works seldom since the upgrade to 3.0-rc1.

(My guess for how that commit happened: Some compiler complained about "tm" being unused and this warning was silenced in the obvious way without noticing that timeout_markstart() has side effects.)

(Also I wonder if I am the only one using lua-socket with timeouts since I immediately ran into a bug after upgrading and the bug exists since a year).

Cheers

Are we ready to release?

I am reasonably happy with the current state of the code. Almost pulling the trigger for a release.

I guess we need to focus a bit on documentation. Can anybody help?

setsockname with '*' fail

may be should write

    /* translate luasocket special values to C */
    if (strcmp(address, "*") == 0) address = NULL;
    if  (!serv) serv = "0";

in inet_trybind enstead of write this in tcp bind and udp setsockname

socket.http does not work with IPv6 servers

I'm glad that luasocket now got support for IPv6 - this was long
overdue and is the main reason why Lua was hardly useful for me
so far.

But trying with today's code cloned from github (apparently a 3.0-rc1),
using an example of a HTTP client from documentation, it fails to work
with IPv6 web servers:

local io = require("io")
local http = require("socket.http")
local ltn12 = require("ltn12")
b,e = http.request {
  url = "http://[2001:1470:ff80::80:1]/",
  sink = ltn12.sink.file(io.stdout)
}
print(b,e)

gives:

$ lua-5.1 http-socket.lua
lua-5.1: /usr/local/share/lua/5.1/socket/http.lua:116: bad argument #2 to 'connect' (number expected, got string)
stack traceback:
        [C]: in function 'request'
        http-socket.lua:4: in main chunk
        [C]: ?

and:

local io = require("io")
local http = require("socket.http")
local ltn12 = require("ltn12")
b,e = http.request {
  url = "http://ipv6.test-ipv6.com/",
  sink = ltn12.sink.file(io.stdout)
}
print(b,e)

gives:

$ lua-5.1 http-socket.lua
nil     No address associated with name

It would be really nice and useful if support for IPv6 would be extended
to all components of the luasocket module.

Tag prior releases

The repository lacks tags letting us know the status in relation to prior versions. These would be useful to any looking to work with the code integrating into other projects.

In my case, I'm looking to see what sort of changes I might have to make in LuaEvent to work with 3.0 series. I don't expect any, but w/ git-based diff and change tracking, it'd be a little easier.

FTP: processing 2xx responses

SlimFTP on request MTDM return data with status code 213 and don't create new connection.
But socket.ftp ignore recived data and try use new connection.
I add check status code in recive method:

local code,reply = self.try(self.tp:check{"1..", "2.."})
if (code >= 200) and (code <= 299) then
    recvt.sink(reply)
    return 1
end

Support UNIX sockets (including SOCK_DGRAM)

Please consider supporting UNIX sockets officially.
The code is already in the tree if I'm not mistaken.
However, it seems to currently only handle the SOCK_STREAM type, whereas I'd very much like to use SOCK_DGRAM in my application.
Thanks.

getnameinfo's interface

Is there any reason why getnameinfo() restricts the acceptable returns to SOCK_STREAM? Do they come repeated otherwise?

Read all available data from socket

LuaSocket does not provide ability to read some amount of data that currently available.
I suppose add pattern "*r" with optianal number parameter(max size).

[edit] no bug

[edit] I think my problem was actually implicit conversion of https to http in http.lua.

Closing TCP server sockets on fork

Hi,

I want to suggest to add FD_CLOEXEC flag on TCP server sockets, to automatically close sockets on fork. I actually don't know if it left on purpose or it is a bug but in common use case it makes sense to close server sockets of forked process. I noticed this bug/feature while using luasockets v2.0.2 with xavante and wsapi.

My use case:

  • xavante receives request
  • wsapi handler processes request and forks process
  • forked process lauches script that reloads xavante
  • forked process exits

Forked process server sockets still open and when starting xavante again i get 'address already in use' error.

Here is my patch that i used on luasockets-2.0.2:

diff --git a/lua-modules/luasocket-2.0.2/src/socket.h b/lua-modules/luasocket-2.0.2/src/socket.h
index 656c7f5..cd81350 100644
--- a/lua-modules/luasocket-2.0.2/src/socket.h
+++ b/lua-modules/luasocket-2.0.2/src/socket.h
@@ -48,6 +48,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count,

 void socket_setnonblocking(p_socket ps);
 void socket_setblocking(p_socket ps);
+void socket_set_coe(p_socket ps);

 int socket_waitfd(p_socket ps, int sw, p_timeout tm);
 int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds,
diff --git a/lua-modules/luasocket-2.0.2/src/tcp.c b/lua-modules/luasocket-2.0.2/src/tcp.c
index 6b8a79b..ab4b219 100644
--- a/lua-modules/luasocket-2.0.2/src/tcp.c
+++ b/lua-modules/luasocket-2.0.2/src/tcp.c
@@ -199,6 +199,11 @@ static int meth_bind(lua_State *L)
         lua_pushstring(L, err);
         return 2;
     }
+    /*
+     * XXX: need to close socket on exec. Requred for xavante
+     * 'address already in use' issue. Described in #2947
+     */
+    socket_set_coe(&tcp->sock);
     lua_pushnumber(L, 1);
     return 1;
 }
diff --git a/lua-modules/luasocket-2.0.2/src/usocket.c b/lua-modules/luasocket-2.0.2/src/usocket.c
index 70c6e1e..57cedbb 100644
--- a/lua-modules/luasocket-2.0.2/src/usocket.c
+++ b/lua-modules/luasocket-2.0.2/src/usocket.c
@@ -320,6 +320,15 @@ void socket_setnonblocking(p_socket ps) {
 }

 /*-------------------------------------------------------------------------*\
+* Put socket to close on exec
+\*-------------------------------------------------------------------------*/
+void socket_set_coe(p_socket ps) {
+    int flags = fcntl(*ps, F_GETFD);
+    flags |= FD_CLOEXEC;
+    fcntl(*ps, F_SETFD, flags);
+}
+
+/*-------------------------------------------------------------------------*\
 * DNS helpers
 \*-------------------------------------------------------------------------*/
 int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
diff --git a/lua-modules/luasocket-2.0.2/src/wsocket.c b/lua-modules/luasocket-2.0.2/src/wsocket.c
index 6022565..fe4d9ec 100644
--- a/lua-modules/luasocket-2.0.2/src/wsocket.c
+++ b/lua-modules/luasocket-2.0.2/src/wsocket.c
@@ -306,6 +306,12 @@ void socket_setnonblocking(p_socket ps) {
 }

 /*-------------------------------------------------------------------------*\
+* Put socket to close on exec
+\*-------------------------------------------------------------------------*/
+void socket_set_coe(p_socket ps) {
+}
+
+/*-------------------------------------------------------------------------*\
 * DNS helpers
 \*-------------------------------------------------------------------------*/
 int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp) {
-- 
1.7.10.4

how does udp:receive() and udp:send() works in right way?

It seems, that I've not fully understand documentation, but I can't get udp:receive working even on IPv4 (same for IPv6):

1st instance:
udp = socket.udp();
udp:setpeername("127.0.0.1",9999)
print(assert(udp:receive())) --[[ also tried io.write instead of print ]]

2dn instance:
udp=socket.udp();
udp:setpeername("127.0.0.1",9999)
udp:send("dddd");

And it is absolutelly nothng on 1st instance.

I've tried to do the same with netcat-listener instance and all work fine even with IPv6 (on ::1)
I've tried to send messages from netcat to luasocket listener and it is absolutelly nothing too.

Lacking IPv6 support

It seems, luasocket don't fully support udp6 (at least, I can't use for example, sendto, on IPv6 addresses).

udp=socket.udp6();
udp:setpeername("::1",9999)
=udp
udp{connected}: 0x60c398
udp:send("dddd")
--here it perfectly send messages to netcat
udp = socket.udp6()
-- clean udp instance for sendto test
udp:sendto("dddd","::1",9999)
stdin:1: bad argument #2 to 'sendto' (invalid ip address)
stack traceback:
[C]: in function 'sendto'
stdin:1: in main chunk
[C]: ?
--fail

inet_global_getaddrinfo

  1. inet_global_getaddrinfo ignore error from getnameinfo
  2. On windows (I test only on XP SP3) when serv parameter is not NULL we get error 11044
    so call have to be
ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, hbuf, NULL, 0, NI_NUMERICHOST);

mingw compatibility - IPV6_V6ONL undefined and other symbols

In the latest "unstable" branch, IPV6_V6ONL is not always defined (e.g. when I cross compiled mingw from Linux). A workaround is seen in:

http://svn.apache.org/repos/asf/apr/apr/trunk/network_io/win32/sockopt.c

So, I did

diff --git a/src/options.c b/src/options.c
index 6cae7ee..2844c0c 100644
--- a/src/options.c
+++ b/src/options.c
@@ -10,6 +10,11 @@
 #include "options.h"
 #include "inet.h"

+/* not available on older Windows SDK and mingw */
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
+
 /*=========================================================================*\
 * Internal functions prototypes
 \*=========================================================================*/
diff --git a/src/tcp.c b/src/tcp.c
index 94148c5..fdd85f4 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -13,6 +13,11 @@
 #include "options.h"
 #include "tcp.h"

+/* not available on older Windows SDK and mingw */
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
+
 /*=========================================================================*\
 * Internal function prototypes
 \*=========================================================================*/
diff --git a/src/udp.c b/src/udp.c
index 0241cc5..6630744 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -13,6 +13,11 @@
 #include "options.h"
 #include "udp.h"

+/* not available on older Windows SDK and mingw */
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
+
 /* min and max macros */
 #ifndef MIN
 #define MIN(x, y) ((x) < (y) ? x : y)

However, inet.c and tcp.c still rely on some *nix specific functions:

CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0x2c5): undefined reference to `_socket_gaistrerror'
CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0x5ad): undefined reference to `_inet_ntop'
CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0x690): undefined reference to `_inet_ntop'
CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0x7b4): undefined reference to `_inet_ntop'
CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0x897): undefined reference to `_inet_ntop'
CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0xb5b): undefined reference to `_socket_gaistrerror'
CMakeFiles/socket_core.dir/objects.a(inet.c.obj):inet.c:(.text+0xc79): undefined reference to `_socket_gaistrerror'
CMakeFiles/socket_core.dir/objects.a(tcp.c.obj):tcp.c:(.text+0xb62): undefined reference to `_socket_gaistrerror'

use llthreads report crash

local llthreads = require"llthreads"

local a = 1 
-- level 0 string literal enclosure [[  ]] of child execution code
local thread_code = [[  

    http = require("socket.http")
    local url = ...
    local body, code, headers = http.request(url)
    print(url)
    print("status=",code)   
    return ...  -- return the parents' input params back to the root
]]


local urls = {"http://www.163.com/","http://www.baidu.com/","http://www.aliyun.com/","http://www.google.com/"}
-- create child thread.
local t = {} 
for i=1,#urls do
    -- create child sub-thread with code to execute and the input parmeters
    local thread = llthreads.new(thread_code ,urls[i]) 
    assert(thread:start()) -- start new child sub-thread
    table.insert(t, thread) -- append the thread at the end of the thread table
end

-- wait (block) for all child sub-threads to complete before returning to ROOT
while true do
    -- always wait on the first element, since order is not important        
    print("CHILD: sub-thread returned: ", t[1]:join()) 
    table.remove(t,1) -- always remove the first element
    if (#t == 0) then break end
end

*** glibc detected *** luajit-2.0.1: double free or corruption (out): 0x00007fb508001d30 ***
======= Backtrace: =========
Segmentation fault

SMTP auth does not work.

The reason in line 66 in file tp.lua
cmd = string.upper(cmd)

this command also upper password hash string.

remove getn for lua 5.2

I got two errors using socket.http.request with lua 5.2.
You can fix them by changing table.getn(tbl) to #tbl in line 262 and 280 in src/url.lua (this should also keep compatibility to lua 5.1).

Allow listing local interface addresses

In order to implement RFC 6724 (Default Address Selection for IPv6), it is necessary to know the machine's local addresses. It is useful in general for many network applications too (listing ICE candidates comes to mind).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.