什么 C++用于编写跨平台服务/守护程序的库?

发布于 2024-08-29 20:12:06 字数 122 浏览 9 评论 0 原文

我想知道什么库可以简化跨平台服务/守护程序的开发? (C/C++)

我的目标是:Windows、Linux 和 OS X。 要求:网络操作和串口通信。

另外,如果有一个基本的示例服务应用程序就好了。

I wonder what library would ease the development of a cross-platform service/daemon ? (C/C++)

I'm targeting: Windows, Linux and OS X.
Requirements: network operations and serial port communication.

Also it would be nice to have a basic sample service application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吻安 2024-09-05 20:12:06

当谈到 Qt 时,你可以尝试 qt-service

When it comes to Qt you might try qt-service.

ま柒月 2024-09-05 20:12:06

Linux 中的守护进程实际上只是一个与终端断开连接运行的进程。在 Windows 中,服务是可以使用服务管理 API 进行控制的东西,但基本上只是一个断开连接的进程。撇开断开连接不谈,守护进程和进程从任务到任务,服务器没有太多共同点。例如,不要求它们是多线程的、异步的或执行网络 I/O。鉴于此,很难看出跨平台库会做什么。

A daemon in Linux is really just a process that runs disconnected from a terminal. In Windows, a service is something that can be controlled using the service management API, but once again is basically just a disconnected process. The disconnection aside, daemons & servers don't have much in common, from task to task. There is no requirement, for example, that they be multi-threaded, be asynchronous or perform network I/O. Given that, it's kind of hard to see what a cross-platform library would do.

傲世九天 2024-09-05 20:12:06

您应该看看 POCO。根据您正在做的事情,它可能有设施为您完成大量工作,而工作量比 Boost 少得多。

必须提及ACE,尽管我个人不太关心它。

You should take a look POCO. Depending on what you are doing it could have facilities to do a large amount of the work for you with a lot less work than Boost.

An obligatory mention for ACE though I don't personally care for it much.

So要识趣 2024-09-05 20:12:06

Boost 可能拥有您所需要的大部分线程网络 I/O。

您可能还会发现 Qt 是一个不错的选择。它还具有线程和网络库,并且具有更易于使用和使用的功能。了解使用运行循环的事件驱动编程模型。 Qt 的信号/槽系统非常易于使用,非常适合网络守护进程/服务(Boost 还包括 signal/slot 系统,但它更难使用并且不包含事件循环;您必须使用一些事件库来滚动自己)。作为一个跨平台库,Qt 可以处理桥接 Unix(OS X 和 Linux)与 Windows 进程、文件系统等心智模型方面的许多问题。

对于单元测试,我对 Google 的 C++ 单元非常满意名为 googletest 的测试库(尽管 Boost 和 Qt 也都有内置的单元测试系统) 。它可以在您指定的所有平台上运行。我在跨平台 Qt 项目上使用 googletest 做了很多工作,发现它相当令人满意。

Boost probably has most of what you need in terms of threading and networking I/O.

You may also find Qt a good alternative. It also has threading and networking libraries and has a much easier to use & understand event-driven programming model using a run loop. Qt's signal/slot system is very easy to use and ideal for a network daemon/service (Boost also includes a signal/slot system but it is harder to use and does not include an event loop; you have to roll your own using some event library). As a cross-platform library, Qt can handle many of the issues in bridging the Unix (OS X and Linux) vs. Windows mental model for processes, filesystems, etc.

For unit testing, I've been very happy with Google's C++ unit testing library called googletest (though both Boost and Qt also have built-in unit testing systems). It runs on all the platforms you specify. I've done a lot of work with googletest on cross-platform Qt projects and found it quite satisfactory.

场罚期间 2024-09-05 20:12:06

我在 ASIO 的非 boost 版本中发现了一个很大的库。您不需要所有的 boost 库,而只需要这个仅包含标头且文档非常齐全的小库 http://think-async。例如

,白天的服务器-客户端系统只需很少的代码行即可实现。
看看它。

(记得看非增强版本)

I've found a big library in the non-boost version of ASIO. You don't need all boost library but only this little headers-only and very well documented library http://think-async.com/

As examples, a daytime server-client system is implemented in very few lines of code.
Take a look at it.

(remember to look at the non boost-ized version)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文