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
93713f9e
Commit
93713f9e
authored
Feb 05, 2019
by
knowledge4igor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tiny code improvements
parent
153d9f0c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
33 deletions
+41
-33
include/pistache/client.h
include/pistache/client.h
+3
-4
include/pistache/peer.h
include/pistache/peer.h
+2
-2
src/client/client.cc
src/client/client.cc
+32
-23
src/common/peer.cc
src/common/peer.cc
+4
-4
No files found.
include/pistache/client.h
View file @
93713f9e
...
...
@@ -30,8 +30,6 @@ namespace Http {
class
ConnectionPool
;
class
Transport
;
std
::
pair
<
StringView
,
StringView
>
splitUrl
(
const
std
::
string
&
url
);
struct
Connection
:
public
std
::
enable_shared_from_this
<
Connection
>
{
friend
class
ConnectionPool
;
...
...
@@ -96,8 +94,7 @@ struct Connection : public std::enable_shared_from_this<Connection> {
Async
::
Rejection
reject
,
OnDone
onDone
);
Fd
fd
;
Fd
fd
()
const
;
void
handleResponsePacket
(
const
char
*
buffer
,
size_t
totalBytes
);
void
handleError
(
const
char
*
error
);
void
handleTimeout
();
...
...
@@ -124,6 +121,8 @@ private:
OnDone
onDone
;
};
Fd
fd_
;
struct
sockaddr_in
saddr
;
std
::
unique_ptr
<
RequestEntry
>
requestEntry
;
std
::
atomic
<
uint32_t
>
state_
;
...
...
include/pistache/peer.h
View file @
93713f9e
...
...
@@ -40,8 +40,8 @@ public:
Peer
(
const
Address
&
addr
);
~
Peer
()
{}
Address
address
()
const
;
std
::
string
hostname
()
const
;
const
Address
&
address
()
const
;
const
std
::
string
&
hostname
()
const
;
void
associateFd
(
Fd
fd
);
Fd
fd
()
const
;
...
...
src/client/client.cc
View file @
93713f9e
...
...
@@ -26,22 +26,25 @@ namespace Http {
static
constexpr
const
char
*
UA
=
"pistache/0.1"
;
std
::
pair
<
StringView
,
StringView
>
splitUrl
(
const
std
::
string
&
url
)
{
RawStreamBuf
<
char
>
buf
(
const_cast
<
char
*>
(
&
url
[
0
]),
url
.
size
());
StreamCursor
cursor
(
&
buf
);
namespace
{
std
::
pair
<
StringView
,
StringView
>
splitUrl
(
const
std
::
string
&
url
)
{
RawStreamBuf
<
char
>
buf
(
const_cast
<
char
*>
(
&
url
[
0
]),
url
.
size
());
StreamCursor
cursor
(
&
buf
);
match_string
(
"http://"
,
std
::
strlen
(
"http://"
),
cursor
);
match_string
(
"www"
,
std
::
strlen
(
"www"
),
cursor
);
match_literal
(
'.'
,
cursor
);
match_string
(
"http://"
,
std
::
strlen
(
"http://"
),
cursor
);
match_string
(
"www"
,
std
::
strlen
(
"www"
),
cursor
);
match_literal
(
'.'
,
cursor
);
StreamCursor
::
Token
hostToken
(
cursor
);
match_until
({
'?'
,
'/'
},
cursor
);
StreamCursor
::
Token
hostToken
(
cursor
);
match_until
({
'?'
,
'/'
},
cursor
);
StringView
host
(
hostToken
.
rawText
(),
hostToken
.
size
());
StringView
page
(
cursor
.
offset
(),
buf
.
endptr
());
StringView
host
(
hostToken
.
rawText
(),
hostToken
.
size
());
StringView
page
(
cursor
.
offset
(),
buf
.
endptr
());
return
std
::
make_pair
(
std
::
move
(
host
),
std
::
move
(
page
));
return
std
::
make_pair
(
std
::
move
(
host
),
std
::
move
(
page
));
}
}
struct
ExceptionPrinter
{
...
...
@@ -174,7 +177,7 @@ Transport::onReady(const Aio::FdSet& fds) {
// We are connected, we can start reading data now
auto
connection
=
connIt
->
second
.
connection
.
lock
();
if
(
connection
)
{
reactor
()
->
modifyFd
(
key
(),
connection
->
fd
,
NotifyOn
::
Read
);
reactor
()
->
modifyFd
(
key
(),
connection
->
fd
()
,
NotifyOn
::
Read
);
}
else
{
throw
std
::
runtime_error
(
"Connection error"
);
}
...
...
@@ -228,7 +231,7 @@ Transport::asyncSendRequestImpl(
if
(
!
conn
)
throw
std
::
runtime_error
(
"Send request error"
);
auto
fd
=
conn
->
fd
;
auto
fd
=
conn
->
fd
()
;
ssize_t
totalWritten
=
0
;
for
(;;)
{
...
...
@@ -284,17 +287,17 @@ Transport::handleConnectionQueue() {
if
(
!
conn
)
{
throw
std
::
runtime_error
(
"Connection error"
);
}
int
res
=
::
connect
(
conn
->
fd
,
data
->
getAddr
(),
data
->
addr_len
);
int
res
=
::
connect
(
conn
->
fd
()
,
data
->
getAddr
(),
data
->
addr_len
);
if
(
res
==
-
1
)
{
if
(
errno
==
EINPROGRESS
)
{
reactor
()
->
registerFdOneShot
(
key
(),
conn
->
fd
,
NotifyOn
::
Write
|
NotifyOn
::
Hangup
|
NotifyOn
::
Shutdown
);
reactor
()
->
registerFdOneShot
(
key
(),
conn
->
fd
()
,
NotifyOn
::
Write
|
NotifyOn
::
Hangup
|
NotifyOn
::
Shutdown
);
}
else
{
data
->
reject
(
Error
::
system
(
"Failed to connect"
));
continue
;
}
}
connections
.
insert
(
std
::
make_pair
(
conn
->
fd
,
std
::
move
(
*
data
)));
connections
.
insert
(
std
::
make_pair
(
conn
->
fd
()
,
std
::
move
(
*
data
)));
}
}
...
...
@@ -305,7 +308,7 @@ Transport::handleIncoming(std::shared_ptr<Connection> connection) {
ssize_t
totalBytes
=
0
;
for
(;;)
{
ssize_t
bytes
=
recv
(
connection
->
fd
,
buffer
+
totalBytes
,
Const
::
MaxBuffer
-
totalBytes
,
0
);
ssize_t
bytes
=
recv
(
connection
->
fd
()
,
buffer
+
totalBytes
,
Const
::
MaxBuffer
-
totalBytes
,
0
);
if
(
bytes
==
-
1
)
{
if
(
errno
==
EAGAIN
||
errno
==
EWOULDBLOCK
)
{
if
(
totalBytes
>
0
)
{
...
...
@@ -322,7 +325,7 @@ Transport::handleIncoming(std::shared_ptr<Connection> connection) {
}
else
{
connection
->
handleError
(
"Remote closed connection"
);
}
connections
.
erase
(
connection
->
fd
);
connections
.
erase
(
connection
->
fd
()
);
connection
->
close
();
break
;
}
...
...
@@ -348,7 +351,7 @@ Transport::handleTimeout(const std::shared_ptr<Connection>& connection) {
}
Connection
::
Connection
()
:
fd
(
-
1
)
:
fd
_
(
-
1
)
,
requestEntry
(
nullptr
)
{
state_
.
store
(
static_cast
<
uint32_t
>
(
State
::
Idle
));
...
...
@@ -382,7 +385,7 @@ Connection::connect(const Address& addr)
make_non_blocking
(
sfd
);
connectionState_
.
store
(
Connecting
);
fd
=
sfd
;
fd
_
=
sfd
;
transport_
->
asyncConnect
(
shared_from_this
(),
addr
->
ai_addr
,
addr
->
ai_addrlen
)
.
then
([
=
]()
{
...
...
@@ -402,7 +405,7 @@ Connection::connect(const Address& addr)
std
::
string
Connection
::
dump
()
const
{
std
::
ostringstream
oss
;
oss
<<
"Connection(fd = "
<<
fd
<<
", src_port = "
;
oss
<<
"Connection(fd = "
<<
fd
_
<<
", src_port = "
;
oss
<<
ntohs
(
saddr
.
sin_port
)
<<
")"
;
return
oss
.
str
();
}
...
...
@@ -420,7 +423,7 @@ Connection::isConnected() const {
void
Connection
::
close
()
{
connectionState_
.
store
(
NotConnected
);
::
close
(
fd
);
::
close
(
fd
_
);
}
void
...
...
@@ -436,6 +439,12 @@ Connection::hasTransport() const {
return
transport_
!=
nullptr
;
}
Fd
Connection
::
fd
()
const
{
assert
(
fd_
!=
-
1
);
return
fd_
;
}
void
Connection
::
handleResponsePacket
(
const
char
*
buffer
,
size_t
totalBytes
)
{
...
...
src/common/peer.cc
View file @
93713f9e
...
...
@@ -30,13 +30,13 @@ Peer::Peer(const Address& addr)
,
ssl_
(
NULL
)
{
}
Address
Peer
::
address
()
const
{
const
Address
&
Peer
::
address
()
const
{
return
addr
;
}
string
Peer
::
hostname
()
const
{
const
std
::
string
&
Peer
::
hostname
()
const
{
return
hostname_
;
}
...
...
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