Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
576db850
Commit
576db850
authored
Sep 18, 2018
by
Ian Roddis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Augmenting test, removing context preference from transport
parent
04a67aa7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
36 deletions
+31
-36
include/pistache/transport.h
include/pistache/transport.h
+9
-24
tests/streaming_test.cc
tests/streaming_test.cc
+22
-12
No files found.
include/pistache/transport.h
View file @
576db850
...
...
@@ -31,30 +31,15 @@ public:
template
<
typename
Buf
>
Async
::
Promise
<
ssize_t
>
asyncWrite
(
Fd
fd
,
const
Buf
&
buffer
,
int
flags
=
0
)
{
// If the I/O operation has been initiated from an other thread, we queue it and we'll process
// it in our own thread so that we make sure that every I/O operation happens in the right thread
auto
ctx
=
context
();
const
bool
isInRightThread
=
std
::
this_thread
::
get_id
()
==
ctx
.
thread
();
if
(
!
isInRightThread
)
{
return
Async
::
Promise
<
ssize_t
>
([
=
](
Async
::
Deferred
<
ssize_t
>
deferred
)
mutable
{
BufferHolder
holder
(
buffer
);
auto
detached
=
holder
.
detach
();
WriteEntry
write
(
std
::
move
(
deferred
),
detached
,
flags
);
write
.
peerFd
=
fd
;
auto
*
e
=
writesQueue
.
allocEntry
(
std
::
move
(
write
));
writesQueue
.
push
(
e
);
});
}
return
Async
::
Promise
<
ssize_t
>
([
&
](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
auto
it
=
toWrite
.
find
(
fd
);
if
(
it
!=
std
::
end
(
toWrite
))
{
reject
(
Pistache
::
Error
(
"Multiple writes on the same fd"
));
return
;
}
asyncWriteImpl
(
fd
,
flags
,
BufferHolder
(
buffer
),
Async
::
Deferred
<
ssize_t
>
(
std
::
move
(
resolve
),
std
::
move
(
reject
)));
// Always enqueue reponses for sending. Giving preference to consumer
// context means chunked responses could be sent out of order.
return
Async
::
Promise
<
ssize_t
>
([
=
](
Async
::
Deferred
<
ssize_t
>
deferred
)
mutable
{
BufferHolder
holder
(
buffer
);
auto
detached
=
holder
.
detach
();
WriteEntry
write
(
std
::
move
(
deferred
),
detached
,
flags
);
write
.
peerFd
=
fd
;
auto
*
e
=
writesQueue
.
allocEntry
(
std
::
move
(
write
));
writesQueue
.
push
(
e
);
});
}
...
...
tests/streaming_test.cc
View file @
576db850
...
...
@@ -15,15 +15,29 @@ void dumpData(const Rest::Request&req, Http::ResponseWriter response) {
UNUSED
(
req
);
auto
stream
=
response
.
stream
(
Http
::
Code
::
Ok
);
std
::
streamsize
n
=
1000
;
char
data
=
'A'
;
char
letter
=
'A'
;
std
::
mutex
responseGuard
;
std
::
vector
<
std
::
thread
>
workers
;
auto
sendPayload
=
[
&
responseGuard
,
&
stream
,
n
](
char
let
)
->
void
{
size_t
chunk_size
=
n
/
10
;
{
std
::
unique_lock
<
std
::
mutex
>
l
(
responseGuard
);
for
(
size_t
chunk
=
0
;
chunk
<
10
;
++
chunk
)
{
std
::
string
payload
(
chunk_size
*
chunk
,
let
);
stream
.
write
(
payload
.
c_str
(),
n
);
stream
.
flush
();
}
}
};
for
(
size_t
i
;
i
<
26
;
++
i
)
{
std
::
cout
<<
"Sending "
<<
n
<<
" bytes of "
<<
data
<<
std
::
endl
;
std
::
string
payload
(
data
++
,
n
);
stream
.
write
(
payload
.
c_str
(),
n
);
stream
.
flush
();
workers
.
emplace_back
(
std
::
thread
(
sendPayload
,
letter
+
i
));
}
for
(
auto
&
w
:
workers
)
{
w
.
join
();
}
stream
.
ends
();
}
...
...
@@ -87,16 +101,12 @@ TEST(stream, from_description)
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
&
ss
);
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
{
std
::
cout
<<
"Curl failed: "
<<
curl_easy_strerror
(
res
)
<<
std
::
endl
;
throw
std
::
runtime_error
(
curl_easy_strerror
(
res
))
;
}
curl_easy_cleanup
(
curl
);
}
std
::
cout
<<
"GOT HERE"
<<
std
::
endl
;
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
150
));
ASSERT_EQ
(
ss
.
str
().
size
(),
26000
);
kill
(
pid
,
SIGTERM
);
int
r
;
...
...
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