close fd when write failed

This commit is contained in:
云风
2012-10-18 13:47:53 +08:00
parent 9c6309ed71
commit 491a8cd29b
4 changed files with 55 additions and 41 deletions

View File

@@ -19,6 +19,7 @@ end
function socket.connect(addr)
local ip, port = string.match(addr,"([^:]+):(.+)")
port = tonumber(port)
socket.close()
fd = c.open(ip,port)
if fd == nil then
return true
@@ -54,6 +55,7 @@ end
function socket.write(...)
local str = c.write(fd, ...)
if str then
socket.close()
table.insert(data, str)
end
end
@@ -61,6 +63,7 @@ end
function socket.writeblock(...)
local str = c.write(fd, ...)
if str then
socket.close()
table.insert(data, str)
end
end