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
551cbb47
Unverified
Commit
551cbb47
authored
Nov 17, 2020
by
Dennis Jenkins
Committed by
GitHub
Nov 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Adding a Peer ID to identify connections (#836)" (#837)
This reverts commit
eb9102dd
.
parent
eb9102dd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
4 additions
and
75 deletions
+4
-75
include/pistache/http.h
include/pistache/http.h
+1
-6
include/pistache/peer.h
include/pistache/peer.h
+0
-2
src/common/http.cc
src/common/http.cc
+2
-0
src/common/peer.cc
src/common/peer.cc
+1
-4
tests/http_server_test.cc
tests/http_server_test.cc
+0
-63
No files found.
include/pistache/http.h
View file @
551cbb47
...
...
@@ -415,12 +415,6 @@ public:
ResponseWriter
clone
()
const
;
std
::
shared_ptr
<
Tcp
::
Peer
>
getPeer
()
const
{
if
(
auto
sp
=
peer_
.
lock
())
return
sp
;
return
nullptr
;
}
private:
ResponseWriter
(
Tcp
::
Transport
*
transport
,
Request
request
,
Handler
*
handler
,
std
::
weak_ptr
<
Tcp
::
Peer
>
peer
);
...
...
@@ -587,6 +581,7 @@ public:
private:
void
onConnection
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
peer
)
override
;
void
onDisconnection
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
peer
)
override
;
void
onInput
(
const
char
*
buffer
,
size_t
len
,
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
peer
)
override
;
RequestParser
&
getParser
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
peer
)
const
;
...
...
include/pistache/peer.h
View file @
551cbb47
...
...
@@ -48,7 +48,6 @@ public:
std
::
shared_ptr
<
Http
::
Parser
>
tryGetData
(
std
::
string
name
)
const
;
Async
::
Promise
<
ssize_t
>
send
(
const
RawBuffer
&
buffer
,
int
flags
=
0
);
size_t
getID
()
const
;
protected:
Peer
(
Fd
fd
,
const
Address
&
addr
,
void
*
ssl
);
...
...
@@ -65,7 +64,6 @@ private:
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
Http
::
Parser
>>
data_
;
void
*
ssl_
=
nullptr
;
const
size_t
id_
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Peer
&
peer
);
...
...
src/common/http.cc
View file @
551cbb47
...
...
@@ -964,6 +964,8 @@ void Handler::onConnection(const std::shared_ptr<Tcp::Peer> &peer) {
peer
->
putData
(
ParserData
,
std
::
make_shared
<
RequestParser
>
(
maxRequestSize_
));
}
void
Handler
::
onDisconnection
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
/*peer*/
)
{}
void
Handler
::
onTimeout
(
const
Request
&
/*request*/
,
ResponseWriter
/*response*/
)
{}
...
...
src/common/peer.cc
View file @
551cbb47
...
...
@@ -18,8 +18,6 @@
namespace
Pistache
{
namespace
Tcp
{
std
::
atomic
<
size_t
>
idCounter
{
0
};
namespace
{
struct
ConcretePeer
:
Peer
{
ConcretePeer
()
=
default
;
...
...
@@ -28,7 +26,7 @@ struct ConcretePeer : Peer {
}
// namespace
Peer
::
Peer
(
Fd
fd
,
const
Address
&
addr
,
void
*
ssl
)
:
fd_
(
fd
),
addr
(
addr
),
ssl_
(
ssl
)
,
id_
(
idCounter
++
)
{}
:
fd_
(
fd
),
addr
(
addr
),
ssl_
(
ssl
)
{}
Peer
::~
Peer
()
{
#ifdef PISTACHE_USE_SSL
...
...
@@ -68,7 +66,6 @@ const std::string &Peer::hostname() {
}
void
*
Peer
::
ssl
()
const
{
return
ssl_
;
}
size_t
Peer
::
getID
()
const
{
return
id_
;
}
int
Peer
::
fd
()
const
{
if
(
fd_
==
-
1
)
{
...
...
tests/http_server_test.cc
View file @
551cbb47
...
...
@@ -3,7 +3,6 @@
#include <pistache/common.h>
#include <pistache/endpoint.h>
#include <pistache/http.h>
#include <pistache/peer.h>
#include "gtest/gtest.h"
...
...
@@ -129,7 +128,6 @@ int clientLogicFunc(int response_size, const std::string &server_page,
return
resolver_counter
;
}
/*
TEST
(
http_server_test
,
client_disconnection_on_timeout_from_single_threaded_server
)
{
const
Pistache
::
Address
address
(
"localhost"
,
Pistache
::
Port
(
0
));
...
...
@@ -416,64 +414,3 @@ TEST(http_server_test, response_size_captured) {
ASSERT_LT
(
rsize
,
300u
);
ASSERT_EQ
(
rcode
,
Http
::
Code
::
Ok
);
}
*/
struct
ClientCountingHandler
:
public
Http
::
Handler
{
HTTP_PROTOTYPE
(
ClientCountingHandler
)
ClientCountingHandler
(
std
::
atomic
<
size_t
>
&
counter
)
:
counter_
(
counter
)
{
std
::
cout
<<
"INITING"
<<
std
::
endl
;}
void
onRequest
(
const
Http
::
Request
&
request
,
Http
::
ResponseWriter
writer
)
override
{
auto
peer
=
writer
.
getPeer
();
if
(
peer
)
{
activeConnections
.
insert
(
peer
->
getID
());
}
else
{
return
;
}
std
::
string
requestAddress
=
request
.
address
().
host
();
writer
.
send
(
Http
::
Code
::
Ok
,
requestAddress
);
std
::
cout
<<
"[server] Sent: "
<<
requestAddress
<<
std
::
endl
;
}
void
onDisconnection
(
const
std
::
shared_ptr
<
Tcp
::
Peer
>
&
peer
)
override
{
++
counter_
;
std
::
cout
<<
"[server] Disconnect from peer ID "
<<
peer
->
getId
()
<<
" connecting from "
<<
peer
->
address
().
host
()
<<
"; counter now at "
<<
counter_
<<
std
::
endl
;
activeConnections
.
erase
(
peer
->
getID
());
}
size_t
getClientsServed
()
const
{
return
counter_
;
}
std
::
unordered_set
<
size_t
>
activeConnections
;
std
::
atomic
<
size_t
>
&
counter_
;
};
TEST
(
http_server_test
,
client_multiple_requests_disconnects_handled
)
{
const
Pistache
::
Address
address
(
"localhost"
,
Pistache
::
Port
(
0
));
Http
::
Endpoint
server
(
address
);
auto
flags
=
Tcp
::
Options
::
ReuseAddr
;
auto
server_opts
=
Http
::
Endpoint
::
options
().
flags
(
flags
);
server
.
init
(
server_opts
);
std
::
cout
<<
"Trying to run server...
\n
"
;
std
::
atomic
<
size_t
>
counter
{
0
};
auto
handler
=
Http
::
make_handler
<
ClientCountingHandler
>
(
counter
);
server
.
setHandler
(
handler
);
server
.
serveThreaded
();
const
std
::
string
server_address
=
"localhost:"
+
server
.
getPort
().
toString
();
std
::
cout
<<
"Server address: "
<<
server_address
<<
"
\n
"
;
const
size_t
CLIENT_REQUEST_SIZE
=
3
;
clientLogicFunc
(
CLIENT_REQUEST_SIZE
,
server_address
,
1
,
6
);
server
.
shutdown
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
ASSERT_EQ
(
counter
,
CLIENT_REQUEST_SIZE
);
ASSERT_EQ
(
handler
->
activeConnections
.
size
(),
0UL
);
}
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