[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: bug: luasocket2.0.2 udp socket is trashed when setsockname fails
- From: Sam Roberts <vieuxtech@...>
- Date: Thu, 17 Dec 2009 12:11:20 -0800
On bind() failure with a udp socket (:setsockname()), the descriptor
appears to be closed and set to -1.
Sorry, no time to provide a patch right now (or test with tcp), we are
attempting year end releases.
Output:
% lua bind.lua
version: LuaSocket 2.0.2
fd: 4
setsockname:(busy) nil address already in use
getsockname: nil getsockname failed
setsockname:(free) nil Bad file descriptor
getsockname: nil getsockname failed
Replication:
-- bind.lua
require"socket"
print("version:", socket._VERSION)
u0 = socket.udp()
assert(u0:setsockname("*", 33000))
u1 = socket.udp()
print("fd:", u1:getfd())
print("setsockname:(busy)", u1:setsockname("*", 33000))
print("getsockname:", u1:getsockname())
print("setsockname:(free)", u1:setsockname("*", 33001))
print("getsockname:", u1:getsockname())
u1:close()
while true do end
os.exit(0)
System trace output:
% strace -v -e trace=network,close,shutdown lua bind.lua
[...]
version: LuaSocket 2.0.2
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
bind(3, {sa_family=AF_INET, sin_port=htons(33000),
sin_addr=inet_addr("0.0.0.0")}, 16) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 4
fd: 4
bind(4, {sa_family=AF_INET, sin_port=htons(33000),
sin_addr=inet_addr("0.0.0.0")}, 16) = -1 EADDRINUSE (Address already
in use)
close(4) = 0
setsockname:(busy) nil address already in use
getsockname(4294967295, 0x7fff878afac0, [27906859243405328]) = -1
EBADF (Bad file descriptor)
getsockname: nil getsockname failed
bind(4294967295, {sa_family=AF_INET, sin_port=htons(33001),
sin_addr=inet_addr("0.0.0.0")}, 16) = -1 EBADF (Bad file descriptor)
setsockname:(free) nil Bad file descriptor
getsockname(4294967295, 0x7fff878afac0, [27907099761573904]) = -1
EBADF (Bad file descriptor)
getsockname: nil getsockname failed