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
61af27cb
Unverified
Commit
61af27cb
authored
Oct 06, 2018
by
Dennis Jenkins
Committed by
GitHub
Oct 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #311 from knowledge4igor/code_improvements_4
Several code improvements
parents
c5fd213e
e8859f80
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
33 deletions
+49
-33
include/pistache/cookie.h
include/pistache/cookie.h
+2
-2
include/pistache/os.h
include/pistache/os.h
+7
-5
src/common/http.cc
src/common/http.cc
+2
-2
src/common/os.cc
src/common/os.cc
+5
-5
src/server/listener.cc
src/server/listener.cc
+12
-18
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
tests/http_uri_test.cc
tests/http_uri_test.cc
+19
-0
tests/rest_server_test.cc
tests/rest_server_test.cc
+1
-1
No files found.
include/pistache/cookie.h
View file @
61af27cb
...
...
@@ -41,7 +41,7 @@ struct Cookie {
class
CookieJar
{
public:
typedef
std
::
unordered_map
<
std
::
string
,
Cookie
>
Storage
;
using
Storage
=
std
::
unordered_map
<
std
::
string
,
Cookie
>
;
struct
iterator
:
std
::
iterator
<
std
::
bidirectional_iterator_tag
,
Cookie
>
{
iterator
(
const
Storage
::
const_iterator
&
_iterator
)
...
...
@@ -59,7 +59,7 @@ public:
iterator
operator
++
(
int
)
{
iterator
ret
(
it_
);
it_
++
;
++
it_
;
return
ret
;
}
...
...
include/pistache/os.h
View file @
61af27cb
...
...
@@ -18,7 +18,7 @@
namespace
Pistache
{
typedef
int
Fd
;
using
Fd
=
int
;
uint
hardware_concurrency
();
bool
make_non_blocking
(
int
fd
);
...
...
@@ -87,8 +87,10 @@ inline constexpr bool operator==(Tag lhs, Tag rhs) {
}
struct
Event
{
explicit
Event
(
Tag
_tag
)
:
tag
(
_tag
)
explicit
Event
(
Tag
_tag
)
:
flags
()
,
fd
(
-
1
)
,
tag
(
_tag
)
{
}
Flags
<
NotifyOn
>
flags
;
...
...
@@ -111,8 +113,8 @@ public:
std
::
chrono
::
milliseconds
timeout
=
std
::
chrono
::
milliseconds
(
0
))
const
;
private:
int
toEpollEvents
(
Flags
<
NotifyOn
>
interest
)
const
;
Flags
<
NotifyOn
>
toNotifyOn
(
int
events
)
const
;
static
int
toEpollEvents
(
const
Flags
<
NotifyOn
>&
interest
)
;
static
Flags
<
NotifyOn
>
toNotifyOn
(
int
events
)
;
int
epoll_fd
;
};
...
...
src/common/http.cc
View file @
61af27cb
...
...
@@ -505,9 +505,9 @@ namespace Uri {
for
(
const
auto
&
e
:
params
)
{
query_url
+=
"&"
+
e
.
first
+
"="
+
e
.
second
;
}
if
(
not
query_url
.
empty
())
{
if
(
!
query_url
.
empty
())
{
query_url
[
0
]
=
'?'
;
// replace first `&` with `?`
}
else
{
/* query_url is empty */
}
}
return
query_url
;
}
...
...
src/common/os.cc
View file @
61af27cb
...
...
@@ -25,13 +25,13 @@ uint hardware_concurrency() {
}
bool
make_non_blocking
(
int
s
fd
)
bool
make_non_blocking
(
int
fd
)
{
int
flags
=
fcntl
(
s
fd
,
F_GETFL
,
0
);
int
flags
=
fcntl
(
fd
,
F_GETFL
,
0
);
if
(
flags
==
-
1
)
return
false
;
flags
|=
O_NONBLOCK
;
int
ret
=
fcntl
(
s
fd
,
F_SETFL
,
flags
);
int
ret
=
fcntl
(
fd
,
F_SETFL
,
flags
);
if
(
ret
==
-
1
)
return
false
;
return
true
;
...
...
@@ -206,7 +206,7 @@ namespace Polling {
}
int
Epoll
::
toEpollEvents
(
Flags
<
NotifyOn
>
interest
)
const
{
Epoll
::
toEpollEvents
(
const
Flags
<
NotifyOn
>&
interest
)
{
int
events
=
0
;
if
(
interest
.
hasFlag
(
NotifyOn
::
Read
))
...
...
@@ -222,7 +222,7 @@ namespace Polling {
}
Flags
<
NotifyOn
>
Epoll
::
toNotifyOn
(
int
events
)
const
{
Epoll
::
toNotifyOn
(
int
events
)
{
Flags
<
NotifyOn
>
flags
;
if
(
events
&
EPOLLIN
)
...
...
src/server/listener.cc
View file @
61af27cb
...
...
@@ -3,30 +3,27 @@
*/
#include <iostream>
#include <cassert>
#include <cstring>
#include <pistache/listener.h>
#include <pistache/peer.h>
#include <pistache/common.h>
#include <pistache/os.h>
#include <pistache/transport.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/epoll.h>
#include <pthread.h>
#include <signal.h>
#include <sys/timerfd.h>
#include <sys/sendfile.h>
#include <cerrno>
#include <pistache/listener.h>
#include <pistache/peer.h>
#include <pistache/common.h>
#include <pistache/os.h>
#include <pistache/transport.h>
#include <chrono>
#include <memory>
#include <vector>
#include <cerrno>
#include <signal.h>
using
namespace
std
;
namespace
Pistache
{
namespace
Tcp
{
...
...
@@ -46,9 +43,6 @@ namespace {
}
}
using
Polling
::
NotifyOn
;
void
setSocketOptions
(
Fd
fd
,
Flags
<
Options
>
options
)
{
if
(
options
.
hasFlag
(
Options
::
ReuseAddr
))
{
int
one
=
1
;
...
...
@@ -324,7 +318,7 @@ Listener::handleNewConnection() {
make_non_blocking
(
client_fd
);
auto
peer
=
make_shared
<
Peer
>
(
Address
::
fromUnix
((
struct
sockaddr
*
)
&
peer_addr
));
auto
peer
=
std
::
make_shared
<
Peer
>
(
Address
::
fromUnix
((
struct
sockaddr
*
)
&
peer_addr
));
peer
->
associateFd
(
client_fd
);
dispatchPeer
(
peer
);
...
...
tests/CMakeLists.txt
View file @
61af27cb
...
...
@@ -16,6 +16,7 @@ pistache_test(router_test)
pistache_test
(
cookie_test
)
pistache_test
(
view_test
)
pistache_test
(
http_parsing_test
)
pistache_test
(
http_uri_test
)
pistache_test
(
http_client_test
)
pistache_test
(
net_test
)
pistache_test
(
listener_test
)
...
...
tests/http_uri_test.cc
0 → 100644
View file @
61af27cb
#include "gtest/gtest.h"
#include <pistache/http.h>
using
namespace
Pistache
;
TEST
(
http_uri_test
,
query_as_string_test
)
{
Http
::
Uri
::
Query
query1
;
ASSERT_TRUE
(
query1
.
as_str
().
empty
());
Http
::
Uri
::
Query
query2
;
query2
.
add
(
"value1"
,
"name1"
);
ASSERT_STREQ
(
query2
.
as_str
().
c_str
(),
"?value1=name1"
);
Http
::
Uri
::
Query
query3
;
query3
.
add
(
"value1"
,
"name1"
);
query3
.
add
(
"value2"
,
"name2"
);
ASSERT_STREQ
(
query3
.
as_str
().
c_str
(),
"?value2=name2&value1=name1"
);
}
\ No newline at end of file
tests/rest_server_test.cc
View file @
61af27cb
...
...
@@ -44,7 +44,7 @@ private:
Routes
::
Get
(
router
,
"/read/function1"
,
Routes
::
bind
(
&
StatsEndpoint
::
doAuth
,
this
));
}
void
doAuth
(
const
Rest
::
Request
&
request
,
Http
::
ResponseWriter
response
)
{
void
doAuth
(
const
Rest
::
Request
&
/*request*/
,
Http
::
ResponseWriter
response
)
{
std
::
thread
worker
([](
Http
::
ResponseWriter
writer
)
{
writer
.
send
(
Http
::
Code
::
Ok
,
"1"
);
},
std
::
move
(
response
));
...
...
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