-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Move IoError interface from Network to Api namespace #6104
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "envoy/common/platform.h" | ||
| #include "envoy/common/pure.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Api { | ||
|
|
||
| class IoError; | ||
|
|
||
| // IoErrorCode::Again is used frequently. Define it to be a distinguishable address to avoid | ||
| // frequent memory allocation of IoError instance. | ||
| // If this is used, IoCallResult has to be instantiated with a deleter that does not | ||
| // deallocate memory for this error. | ||
| #define ENVOY_ERROR_AGAIN reinterpret_cast<Api::IoError*>(0x01) | ||
|
|
||
| /** | ||
| * Base class for any I/O error. | ||
| */ | ||
| class IoError { | ||
| public: | ||
| enum class IoErrorCode { | ||
| // No data available right now, try again later. | ||
| Again, | ||
| // Not supported. | ||
| NoSupport, | ||
| // Address family not supported. | ||
| AddressFamilyNoSupport, | ||
| // During non-blocking connect, the connection cannot be completed immediately. | ||
| InProgress, | ||
| // Permission denied. | ||
| Permission, | ||
| // Bad handle | ||
| BadHandle, | ||
| // Other error codes cannot be mapped to any one above in getErrorCode(). | ||
| UnknownError | ||
| }; | ||
| virtual ~IoError() {} | ||
|
|
||
| // Map platform specific error into IoErrorCode. | ||
| // Needed to hide errorCode() in case of ENVOY_ERROR_AGAIN. | ||
| static IoErrorCode getErrorCode(const IoError& err) { | ||
| if (&err == ENVOY_ERROR_AGAIN) { | ||
| return IoErrorCode::Again; | ||
| } | ||
| return err.errorCode(); | ||
| } | ||
|
|
||
| static std::string getErrorDetails(const IoError& err) { | ||
| if (&err == ENVOY_ERROR_AGAIN) { | ||
| return "Try again later"; | ||
| } | ||
| return err.errorDetails(); | ||
| } | ||
|
|
||
| protected: | ||
| virtual IoErrorCode errorCode() const PURE; | ||
| virtual std::string errorDetails() const PURE; | ||
| }; | ||
|
|
||
| using IoErrorDeleterType = void (*)(IoError*); | ||
| using IoErrorPtr = std::unique_ptr<IoError, IoErrorDeleterType>; | ||
|
|
||
| /** | ||
| * Basic type for return result which has a return code and error code defined | ||
| * according to different implementations. | ||
| */ | ||
| template <typename T> struct IoCallResult { | ||
| IoCallResult(T rc, IoErrorPtr err) : rc_(rc), err_(std::move(err)) {} | ||
|
|
||
| IoCallResult(IoCallResult<T>&& result) : rc_(result.rc_), err_(std::move(result.err_)) {} | ||
|
|
||
| virtual ~IoCallResult() {} | ||
|
|
||
| T rc_; | ||
| IoErrorPtr err_; | ||
| }; | ||
|
|
||
| using IoCallBoolResult = IoCallResult<bool>; | ||
| using IoCallSizeResult = IoCallResult<ssize_t>; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're left overs from #6072. I'll remove them. |
||
| using IoCallUintResult = IoCallResult<uint64_t>; | ||
|
|
||
| } // namespace Api | ||
| } // namespace Envoy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.