Coder Social home page Coder Social logo

服务端同时开启多个端口 about uv-cpp HOT 4 CLOSED

wlgq2 avatar wlgq2 commented on July 22, 2024
服务端同时开启多个端口

from uv-cpp.

Comments (4)

wlgq2 avatar wlgq2 commented on July 22, 2024 2

我还是抽空写个使用文档吧……

from uv-cpp.

wlgq2 avatar wlgq2 commented on July 22, 2024

如果这些server跑在同一个线程,那没什么问题。如果这些server跑在不同线程,相互之间不交互数据,那也没什么问题。如果这些server跑在不同线程并且相互要交互数据,由于libuv本身不是线程线程安全,通过async接口交互数据就没问题(在loop1注册一个函数到loop2里面执行),在uv-cpp里面封装成了uv::EventLoop::runInThisLoop接口。只要每个线程都单独开一个loop,就没问题。

from uv-cpp.

wlgq2 avatar wlgq2 commented on July 22, 2024

需要注意的是这些对象的构造函数也不是线程安全的(因为要注册到loop里面去)。举个例子,在loop1里面创建一个loop2线程下运行的client。
loop2->runInThisLoop([loop2]() { uv::TcpClient(loop2); });

from uv-cpp.

cjl3230 avatar cjl3230 commented on July 22, 2024

方便写个例子程序参考吗?刚刚开始学习您的uv-cpp的库,还不太了解

from uv-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.