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
e744386a
Commit
e744386a
authored
Feb 08, 2020
by
hyperxor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code simplification in Peer class and small fix in Listener
parent
ea1ed4c0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
15 deletions
+23
-15
include/pistache/peer.h
include/pistache/peer.h
+8
-7
src/common/peer.cc
src/common/peer.cc
+11
-5
src/server/listener.cc
src/server/listener.cc
+4
-3
No files found.
include/pistache/peer.h
View file @
e744386a
...
...
@@ -36,14 +36,12 @@ class Peer {
public:
friend
class
Transport
;
Peer
();
explicit
Peer
(
const
Address
&
addr
);
~
Peer
();
static
std
::
shared_ptr
<
Peer
>
Create
(
Fd
fd
,
const
Address
&
addr
);
const
Address
&
address
()
const
;
const
std
::
string
&
hostname
();
void
associateFd
(
Fd
fd
);
Fd
fd
()
const
;
void
associateSSL
(
void
*
ssl
);
...
...
@@ -58,20 +56,23 @@ public:
Async
::
Promise
<
ssize_t
>
send
(
const
RawBuffer
&
buffer
,
int
flags
=
0
);
protected:
Peer
(
Fd
fd
,
const
Address
&
addr
);
private:
void
associateTransport
(
Transport
*
transport
);
Transport
*
transport
()
const
;
Transport
*
transport_
;
Transport
*
transport_
=
nullptr
;
Fd
fd_
=
-
1
;
Address
addr
;
Fd
fd_
;
std
::
string
hostname_
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
Pistache
::
Http
::
Private
::
ParserBase
>>
data_
;
void
*
ssl_
;
void
*
ssl_
=
nullptr
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Peer
&
peer
);
...
...
src/common/peer.cc
View file @
e744386a
...
...
@@ -18,10 +18,14 @@
namespace
Pistache
{
namespace
Tcp
{
Peer
::
Peer
()
:
transport_
(
nullptr
),
fd_
(
-
1
),
ssl_
(
NULL
)
{}
namespace
{
struct
ConcretePeer
:
Peer
{
ConcretePeer
()
=
default
;
ConcretePeer
(
Fd
fd
,
const
Address
&
addr
)
:
Peer
(
fd
,
addr
)
{}
};
}
// namespace
Peer
::
Peer
(
const
Address
&
addr
)
:
transport_
(
nullptr
),
addr
(
addr
),
fd_
(
-
1
),
ssl_
(
NULL
)
{}
Peer
::
Peer
(
Fd
fd
,
const
Address
&
addr
)
:
fd_
(
fd
),
addr
(
addr
)
{}
Peer
::~
Peer
()
{
#ifdef PISTACHE_USE_SSL
...
...
@@ -30,6 +34,10 @@ Peer::~Peer() {
#endif
/* PISTACHE_USE_SSL */
}
std
::
shared_ptr
<
Peer
>
Peer
::
Create
(
Fd
fd
,
const
Address
&
addr
)
{
return
std
::
make_shared
<
ConcretePeer
>
(
fd
,
addr
);
}
const
Address
&
Peer
::
address
()
const
{
return
addr
;
}
const
std
::
string
&
Peer
::
hostname
()
{
...
...
@@ -52,8 +60,6 @@ const std::string &Peer::hostname() {
return
hostname_
;
}
void
Peer
::
associateFd
(
int
fd
)
{
fd_
=
fd
;
}
#ifdef PISTACHE_USE_SSL
void
Peer
::
associateSSL
(
void
*
ssl
)
{
ssl_
=
ssl
;
}
...
...
src/server/listener.cc
View file @
e744386a
...
...
@@ -316,8 +316,10 @@ void Listener::handleNewConnection() {
if
(
this
->
useSSL_
)
{
ssl
=
SSL_new
((
SSL_CTX
*
)
this
->
ssl_ctx_
);
if
(
ssl
==
NULL
)
if
(
ssl
==
NULL
)
{
close
(
client_fd
);
throw
std
::
runtime_error
(
"Cannot create SSL connection"
);
}
SSL_set_fd
(
ssl
,
client_fd
);
SSL_set_accept_state
(
ssl
);
...
...
@@ -334,8 +336,7 @@ void Listener::handleNewConnection() {
make_non_blocking
(
client_fd
);
auto
peer
=
std
::
make_shared
<
Peer
>
(
Address
::
fromUnix
((
struct
sockaddr
*
)
&
peer_addr
));
peer
->
associateFd
(
client_fd
);
Peer
::
Create
(
client_fd
,
Address
::
fromUnix
((
struct
sockaddr
*
)
&
peer_addr
));
#ifdef PISTACHE_USE_SSL
if
(
this
->
useSSL_
)
...
...
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