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
fa0ac913
Commit
fa0ac913
authored
Oct 02, 2018
by
Ian Roddis
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://github.com/oktal/pistache
into streaming_test
parents
d90b9f58
d59eee7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
13 deletions
+53
-13
include/pistache/common.h
include/pistache/common.h
+1
-0
include/pistache/listener.h
include/pistache/listener.h
+2
-2
src/server/listener.cc
src/server/listener.cc
+20
-9
tests/listener_test.cc
tests/listener_test.cc
+30
-2
No files found.
include/pistache/common.h
View file @
fa0ac913
...
...
@@ -59,6 +59,7 @@ namespace Const {
static
constexpr
size_t
MaxBacklog
=
128
;
static
constexpr
size_t
MaxEvents
=
1024
;
static
constexpr
size_t
MaxBuffer
=
4096
;
static
constexpr
size_t
DefaultWorkers
=
1
;
// Defined from CMakeLists.txt in project root
static
constexpr
size_t
DefaultMaxPayload
=
4096
;
...
...
include/pistache/listener.h
View file @
fa0ac913
...
...
@@ -42,7 +42,7 @@ public:
Listener
();
~
Listener
();
Listener
(
const
Address
&
address
);
explicit
Listener
(
const
Address
&
address
);
void
init
(
size_t
workers
,
Flags
<
Options
>
options
=
Options
::
None
,
...
...
@@ -80,7 +80,7 @@ private:
std
::
shared_ptr
<
Transport
>
transport_
;
std
::
shared_ptr
<
Handler
>
handler_
;
std
::
shared_ptr
<
Aio
::
Reactor
>
reactor_
;
Aio
::
Reactor
reactor_
;
Aio
::
Reactor
::
Key
transportKey
;
void
handleNewConnection
();
...
...
src/server/listener.cc
View file @
fa0ac913
...
...
@@ -74,16 +74,27 @@ void setSocketOptions(Fd fd, Flags<Options> options) {
}
Listener
::
Listener
()
:
listen_fd
(
-
1
)
:
addr_
()
,
listen_fd
(
-
1
)
,
backlog_
(
Const
::
MaxBacklog
)
,
reactor_
(
Aio
::
Reactor
::
create
())
,
shutdownFd
()
,
poller
()
,
options_
()
,
workers_
(
Const
::
DefaultWorkers
)
,
reactor_
()
,
transportKey
()
{
}
Listener
::
Listener
(
const
Address
&
address
)
:
addr_
(
address
)
,
listen_fd
(
-
1
)
,
backlog_
(
Const
::
MaxBacklog
)
,
reactor_
(
Aio
::
Reactor
::
create
())
,
shutdownFd
()
,
poller
()
,
options_
()
,
workers_
(
Const
::
DefaultWorkers
)
,
reactor_
()
,
transportKey
()
{
}
...
...
@@ -190,8 +201,8 @@ Listener::bind(const Address& address) {
transport_
.
reset
(
new
Transport
(
handler_
));
reactor_
->
init
(
Aio
::
AsyncContext
(
workers_
));
transportKey
=
reactor_
->
addHandler
(
transport_
);
reactor_
.
init
(
Aio
::
AsyncContext
(
workers_
));
transportKey
=
reactor_
.
addHandler
(
transport_
);
return
true
;
}
...
...
@@ -203,7 +214,7 @@ Listener::isBound() const {
void
Listener
::
run
()
{
reactor_
->
run
();
reactor_
.
run
();
for
(;;)
{
std
::
vector
<
Polling
::
Event
>
events
;
...
...
@@ -238,12 +249,12 @@ Listener::runThreaded() {
void
Listener
::
shutdown
()
{
if
(
shutdownFd
.
isBound
())
shutdownFd
.
notify
();
reactor_
->
shutdown
();
reactor_
.
shutdown
();
}
Async
::
Promise
<
Listener
::
Load
>
Listener
::
requestLoad
(
const
Listener
::
Load
&
old
)
{
auto
handlers
=
reactor_
->
handlers
(
transportKey
);
auto
handlers
=
reactor_
.
handlers
(
transportKey
);
std
::
vector
<
Async
::
Promise
<
rusage
>>
loads
;
for
(
const
auto
&
handler
:
handlers
)
{
...
...
@@ -321,7 +332,7 @@ Listener::handleNewConnection() {
void
Listener
::
dispatchPeer
(
const
std
::
shared_ptr
<
Peer
>&
peer
)
{
auto
handlers
=
reactor_
->
handlers
(
transportKey
);
auto
handlers
=
reactor_
.
handlers
(
transportKey
);
auto
idx
=
peer
->
fd
()
%
handlers
.
size
();
auto
transport
=
std
::
static_pointer_cast
<
Transport
>
(
handlers
[
idx
]);
...
...
tests/listener_test.cc
View file @
fa0ac913
...
...
@@ -109,7 +109,7 @@ TEST(listener_test, listener_bind_port_free) {
if
(
port_nb
==
0
)
{
FAIL
()
<<
"Could not find a free port. Abor
d
test.
\n
"
;
FAIL
()
<<
"Could not find a free port. Abor
t
test.
\n
"
;
}
Pistache
::
Port
port
(
port_nb
);
...
...
@@ -123,6 +123,34 @@ TEST(listener_test, listener_bind_port_free) {
ASSERT_TRUE
(
true
);
}
// Listener should not crash if an additional member is added to the listener class. This test
// is there to prevent regression for PR 303
TEST
(
listener_test
,
listener_uses_default
)
{
uint16_t
port_nb
;
// This is just done to get the value of a free port. The socket will be closed
// after the closing curly bracket and the port will be free again (SO_REUSEADDR option).
// In theory, it is possible that some application grab this port before we bind it again...
{
SocketWrapper
s
=
bind_free_port
();
port_nb
=
s
.
port
();
}
if
(
port_nb
==
0
)
{
FAIL
()
<<
"Could not find a free port. Abort test.
\n
"
;
}
Pistache
::
Port
port
(
port_nb
);
Pistache
::
Address
address
(
Pistache
::
Ipv4
::
any
(),
port
);
Pistache
::
Tcp
::
Listener
listener
;
listener
.
setHandler
(
Pistache
::
Http
::
make_handler
<
DummyHandler
>
());
listener
.
bind
(
address
);
ASSERT_TRUE
(
true
);
}
TEST
(
listener_test
,
listener_bind_port_not_free_throw_runtime
)
{
...
...
@@ -130,7 +158,7 @@ TEST(listener_test, listener_bind_port_not_free_throw_runtime) {
uint16_t
port_nb
=
s
.
port
();
if
(
port_nb
==
0
)
{
FAIL
()
<<
"Could not find a free port. Abor
d
test.
\n
"
;
FAIL
()
<<
"Could not find a free port. Abor
t
test.
\n
"
;
}
Pistache
::
Port
port
(
port_nb
);
...
...
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