socketOutMsg.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --- 模块功能:socket客户端数据发送处理
  2. -- @author openLuat
  3. -- @module socketLongConnectionTrasparent.socketOutMsg
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2018.03.28
  7. module(...,package.seeall)
  8. --数据发送的消息队列
  9. local msgQueue = {}
  10. local function insertMsg(data,user)
  11. table.insert(msgQueue,{data=data,user=user})
  12. sys.publish("APP_SOCKET_SEND_DATA")
  13. end
  14. --- 去初始化“socket客户端数据发送”
  15. -- @return 无
  16. -- @usage socketOutMsg.unInit()
  17. function unInit()
  18. while #msgQueue>0 do
  19. local outMsg = table.remove(msgQueue,1)
  20. if outMsg.user and outMsg.user.cb then outMsg.user.cb(false,outMsg.user.para) end
  21. end
  22. end
  23. --- socket客户端数据发送处理
  24. -- @param socketClient,socket客户端对象
  25. -- @return 处理成功返回true,处理出错返回false
  26. -- @usage socketOutMsg.proc(socketClient)
  27. function proc(socketClient)
  28. while #msgQueue>0 do
  29. local outMsg = table.remove(msgQueue,1)
  30. local result = socketClient:send(outMsg.data)
  31. if outMsg.user and outMsg.user.cb then outMsg.user.cb(result,outMsg.user.para) end
  32. if not result then return end
  33. end
  34. return true
  35. end
  36. local function uartRecvData(data)
  37. insertMsg(data)
  38. end
  39. sys.subscribe("UART_RECV_DATA",uartRecvData)