reconnect

This commit is contained in:
云风
2012-08-15 11:42:32 +08:00
parent ed7e0da860
commit e7539a07b6
5 changed files with 99 additions and 63 deletions

View File

@@ -9,14 +9,15 @@ function socket.connect(addr)
local ip, port = string.match(addr,"([^:]+):(.+)")
port = tonumber(port)
fd = c.open(ip,port)
if fd == nil then
return true
end
skynet.send(".connection","ADD "..fd.." "..skynet.self())
object = c.new()
end
function socket.push(msg,sz)
if msg == nil then
socket.close()
else
if msg then
c.push(object, msg, sz)
end
end
@@ -33,13 +34,12 @@ function socket.write(...)
c.write(fd, ...)
end
function socket.yield()
c.yield(object)
end
function socket.close()
skynet.send(".connection","DEL "..fd)
fd = nil
if fd then
c.close(fd)
skynet.send(".connection","DEL "..fd)
fd = nil
end
end
return socket