其中升压错误codeS /条件由Boost.Asio的调用返回的? [英] Which Boost error codes/conditions are returned by which Boost.Asio calls?

查看:266
本文介绍了其中升压错误codeS /条件由Boost.Asio的调用返回的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个使用Boost.Asio的作为底层套接字API一个TCP I / O设备,和我注意到 Boost.Asio的似乎缺少文档上的特定错误升压codeS /条件可能导致每个单独的操作(如函数/方法调用或异步运行)。所有这一切我已经能够找到的是错误code API和一些非正式的错误code列出,其中没有一个具体的业务相关的特定codeS

I am currently writing a TCP I/O facility that uses Boost.Asio as the underlying socket API, and I've noticed that Boost.Asio seems to lack documentation on which specific Boost error codes/conditions can result from each individual operation (e.g. function/method call or asynchronous operation). All that I've been able to find is the error code API and some informal error code lists, none of which correlate specific codes to specific operations.

这显然缺乏文档是令人沮丧的,因为它是很难写出健壮code,当你不知道可能的故障模式。这是不可能的,甚至给出例子,因为我甚至相信这些问题可以从哪些操作出现由于缺少文档。

This apparent lack of documentation is frustrating, because it's difficult to write robust code when you don't know the possible failure modes. It's impossible to even give examples, since I'm not even confident of which issues could arise from which operations due to the lack of documentation.

在比较中,POSIX套接字API是pretty在记录故障模式得体。特别是,它列出可以由每个函数调用中产生错误号和返回值。

In comparison, the POSIX socket API is pretty decent at documenting failure modes. In particular, it lists errno and return values that can be generated by each function call.

这是否Boost.Asio的文件存在的地方,而我只是没有看到呢?或者我应该只是猜测,逆向工程,或收集在Boost.Asio的API的不同部分的故障模式的经验数据,以便能够编写使用它强大的code?

Does this Boost.Asio documentation exist somewhere, and I'm just not seeing it? Or am I supposed to just guess at, reverse engineer, or collect empirical data on the failure modes of various parts of the Boost.Asio API in order to be able to write robust code that uses it?

推荐答案

在一般情况下,当Boost.Asio的依赖于操作系统的执行,则它将既不指定条件,可能发生错误的条件,也没有错误codeS那可以返回。如果失败,将Boost.Asio的填充的boost ::系统::错误_ code 如果应用程序能够接收它,比如异步操作或同步操作过载与错误_ code 参数;否则会抛出包含错误_ code 例外。在<一个href=\"http://www.boost.org/doc/libs/1_59_0/doc/html/boost_asio/reference/asynchronous_operations.html\"相对=nofollow>文档规定如下:

In general, when Boost.Asio depends on the OS implementation, then it will neither specify the conditions under which errors may occur nor the error codes that may be returned. On failure Boost.Asio will populate a boost::system::error_code if the application is capable of receiving it, such as for asynchronous operations or synchronous operation overloads with the error_code parameter; otherwise it will throw an exception containing the error_code. The documentation states the following:

除非另有说明,当一个异步操作的行为被定义为如同由POSIX函数来实现,该处理器将有类型的值来调用错误_ code 对应于该功能,如果有通过POSIX描述的故障情况。否则,处理器将反映操作系统错误实现定义的错误_ code 价值被调用。

Unless otherwise noted, when the behaviour of an asynchronous operation is defined "as if" implemented by a POSIX function, the handler will be invoked with a value of type error_code that corresponds to the failure condition described by POSIX for that function, if any. Otherwise the handler will be invoked with an implementation-defined error_code value that reflects the operating system error.

异步操作不会失败与通过信号指示中断错误条件(POSIX EINTR )。异步操作不会失败,(POSIX EWOULDBLOCK EAGAIN 与非阻塞的操作有关的任何错误状况或 EINPROGRESS ;的Windows WSAEWOULDBLOCK WSAEINPROGRESS

Asynchronous operations will not fail with an error condition that indicates interruption by a signal (POSIX EINTR). Asynchronous operations will not fail with any error condition associated with non-blocking operations (POSIX EWOULDBLOCK, EAGAIN or EINPROGRESS; Windows WSAEWOULDBLOCK or WSAEINPROGRESS).

如果错误处理依赖于精确的错误code,那么就可以经常使用的 BSD API映射文档以确定正在作出何种操作系统调用。然后我们可以使用适当的操作系统文档,以确定哪些错误发生的条件和值。错误codeS和Boost.Asio的错误codeS之间的映射位于的 ASIO / error.hpp ,但映射通常是相当简单的。

If error handling depends on the exact error code, then one can often use the BSD API mapping documentation to determine which OS calls are being made. One can then use the appropriate OS documentation to determine the conditions for which an error occurs and the values. The mapping between error codes and Boost.Asio error codes is located within asio/error.hpp, but the mapping is normally fairly straight forward.

这篇关于其中升压错误codeS /条件由Boost.Asio的调用返回的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆