Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with C++11 system_error (see PR #27) #25

Open
EvanBalster opened this issue May 18, 2021 · 1 comment
Open

Integrate with C++11 system_error (see PR #27) #25

EvanBalster opened this issue May 18, 2021 · 1 comment

Comments

@EvanBalster
Copy link

(Lodging an issue for this; I might be inclined to develop a pull request.)

C++11 introduces an error_code class that can accommodate both POSIX standard error codes and alternative collections of error codes such as NNG's. An error_code includes an integer value (0 for no error) and an error category which can be either the C++/POSIX one or some custom category. nngpp would benefit from implementing a custom error category.

https://en.cppreference.com/w/cpp/error/error_category
Implementations of std::error_category have a few responsibilities: Categorizing error codes, providing string representations, and mapping platform-dependent codes to platform-agnostic ones (including standard C++/POSIX error codes). These functions serve to make codebases more consistent and integrable; for example, libasio uses std::error_code extensively.

I recommend making nng::error convertible to std::error_code and/or adding a method for doing so to nng::exception.

The POSIX error codes supported by C++11 are listed here: https://en.cppreference.com/w/cpp/error/errc
The following codes have no direct mapping to a C++/POSIX equivalent.

NNG CODE possible C++ mapping
ECLOSED  
ESTATE  
EUNREACHABLE, EADDRINVAL address_not_available
ENOFILES  
EREADONLY / EWRITEONLY  
ECRYPTO / EPEERAUTH  
ENOARG / EAMBIGUOUS / EBADTYPE  
ECONNSHUT connection_aborted
EINTERNAL  
ESYSERR  
ETRANERR  

These codes would need to be either lossily mapped to C++ codes or implemented as an NNG-specific error_condition. It would be somewhat advantageous to assign them values that don't conflict with the standard C++ ones.

@EvanBalster
Copy link
Author

EvanBalster commented Jul 8, 2021

I'm working on a pull request which adds support for <system_error> to error.h without modifying or removing any current functionality.

These are my notes as I attempt to complete the mapping to generic_error_category based on the POSIX standard and a partial mapping in NNG's nn.c.

NNG CODE POSIX C++ errc Basis of mapping
ECLOSED EBADF bad_file_descriptor nn.c
ESTATE ENOTTY inappropriate_io_control_operation POSIX (nn.c uses EFSM)
EUNREACHABLE EHOSTUNREACH host_unreachable nn.c
EADDRINVAL EADDRNOTAVAIL address_not_available POSIX (nn.c uses EINVAL)
ENOFILES EMFILE too_many_files_open nn.c
EREADONLY / EWRITEONLY †EACCES permission_denied nn.c
ECRYPTO / EPEERAUTH †EACCES permission_denied nn.c
ENOARG †EINVAL invalid_argument "option requires argument"
EAMBIGUOUS †EINVAL invalid_argument nn.c
EBADTYPE †EINVAL invalid_argument nn.c
ECONNSHUT †ECONNABORTED connection_aborted closest available
EINTERNAL NNG-specific
ESYSERR (flag) platform-specific
ETRANERR (flag) transport-specific

† "Lossy" mappings; multiple NNG error codes would map to one POSIX error in default_error_condition.

@EvanBalster EvanBalster changed the title Integrate with C++11 system_error Integrate with C++11 system_error (see PR #27) Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant