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
8d2ed06b
Commit
8d2ed06b
authored
Apr 24, 2018
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pipe bug where tryPumpFrom() behaved differently than pumpTo().
parent
3b85e1c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
async-io-test.c++
c++/src/kj/async-io-test.c++
+20
-0
async-io.c++
c++/src/kj/async-io.c++
+21
-1
No files found.
c++/src/kj/async-io-test.c++
View file @
8d2ed06b
...
...
@@ -1289,5 +1289,25 @@ KJ_TEST("Userland pipe pumpTo less than write amount") {
writePromise
.
wait
(
ws
);
}
KJ_TEST
(
"Userland pipe pumpFrom EOF on abortRead()"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
));
auto
promise
=
pipe
.
out
->
write
(
"foobar"
,
6
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foobar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
KJ_EXPECT
(
!
pumpPromise
.
poll
(
ws
));
pipe
.
out
=
nullptr
;
pipe2
.
in
=
nullptr
;
// force pump to notice EOF
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
6
);
pipe2
.
out
=
nullptr
;
}
}
// namespace
}
// namespace kj
c++/src/kj/async-io.c++
View file @
8d2ed06b
...
...
@@ -522,7 +522,26 @@ private:
void
abortRead
()
override
{
canceler
.
cancel
(
"abortRead() was called"
);
fulfiller
.
reject
(
KJ_EXCEPTION
(
FAILED
,
"read end of pipe was aborted"
));
// The input might have reached EOF, but we haven't detected it yet because we haven't tried
// to read that far. If we had not optimized tryPumpFrom() and instead used the default
// pumpTo() implementation, then the input would not have called write() again once it
// reached EOF, and therefore the abortRead() on the other end would *not* propagate an
// exception! We need the same behavior here. To that end, we need to detect if we're at EOF
// by reading one last byte.
checkEofTask
=
kj
::
evalNow
([
&
]()
{
static
char
junk
;
return
input
.
tryRead
(
&
junk
,
1
,
1
).
then
([
this
](
uint64_t
n
)
{
if
(
n
==
0
)
{
fulfiller
.
fulfill
(
kj
::
cp
(
pumpedSoFar
));
}
else
{
fulfiller
.
reject
(
KJ_EXCEPTION
(
FAILED
,
"read end of pipe was aborted"
));
}
}).
eagerlyEvaluate
([
this
](
kj
::
Exception
&&
e
)
{
fulfiller
.
reject
(
kj
::
mv
(
e
));
});
});
pipe
.
endState
(
*
this
);
pipe
.
abortRead
();
}
...
...
@@ -547,6 +566,7 @@ private:
uint64_t
amount
;
uint64_t
pumpedSoFar
=
0
;
Canceler
canceler
;
kj
::
Promise
<
void
>
checkEofTask
=
nullptr
;
};
class
BlockedRead
final
:
public
AsyncIoStream
{
...
...
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