Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
nghttp2
Commits
36a20233
Commit
36a20233
authored
Feb 05, 2017
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: Fix compile errors for asio server examples
parent
51e474c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
4 deletions
+39
-4
examples/asio-sv.cc
examples/asio-sv.cc
+20
-2
examples/asio-sv2.cc
examples/asio-sv2.cc
+19
-2
No files found.
examples/asio-sv.cc
View file @
36a20233
...
...
@@ -36,12 +36,25 @@
#include <iostream>
#include <string>
#include <thread>
#include <nghttp2/asio_http2_server.h>
using
namespace
nghttp2
::
asio_http2
;
using
namespace
nghttp2
::
asio_http2
::
server
;
namespace
{
void
run_forever
(
boost
::
asio
::
io_service
&
io_service
,
size_t
num_threads
)
{
std
::
vector
<
std
::
thread
>
ts
;
for
(
size_t
i
=
0
;
i
<
num_threads
;
++
i
)
{
ts
.
emplace_back
([
&
io_service
]()
{
io_service
.
run
();
});
}
for
(
auto
&
t
:
ts
)
{
t
.
join
();
}
}
}
// namespace
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
// Check command line arguments.
...
...
@@ -58,9 +71,9 @@ int main(int argc, char *argv[]) {
std
::
string
port
=
argv
[
2
];
std
::
size_t
num_threads
=
std
::
stoi
(
argv
[
3
]);
http2
server
;
boost
::
asio
::
io_service
io_service
;
server
.
num_threads
(
num_threads
);
http2
server
(
io_service
);
server
.
handle
(
"/"
,
[](
const
request
&
req
,
const
response
&
res
)
{
res
.
write_head
(
200
,
{{
"foo"
,
{
"bar"
}}});
...
...
@@ -136,11 +149,16 @@ int main(int argc, char *argv[]) {
if
(
server
.
listen_and_serve
(
ec
,
tls
,
addr
,
port
))
{
std
::
cerr
<<
"error: "
<<
ec
.
message
()
<<
std
::
endl
;
}
run_forever
(
io_service
,
num_threads
);
}
else
{
if
(
server
.
listen_and_serve
(
ec
,
addr
,
port
))
{
std
::
cerr
<<
"error: "
<<
ec
.
message
()
<<
std
::
endl
;
}
run_forever
(
io_service
,
num_threads
);
}
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
"exception: "
<<
e
.
what
()
<<
"
\n
"
;
}
...
...
examples/asio-sv2.cc
View file @
36a20233
...
...
@@ -43,12 +43,25 @@
#endif // HAVE_FCNTL_H
#include <iostream>
#include <string>
#include <thread>
#include <nghttp2/asio_http2_server.h>
using
namespace
nghttp2
::
asio_http2
;
using
namespace
nghttp2
::
asio_http2
::
server
;
namespace
{
void
run_forever
(
boost
::
asio
::
io_service
&
io_service
,
size_t
num_threads
)
{
std
::
vector
<
std
::
thread
>
ts
;
for
(
size_t
i
=
0
;
i
<
num_threads
;
++
i
)
{
ts
.
emplace_back
([
&
io_service
]()
{
io_service
.
run
();
});
}
for
(
auto
&
t
:
ts
)
{
t
.
join
();
}
}
}
// namespace
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
// Check command line arguments.
...
...
@@ -65,9 +78,9 @@ int main(int argc, char *argv[]) {
std
::
size_t
num_threads
=
std
::
stoi
(
argv
[
3
]);
std
::
string
docroot
=
argv
[
4
];
http2
server
;
boost
::
asio
::
io_service
io_service
;
server
.
num_threads
(
num_threads
);
http2
server
(
io_service
);
server
.
handle
(
"/"
,
[
&
docroot
](
const
request
&
req
,
const
response
&
res
)
{
auto
path
=
percent_decode
(
req
.
uri
().
path
);
...
...
@@ -112,10 +125,14 @@ int main(int argc, char *argv[]) {
if
(
server
.
listen_and_serve
(
ec
,
tls
,
addr
,
port
))
{
std
::
cerr
<<
"error: "
<<
ec
.
message
()
<<
std
::
endl
;
}
run_forever
(
io_service
,
num_threads
);
}
else
{
if
(
server
.
listen_and_serve
(
ec
,
addr
,
port
))
{
std
::
cerr
<<
"error: "
<<
ec
.
message
()
<<
std
::
endl
;
}
run_forever
(
io_service
,
num_threads
);
}
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
"exception: "
<<
e
.
what
()
<<
"
\n
"
;
...
...
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