Asio Rationale

3 篇文章 0 订阅

Rationale

Most programs interact with the outside world in some way, whether it be via a file, a network, a serial cable, or the console. Sometimes, as is the case with networking, individual I/O operations can take a long time to complete. This poses particular challenges to application development.

Asio provides the tools to manage these long running operations, without requiring programs to use concurrency models based on threads and explicit locking.

The Asio library is intended for programmers using C++ for systems programming, where access to operating system functionality such as networking is often required. In particular, Asio addresses the following goals:

  • Portability. The library should support a range of commonly used operating systems, and provide consistent behaviour across these operating systems.
  • Scalability. The library should facilitate the development of network applications that scale to thousands of concurrent connections. The library implementation for each operating system should use the mechanism that best enables this scalability.
  • Efficiency. The library should support techniques such as scatter-gather I/O, and allow programs to minimise data copying.
  • Model concepts from established APIs, such as BSD sockets. The BSD socket API is widely implemented and understood, and is covered in much literature. Other programming languages often use a similar interface for networking APIs. As far as is reasonable, Asio should leverage existing practice.
  • Ease of use. The library should provide a lower entry barrier for new users by taking a toolkit, rather than framework, approach. That is, it should try to minimise the up-front investment in time to just learning a few basic rules and guidelines. After that, a library user should only need to understand the specific functions that are being used.
  • Basis for further abstraction. The library should permit the development of other libraries that provide higher levels of abstraction. For example, implementations of commonly used protocols such as HTTP.

Although Asio started life focused primarily on networking, its concepts of asynchronous I/O have been extended to include other operating system resources such as serial ports, file descriptors, and so on.

基本原理

大多数程序都以某种方式与外界交互,无论是通过文件、网络、串行电缆还是控制台。有时,就像网络的情况一样,单个 I/O 操作可能需要很长时间才能完成。这对应用程序开发提出了特殊的挑战。

Asio 提供了管理这些长时间运行操作的工具,而不需要程序使用基于线程和显式锁定的并发模型。

Asio 库适用于使用 C++ 进行系统编程的程序员,这些程序员通常需要访问网络等操作系统功能。特别是,Asio 解决了以下目标:

  • 可移植性。该库应支持一系列常用操作系统,并在这些操作系统之间提供一致的行为。
  • 可扩展性。该库应有助于开发可扩展到数千个并发连接的网络应用程序。每个操作系统的库实现都应该使用最能实现这种可伸缩性的机制。
  • 效率。该库应支持分散-收集 I/O 等技术,并允许程序最小化数据复制。
  • 来自已建立的 API 的模型概念,例如 BSD 套接字。BSD 套接字 API 被广泛实现和理解,并且在许多文献中都有介绍。其他编程语言通常使用类似的网络 API 接口。在合理的范围内,Asio 应该利用现有的做法。
  • 便于使用。该库应该通过采用工具包而不是框架方法为新用户提供较低的进入门槛。也就是说,它应该尽量减少前期投资,只学习一些基本的规则和指导方针。之后,库用户应该只需要了解正在使用的特定功能。
  • 进一步抽象的基础。该库应允许开发其他库以提供更高级别抽象。例如,HTTP 等常用协议的实现。

尽管 Asio 一开始主要专注于网络,但它的异步 I/O 概念已经扩展到包括其他操作系统资源,例如串行端口、文件描述符等。

原文出处:  Asio1.20.0(non-Boost)-Documentation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值