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
0d8215d1
Commit
0d8215d1
authored
Nov 03, 2015
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Http::Endpoint can now be configured through a set of options
parent
cf26bf91
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
11 deletions
+67
-11
main.cc
main.cc
+4
-0
src/http.cc
src/http.cc
+31
-8
src/http.h
src/http.h
+23
-0
src/listener.cc
src/listener.cc
+5
-2
src/listener.h
src/listener.h
+4
-1
No files found.
main.cc
View file @
0d8215d1
...
...
@@ -46,6 +46,10 @@ int main(int argc, char *argv[]) {
cout
<<
"Cores = "
<<
hardware_concurrency
()
<<
endl
;
Net
::
Http
::
Endpoint
server
(
addr
);
auto
opts
=
Net
::
Http
::
Endpoint
::
options
()
.
threads
(
2
)
.
flags
(
Net
::
Tcp
::
Options
::
InstallSignalHandler
);
server
.
init
(
opts
);
server
.
setHandler
(
std
::
make_shared
<
MyHandler
>
());
server
.
serve
();
...
...
src/http.cc
View file @
0d8215d1
...
...
@@ -479,6 +479,28 @@ Handler::getParser(const std::shared_ptr<Tcp::Peer>& peer) const {
return
*
peer
->
getData
<
Private
::
Parser
>
(
ParserData
);
}
Endpoint
::
Options
::
Options
()
:
threads_
(
1
)
{
}
Endpoint
::
Options
&
Endpoint
::
Options
::
threads
(
int
val
)
{
threads_
=
val
;
return
*
this
;
}
Endpoint
::
Options
&
Endpoint
::
Options
::
flags
(
Flags
<
Tcp
::
Options
>
flags
)
{
flags_
=
flags
;
return
*
this
;
}
Endpoint
::
Options
&
Endpoint
::
Options
::
backlog
(
int
val
)
{
backlog_
=
val
;
return
*
this
;
}
Endpoint
::
Endpoint
()
{
}
...
...
@@ -486,6 +508,11 @@ Endpoint::Endpoint(const Net::Address& addr)
:
listener
(
addr
)
{
}
void
Endpoint
::
init
(
const
Endpoint
::
Options
&
options
)
{
listener
.
init
(
options
.
threads_
,
options
.
flags_
);
}
void
Endpoint
::
setHandler
(
const
std
::
shared_ptr
<
Handler
>&
handler
)
{
handler_
=
handler
;
...
...
@@ -497,14 +524,6 @@ Endpoint::serve()
if
(
!
handler_
)
throw
std
::
runtime_error
(
"Must call setHandler() prior to serve()"
);
listener
.
init
(
4
,
Tcp
::
Options
::
InstallSignalHandler
);
#if 1
listener
.
pinWorker
(
0
,
CpuSet
{
0
}
);
listener
.
pinWorker
(
1
,
CpuSet
{
1
}
);
listener
.
pinWorker
(
2
,
CpuSet
{
2
}
);
listener
.
pinWorker
(
3
,
CpuSet
{
3
}
);
#endif
listener
.
setHandler
(
handler_
);
if
(
listener
.
bind
())
{
...
...
@@ -514,6 +533,10 @@ Endpoint::serve()
}
}
Endpoint
::
Options
Endpoint
::
options
()
{
return
Options
();
}
}
// namespace Http
...
...
src/http.h
View file @
0d8215d1
...
...
@@ -216,12 +216,35 @@ private:
class
Endpoint
{
public:
struct
Options
{
friend
class
Endpoint
;
Options
&
threads
(
int
val
);
Options
&
flags
(
Flags
<
Tcp
::
Options
>
flags
);
Options
&
backlog
(
int
val
);
private:
int
threads_
;
Flags
<
Tcp
::
Options
>
flags_
;
int
backlog_
;
Options
();
};
Endpoint
();
Endpoint
(
const
Net
::
Address
&
addr
);
template
<
typename
...
Args
>
void
initArgs
(
Args
&&
...
args
)
{
listener
.
init
(
std
::
forward
<
Args
>
(
args
)...);
}
void
init
(
const
Options
&
options
);
void
setHandler
(
const
std
::
shared_ptr
<
Handler
>&
handler
);
void
serve
();
static
Options
options
();
private:
std
::
shared_ptr
<
Handler
>
handler_
;
Net
::
Tcp
::
Listener
listener
;
...
...
src/listener.cc
View file @
0d8215d1
...
...
@@ -257,23 +257,26 @@ Handler::onDisconnection(const std::shared_ptr<Tcp::Peer>& peer) {
Listener
::
Listener
()
:
listen_fd
(
-
1
)
,
backlog_
(
Const
::
MaxBacklog
)
{
}
Listener
::
Listener
(
const
Address
&
address
)
:
addr_
(
address
)
,
listen_fd
(
-
1
)
,
backlog_
(
Const
::
MaxBacklog
)
{
}
void
Listener
::
init
(
size_t
workers
,
Flags
<
Options
>
options
)
Listener
::
init
(
size_t
workers
,
Flags
<
Options
>
options
,
int
backlog
)
{
if
(
workers
>
hardware_concurrency
())
{
// Log::warning() << "More workers than available cores"
}
options_
=
options
;
backlog_
=
backlog
;
if
(
options_
.
hasFlag
(
Options
::
InstallSignalHandler
))
{
if
(
signal
(
SIGINT
,
handle_sigint
)
==
SIG_ERR
)
{
...
...
@@ -354,7 +357,7 @@ Listener::bind(const Address& address) {
continue
;
}
TRY
(
::
listen
(
fd
,
Const
::
MaxBacklog
));
TRY
(
::
listen
(
fd
,
backlog_
));
}
...
...
src/listener.h
View file @
0d8215d1
...
...
@@ -79,7 +79,9 @@ public:
Listener
();
Listener
(
const
Address
&
address
);
void
init
(
size_t
workers
,
Flags
<
Options
>
options
=
Options
::
None
);
void
init
(
size_t
workers
,
Flags
<
Options
>
options
=
Options
::
None
,
int
backlog
=
Const
::
MaxBacklog
);
void
setHandler
(
const
std
::
shared_ptr
<
Handler
>&
handler
);
bool
bind
();
...
...
@@ -96,6 +98,7 @@ public:
private:
Address
addr_
;
int
listen_fd
;
int
backlog_
;
std
::
vector
<
std
::
unique_ptr
<
IoWorker
>>
ioGroup
;
Flags
<
Options
>
options_
;
std
::
shared_ptr
<
Handler
>
handler_
;
...
...
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