Merge branch 'git-sam' into diego-sam-mwild-integration

Conflicts in options.c were just due to independent small functions
being close to each other.

unix.c in mwild was broken, it wasn't using LUASOCKET_API.

serial.c needed luaL_reg renamed, and to use LUASOCKET_API.

makefile didn't respect standard DESTDIR and prefix makefile
variables, and didn't allow LUAV variable to select lua version to build
against.

I've tested the top-level install-both target builds and installs
against both lua5.1 and lua5.2, but not done further testing.

Conflicts:
	README
	config
	gem/ltn012.tex
	makefile
	src/makefile
	src/options.c
	src/options.h
	src/tcp.c
	src/usocket.c
This commit is contained in:
Sam Roberts 2012-04-11 14:18:20 -07:00
commit 4b671f4551
22 changed files with 656 additions and 60 deletions

32
test/find-connect-limit Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env lua
--[[
Find out how many TCP connections we can make.
Use ulimit to increase the max number of descriptors:
ulimit -n 10000
ulimit -n
You'll probably need to be root to do this.
]]
require "socket"
host = arg[1] or "google.com"
port = arg[2] or 80
connections = {}
repeat
c = assert(socket.connect(hostip or host, 80))
table.insert(connections, c)
if not hostip then
hostip = c:getpeername()
print("resolved", host, "to", hostip)
end
print("connection #", #connections, c, "fd", c:getfd())
until false

41
test/tcp-getoptions Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env lua
require"socket"
port = 8765
function options(o)
print("options for", o)
for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do
print("getoption", opt, o:getoption(opt))
end
print("getoption", "linger",
"on", o:getoption("linger").on,
"timeout", o:getoption("linger").timeout)
end
local m = socket.tcp()
options(m)
assert(m:bind("*", port))
assert(m:listen())
options(m)
m:close()
local m = socket.bind("*", port)
options(m)
local c = socket.connect("localhost", port)
options(c)
local s = m:accept()
options(s)

View file

@ -7,7 +7,12 @@ while 1 do
print("server: waiting for client connection...");
control = assert(server:accept());
while 1 do
command = assert(control:receive());
command, emsg = control:receive();
if emsg == "closed" then
control:close()
break
end
assert(command, emsg)
assert(control:send(ack));
print(command);
(load(command))();

25
test/udp-zero-length-send Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/lua
--[[
Show that luasocket returns an error message on zero-length UDP sends,
even though the send is valid, and in fact the UDP packet is sent
to the peer:
% sudo tcpdump -i lo -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0
]]
require"socket"
s = assert(socket.udp())
r = assert(socket.udp())
assert(r:setsockname("*", 5432))
assert(s:setpeername("127.0.0.1", 5432))
ssz, emsg = s:send("")
print(ssz == 0 and "OK" or "FAIL",[[send:("")]], ssz, emsg)

37
test/udp-zero-length-send-recv Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/lua
--[[
Show that luasocket returns an error message on zero-length UDP sends,
even though the send is valid, and in fact the UDP packet is sent
to the peer:
% sudo tcpdump -i lo -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
13:40:16.652808 IP 127.0.0.1.56573 > 127.0.0.1.5432: UDP, length 0
]]
require"socket"
s = assert(socket.udp())
r = assert(socket.udp())
assert(r:setsockname("*", 5432))
assert(s:setpeername("127.0.0.1", 5432))
ok, emsg = s:send("")
if ok ~= 0 then
print("send of zero failed with:", ok, emsg)
end
assert(r:settimeout(2))
ok, emsg = r:receive()
if not ok or string.len(ok) ~= 0 then
print("fail - receive of zero failed with:", ok, emsg)
os.exit(1)
end
print"ok"