| 1234567891011121314151617181920212223242526272829303132333435363738 |
- -- Socket消息队列
- local NetworkQueue = {}
- local queue = require("Base/Utils.lua"):CreateQueue()
- local map = {}
- function NetworkQueue:PushUidOnSend(uid)
- queue:Enqueue(uid)
- end
- function NetworkQueue:PushMsgOnRecv(uid, data)
- map[uid] = data
- end
- function NetworkQueue:TryPopMsg()
- local uid = queue:Peek()
- if (uid == nil) then
- return nil
- end
- local ret = map[uid]
- if ret == nil then
- print("NetworkQueue uid is not inside the queue. Msg may not received yet.")
- return nil
- end
- queue:Dequeue()
- map[uid] = nil
- return ret
- end
- function NetworkQueue:Reset()
- queue = require("Base/Utils.lua"):CreateQueue()
- map = {}
- end
- return NetworkQueue
|