Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
abaadba1
Commit
abaadba1
authored
Oct 24, 2016
by
Kenton Varda
Committed by
Kenton Varda
Apr 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement KJ_SYSCALL_HANDLE_ERRORS.
parent
1c71c828
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
debug.h
c++/src/kj/debug.h
+35
-0
No files found.
c++/src/kj/debug.h
View file @
abaadba1
...
...
@@ -290,6 +290,25 @@ namespace kj {
#endif
#define KJ_SYSCALL_HANDLE_ERRORS(call) \
if (int _kjSyscallError = ::kj::_::Debug::syscallError([&](){return (call);}, false)) \
switch (int error = _kjSyscallError)
// Like KJ_SYSCALL, but doesn't throw. Instead, the block after the macro is a switch block on the
// error. Additionally, the int value `error` is defined within the block. So you can do:
//
// KJ_SYSCALL_HANDLE_ERRORS(foo()) {
// case ENOENT:
// handleNoSuchFile();
// break;
// case EEXIST:
// handleExists();
// break;
// default:
// KJ_FAIL_SYSCALL("foo()", error);
// } else {
// handleSuccessCase();
// }
#define KJ_ASSERT KJ_REQUIRE
#define KJ_FAIL_ASSERT KJ_FAIL_REQUIRE
#define KJ_ASSERT_NONNULL KJ_REQUIRE_NONNULL
...
...
@@ -377,6 +396,8 @@ public:
template
<
typename
Call
>
static
SyscallResult
syscall
(
Call
&&
call
,
bool
nonblocking
);
template
<
typename
Call
>
static
int
syscallError
(
Call
&&
call
,
bool
nonblocking
);
#if _WIN32
static
bool
isWin32Success
(
int
boolean
);
...
...
@@ -503,6 +524,20 @@ Debug::SyscallResult Debug::syscall(Call&& call, bool nonblocking) {
return
SyscallResult
(
0
);
}
template
<
typename
Call
>
int
Debug
::
syscallError
(
Call
&&
call
,
bool
nonblocking
)
{
while
(
call
()
<
0
)
{
int
errorNum
=
getOsErrorNumber
(
nonblocking
);
// getOsErrorNumber() returns -1 to indicate EINTR.
// Also, if nonblocking is true, then it returns 0 on EAGAIN, which will then be treated as a
// non-error.
if
(
errorNum
!=
-
1
)
{
return
errorNum
;
}
}
return
0
;
}
template
<
typename
...
Params
>
String
Debug
::
makeDescription
(
const
char
*
macroArgs
,
Params
&&
...
params
)
{
String
argValues
[
sizeof
...(
Params
)]
=
{
str
(
params
)...};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment