萝卜L

导航

lua copas 流水账

  • Copas - Coroutine Oriented Portable Asynchronous Services for Lua (lunarmodules.github.io)

    dispatch with scheduler
    server accepts connections from client
    socket.select
    migrate from traditional to copas
    socket+sleep/timer
    asynchronous(concurrent)/synchronous
    可以不使用copas.loop(),而是通过copas.step()集成于外部过程。
    copas.running、copas.finished()
    server = socket.bind(host, port)-copas.addserver(server, handle)

    host, port: server bind-accept-handle(receive/send)(incoming) client
    host, port: client connect to server(outgoing)

  • Copas - Coroutine Oriented Portable Asynchronous Services for Lua (lunarmodules.github.io)
    LuaSocket: Network support for the Lua language (lunarmodules.github.io)
  • skt/sock都被用于表示socket的实例。
  • copasSocekt=copas.wrap(socket),此时,超时默认为无限期(无需socket:settimeout(0))
  • copas.handler (for incoming connections) and copas.wrap (for outgoing connections)
  • 当前版本3.0.0有外部依赖了binaryheaptimerwheel
  • receive'*l'要和send'\n'搭配。
  • 可以同一个主机多client连接同一个server(此server可在此同一个主机)
  • send/receive耗时少,sleep精确,貌似connect耗时多(2+s)。
  • 貌似使用copasSocket:connectsocket:connect快。(即,先wrap)
    类似的,尽管在服务端(Server)用了copas.addserver(server,handle),但handle中传入的是socket,不是copasSocket,需要copasSocket=copas.wrap(socket)。
    否则,不是并行,会很慢!

posted on 2022-04-11 17:12  萝卜L  阅读(63)  评论(0编辑  收藏  举报