mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
add new socket message WARNING
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user