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
b9667fd2
Commit
b9667fd2
authored
Nov 30, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asio: Listen to all resolved addresses
parent
d23105cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
39 deletions
+50
-39
src/asio_server.cc
src/asio_server.cc
+49
-38
src/asio_server.h
src/asio_server.h
+1
-1
No files found.
src/asio_server.cc
View file @
b9667fd2
...
@@ -50,7 +50,6 @@ server::server(const std::string &address, uint16_t port,
...
@@ -50,7 +50,6 @@ server::server(const std::string &address, uint16_t port,
signals_
(
io_service_pool_
.
get_io_service
()),
signals_
(
io_service_pool_
.
get_io_service
()),
tick_timer_
(
io_service_pool_
.
get_io_service
(),
tick_timer_
(
io_service_pool_
.
get_io_service
(),
boost
::
posix_time
::
seconds
(
1
)),
boost
::
posix_time
::
seconds
(
1
)),
acceptor_
(
io_service_pool_
.
get_io_service
()),
ssl_ctx_
(
std
::
move
(
ssl_ctx
)),
request_cb_
(
std
::
move
(
cb
))
{
ssl_ctx_
(
std
::
move
(
ssl_ctx
)),
request_cb_
(
std
::
move
(
cb
))
{
// Register to handle the signals that indicate when the server should exit.
// Register to handle the signals that indicate when the server should exit.
// It is safe to register for the same signal multiple times in a program,
// It is safe to register for the same signal multiple times in a program,
...
@@ -64,16 +63,24 @@ server::server(const std::string &address, uint16_t port,
...
@@ -64,16 +63,24 @@ server::server(const std::string &address, uint16_t port,
int
signal_number
)
{
io_service_pool_
.
stop
();
});
int
signal_number
)
{
io_service_pool_
.
stop
();
});
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
boost
::
asio
::
ip
::
tcp
::
resolver
resolver
(
acceptor
_
.
get_io_service
());
boost
::
asio
::
ip
::
tcp
::
resolver
resolver
(
io_service_pool
_
.
get_io_service
());
boost
::
asio
::
ip
::
tcp
::
resolver
::
query
query
(
address
,
std
::
to_string
(
port
));
boost
::
asio
::
ip
::
tcp
::
resolver
::
query
query
(
address
,
std
::
to_string
(
port
));
boost
::
asio
::
ip
::
tcp
::
endpoint
endpoint
=
*
resolver
.
resolve
(
query
);
acceptor_
.
open
(
endpoint
.
protocol
());
for
(
auto
itr
=
resolver
.
resolve
(
query
);
acceptor_
.
set_option
(
boost
::
asio
::
ip
::
tcp
::
acceptor
::
reuse_address
(
true
));
itr
!=
boost
::
asio
::
ip
::
tcp
::
resolver
::
iterator
();
++
itr
)
{
acceptor_
.
bind
(
endpoint
);
boost
::
asio
::
ip
::
tcp
::
endpoint
endpoint
=
*
itr
;
auto
acceptor
=
boost
::
asio
::
ip
::
tcp
::
acceptor
(
io_service_pool_
.
get_io_service
());
acceptor
.
open
(
endpoint
.
protocol
());
acceptor
.
set_option
(
boost
::
asio
::
ip
::
tcp
::
acceptor
::
reuse_address
(
true
));
acceptor
.
bind
(
endpoint
);
if
(
backlog
==
-
1
)
{
if
(
backlog
==
-
1
)
{
acceptor_
.
listen
();
acceptor
.
listen
();
}
else
{
}
else
{
acceptor_
.
listen
(
backlog
);
acceptor
.
listen
(
backlog
);
}
acceptors_
.
push_back
(
std
::
move
(
acceptor
));
}
}
start_accept
();
start_accept
();
...
@@ -109,7 +116,8 @@ void server::start_accept() {
...
@@ -109,7 +116,8 @@ void server::start_accept() {
request_cb_
,
io_service_pool_
.
get_task_io_service
(),
request_cb_
,
io_service_pool_
.
get_task_io_service
(),
io_service_pool_
.
get_io_service
(),
*
ssl_ctx_
);
io_service_pool_
.
get_io_service
(),
*
ssl_ctx_
);
acceptor_
.
async_accept
(
for
(
auto
&
acceptor
:
acceptors_
)
{
acceptor
.
async_accept
(
new_connection
->
socket
().
lowest_layer
(),
new_connection
->
socket
().
lowest_layer
(),
[
this
,
new_connection
](
const
boost
::
system
::
error_code
&
e
)
{
[
this
,
new_connection
](
const
boost
::
system
::
error_code
&
e
)
{
if
(
!
e
)
{
if
(
!
e
)
{
...
@@ -126,13 +134,15 @@ void server::start_accept() {
...
@@ -126,13 +134,15 @@ void server::start_accept() {
start_accept
();
start_accept
();
});
});
}
}
else
{
}
else
{
auto
new_connection
=
auto
new_connection
=
std
::
make_shared
<
connection
<
boost
::
asio
::
ip
::
tcp
::
socket
>>
(
std
::
make_shared
<
connection
<
boost
::
asio
::
ip
::
tcp
::
socket
>>
(
request_cb_
,
io_service_pool_
.
get_task_io_service
(),
request_cb_
,
io_service_pool_
.
get_task_io_service
(),
io_service_pool_
.
get_io_service
());
io_service_pool_
.
get_io_service
());
acceptor_
.
async_accept
(
for
(
auto
&
acceptor
:
acceptors_
)
{
acceptor
.
async_accept
(
new_connection
->
socket
(),
new_connection
->
socket
(),
[
this
,
new_connection
](
const
boost
::
system
::
error_code
&
e
)
{
[
this
,
new_connection
](
const
boost
::
system
::
error_code
&
e
)
{
if
(
!
e
)
{
if
(
!
e
)
{
...
@@ -144,6 +154,7 @@ void server::start_accept() {
...
@@ -144,6 +154,7 @@ void server::start_accept() {
start_accept
();
start_accept
();
});
});
}
}
}
}
}
}
// namespace server
}
// namespace server
...
...
src/asio_server.h
View file @
b9667fd2
...
@@ -86,7 +86,7 @@ private:
...
@@ -86,7 +86,7 @@ private:
boost
::
asio
::
deadline_timer
tick_timer_
;
boost
::
asio
::
deadline_timer
tick_timer_
;
/// Acceptor used to listen for incoming connections.
/// Acceptor used to listen for incoming connections.
boost
::
asio
::
ip
::
tcp
::
acceptor
acceptor
_
;
std
::
vector
<
boost
::
asio
::
ip
::
tcp
::
acceptor
>
acceptors
_
;
std
::
unique_ptr
<
boost
::
asio
::
ssl
::
context
>
ssl_ctx_
;
std
::
unique_ptr
<
boost
::
asio
::
ssl
::
context
>
ssl_ctx_
;
...
...
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