add new socket message WARNING

This commit is contained in:
Cloud Wu
2015-08-11 13:21:24 +08:00
parent 27148981d5
commit 947727e33a
10 changed files with 67 additions and 6 deletions

View File

@@ -271,7 +271,7 @@ function skynet.sleep(ti)
end
function skynet.yield()
return skynet.sleep("0")
return skynet.sleep(0)
end
function skynet.wait()

View File

@@ -114,6 +114,12 @@ function gateserver.start(handler)
close_fd(fd)
end
function MSG.warning(fd, size)
if handler.warning then
handler.warning(fd, size)
end
end
skynet.register_protocol {
name = "socket",
id = skynet.PTYPE_SOCKET, -- PTYPE_SOCKET = 6

View File

@@ -133,6 +133,25 @@ socket_message[6] = function(id, size, data, address)
s.callback(str, address)
end
local function default_warning(id, size)
local s = socket_pool[id]
local last = s.warningsize or 0
if last + 64 < size then -- if size increase 64K
s.warningsize = size
skynet.error(string.format("WARNING: %d K bytes need to send out (fd = %d)", size, id))
end
s.warningsize = size
end
-- SKYNET_SOCKET_TYPE_WARNING
socket_message[7] = function(id, size)
local s = socket_pool[id]
if s then
local warning = s.warning or default_warning
warning(id, size)
end
end
skynet.register_protocol {
name = "socket",
id = skynet.PTYPE_SOCKET, -- PTYPE_SOCKET = 6
@@ -404,4 +423,10 @@ end
socket.sendto = assert(driver.udp_send)
socket.udp_address = assert(driver.udp_address)
function socket.warning(id, callback)
local obj = socket_pool[id]
assert(obj)
obj.warning = callback
end
return socket