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
8ec0cbb5
Commit
8ec0cbb5
authored
Apr 21, 2018
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for tryPumpFrom and fix a bug.
parent
ff34f25b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
165 additions
and
4 deletions
+165
-4
async-io-test.c++
c++/src/kj/async-io-test.c++
+163
-2
async-io.c++
c++/src/kj/async-io.c++
+2
-2
No files found.
c++/src/kj/async-io-test.c++
View file @
8ec0cbb5
...
...
@@ -1056,7 +1056,7 @@ KJ_TEST("Userland pipe gather write split pump on buffer boundary") {
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
3
);
}
KJ_TEST
(
"Userland pipe gather write split pump
split
mid-first-buffer"
)
{
KJ_TEST
(
"Userland pipe gather write split pump mid-first-buffer"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
...
...
@@ -1078,7 +1078,7 @@ KJ_TEST("Userland pipe gather write split pump split mid-first-buffer") {
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
4
);
}
KJ_TEST
(
"Userland pipe gather write split pump
split
mid-second-buffer"
)
{
KJ_TEST
(
"Userland pipe gather write split pump mid-second-buffer"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
...
...
@@ -1100,6 +1100,167 @@ KJ_TEST("Userland pipe gather write split pump split mid-second-buffer") {
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
2
);
}
KJ_TEST
(
"Userland pipe gather write pumpFrom"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
));
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foobar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
char
c
;
auto
eofPromise
=
pipe2
.
in
->
tryRead
(
&
c
,
1
,
1
);
eofPromise
.
poll
(
ws
);
// force pump to notice EOF
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
6
);
pipe2
.
out
=
nullptr
;
KJ_EXPECT
(
eofPromise
.
wait
(
ws
)
==
0
);
}
KJ_TEST
(
"Userland pipe gather write pumpFrom split on buffer boundary"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
));
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foo"
).
wait
(
ws
);
expectRead
(
*
pipe2
.
in
,
"bar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
char
c
;
auto
eofPromise
=
pipe2
.
in
->
tryRead
(
&
c
,
1
,
1
);
eofPromise
.
poll
(
ws
);
// force pump to notice EOF
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
6
);
pipe2
.
out
=
nullptr
;
KJ_EXPECT
(
eofPromise
.
wait
(
ws
)
==
0
);
}
KJ_TEST
(
"Userland pipe gather write pumpFrom split mid-first-buffer"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
));
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"fo"
).
wait
(
ws
);
expectRead
(
*
pipe2
.
in
,
"obar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
char
c
;
auto
eofPromise
=
pipe2
.
in
->
tryRead
(
&
c
,
1
,
1
);
eofPromise
.
poll
(
ws
);
// force pump to notice EOF
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
6
);
pipe2
.
out
=
nullptr
;
KJ_EXPECT
(
eofPromise
.
wait
(
ws
)
==
0
);
}
KJ_TEST
(
"Userland pipe gather write pumpFrom split mid-second-buffer"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
));
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foob"
).
wait
(
ws
);
expectRead
(
*
pipe2
.
in
,
"ar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
char
c
;
auto
eofPromise
=
pipe2
.
in
->
tryRead
(
&
c
,
1
,
1
);
eofPromise
.
poll
(
ws
);
// force pump to notice EOF
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
6
);
pipe2
.
out
=
nullptr
;
KJ_EXPECT
(
eofPromise
.
wait
(
ws
)
==
0
);
}
KJ_TEST
(
"Userland pipe gather write split pumpFrom on buffer boundary"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
,
3
))
.
then
([
&
](
uint64_t
i
)
{
KJ_EXPECT
(
i
==
3
);
return
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
,
3
));
});
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foobar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
3
);
}
KJ_TEST
(
"Userland pipe gather write split pumpFrom mid-first-buffer"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
,
2
))
.
then
([
&
](
uint64_t
i
)
{
KJ_EXPECT
(
i
==
2
);
return
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
,
4
));
});
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foobar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
4
);
}
KJ_TEST
(
"Userland pipe gather write split pumpFrom mid-second-buffer"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
auto
pipe
=
newOneWayPipe
();
auto
pipe2
=
newOneWayPipe
();
auto
pumpPromise
=
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
,
4
))
.
then
([
&
](
uint64_t
i
)
{
KJ_EXPECT
(
i
==
4
);
return
KJ_ASSERT_NONNULL
(
pipe2
.
out
->
tryPumpFrom
(
*
pipe
.
in
,
2
));
});
ArrayPtr
<
const
byte
>
parts
[]
=
{
"foo"
_kj
.
asBytes
(),
"bar"
_kj
.
asBytes
()
};
auto
promise
=
pipe
.
out
->
write
(
parts
);
KJ_EXPECT
(
!
promise
.
poll
(
ws
));
expectRead
(
*
pipe2
.
in
,
"foobar"
).
wait
(
ws
);
promise
.
wait
(
ws
);
pipe
.
out
=
nullptr
;
KJ_EXPECT
(
pumpPromise
.
wait
(
ws
)
==
2
);
}
KJ_TEST
(
"Userland pipe pumpTo less than write amount"
)
{
kj
::
EventLoop
loop
;
WaitScope
ws
(
loop
);
...
...
c++/src/kj/async-io.c++
View file @
8ec0cbb5
...
...
@@ -484,8 +484,8 @@ private:
if
(
actual
>=
minBytes
)
{
return
actual
;
}
else
{
return
pipe
.
r
ead
(
reinterpret_cast
<
byte
*>
(
readBuffer
)
+
actual
,
minBytes
-
actual
,
maxBytes
-
actual
)
return
pipe
.
tryR
ead
(
reinterpret_cast
<
byte
*>
(
readBuffer
)
+
actual
,
minBytes
-
actual
,
maxBytes
-
actual
)
.
then
([
actual
](
size_t
actual2
)
{
return
actual
+
actual2
;
});
}
}));
...
...
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