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
f8b2d8fc
Commit
f8b2d8fc
authored
Jun 29, 2016
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client is now using the new Reactor class
parent
537f30ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
23 deletions
+29
-23
examples/http_client.cc
examples/http_client.cc
+1
-1
include/client.h
include/client.h
+6
-6
include/timer_pool.h
include/timer_pool.h
+6
-3
src/client/client.cc
src/client/client.cc
+16
-13
No files found.
examples/http_client.cc
View file @
f8b2d8fc
...
...
@@ -11,7 +11,7 @@
using
namespace
Net
;
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
1
)
{
if
(
argc
<
2
)
{
std
::
cerr
<<
"Usage: http_client page [count]"
<<
std
::
endl
;
return
1
;
}
...
...
include/client.h
View file @
f8b2d8fc
...
...
@@ -8,7 +8,7 @@
#include "async.h"
#include "os.h"
#include "http.h"
#include "
io
.h"
#include "
reactor
.h"
#include "timer_pool.h"
#include "view.h"
#include <atomic>
...
...
@@ -159,14 +159,14 @@ private:
size_t
maxConnectionsPerHost
;
};
class
Transport
:
public
I
o
::
Handler
{
class
Transport
:
public
Ai
o
::
Handler
{
public:
PROTOTYPE_OF
(
I
o
::
Handler
,
Transport
)
PROTOTYPE_OF
(
Ai
o
::
Handler
,
Transport
)
typedef
std
::
function
<
void
()
>
OnResponseParsed
;
void
onReady
(
const
I
o
::
FdSet
&
fds
);
void
onReady
(
const
Ai
o
::
FdSet
&
fds
);
void
registerPoller
(
Polling
::
Epoll
&
poller
);
Async
::
Promise
<
void
>
...
...
@@ -328,11 +328,11 @@ public:
void
shutdown
();
private:
Io
::
ServiceGroup
io_
;
std
::
shared_ptr
<
Aio
::
Reactor
>
reactor_
;
ConnectionPool
pool
;
std
::
shared_ptr
<
Transport
>
transport_
;
Aio
::
Reactor
::
Key
transportKey
;
std
::
atomic
<
uint64_t
>
ioIndex
;
...
...
include/timer_pool.h
View file @
f8b2d8fc
...
...
@@ -17,6 +17,7 @@
#include <unistd.h>
#include "os.h"
#include "io.h"
#include "reactor.h"
namespace
Net
{
...
...
@@ -55,11 +56,13 @@ public:
}
void
disarm
();
void
registerIo
(
Io
::
Service
*
io
)
{
void
registerReactor
(
const
Aio
::
Reactor
::
Key
&
key
,
Aio
::
Reactor
*
reactor
)
{
if
(
!
registered
)
{
io
->
registerFd
(
fd
,
Polling
::
NotifyOn
::
Read
);
reactor
->
registerFd
(
key
,
fd
,
Polling
::
NotifyOn
::
Read
);
registered
=
true
;
}
registered
=
true
;
}
private:
...
...
src/client/client.cc
View file @
f8b2d8fc
...
...
@@ -145,7 +145,7 @@ namespace {
}
void
Transport
::
onReady
(
const
I
o
::
FdSet
&
fds
)
{
Transport
::
onReady
(
const
Ai
o
::
FdSet
&
fds
)
{
for
(
const
auto
&
entry
:
fds
)
{
if
(
entry
.
getTag
()
==
connectionsQueue
.
tag
())
{
handleConnectionQueue
();
...
...
@@ -180,7 +180,7 @@ Transport::onReady(const Io::FdSet& fds) {
else
{
conn
.
resolve
();
// We are connected, we can start reading data now
io
()
->
modifyFd
(
conn
.
connection
->
fd
,
NotifyOn
::
Read
);
reactor
()
->
modifyFd
(
key
(),
conn
.
connection
->
fd
,
NotifyOn
::
Read
);
}
}
else
{
throw
std
::
runtime_error
(
"Unknown fd"
);
...
...
@@ -212,7 +212,8 @@ Transport::asyncSendRequest(
const
Buffer
&
buffer
)
{
return
Async
::
Promise
<
ssize_t
>
([
&
](
Async
::
Resolver
&
resolve
,
Async
::
Rejection
&
reject
)
{
if
(
std
::
this_thread
::
get_id
()
!=
io
()
->
thread
())
{
auto
ctx
=
context
();
if
(
std
::
this_thread
::
get_id
()
!=
ctx
.
thread
())
{
RequestEntry
req
(
std
::
move
(
resolve
),
std
::
move
(
reject
),
connection
,
std
::
move
(
timer
),
buffer
.
detach
());
auto
*
e
=
requestsQueue
.
allocEntry
(
std
::
move
(
req
));
requestsQueue
.
push
(
e
);
...
...
@@ -250,7 +251,7 @@ Transport::asyncSendRequestImpl(
if
(
status
==
FirstTry
)
{
throw
std
::
runtime_error
(
"Unimplemented, fix me!"
);
}
io
()
->
modifyFd
(
fd
,
NotifyOn
::
Write
,
Polling
::
Mode
::
Edge
);
reactor
()
->
modifyFd
(
key
(),
fd
,
NotifyOn
::
Write
,
Polling
::
Mode
::
Edge
);
}
else
{
cleanUp
();
...
...
@@ -265,7 +266,7 @@ Transport::asyncSendRequestImpl(
if
(
req
.
timer
)
{
timeouts
.
insert
(
std
::
make_pair
(
req
.
timer
->
fd
,
conn
));
req
.
timer
->
register
Io
(
io
());
req
.
timer
->
register
Reactor
(
key
(),
reactor
());
}
req
.
resolve
(
totalWritten
);
break
;
...
...
@@ -298,7 +299,7 @@ Transport::handleConnectionQueue() {
int
res
=
::
connect
(
conn
->
fd
,
data
.
addr
,
data
.
addr_len
);
if
(
res
==
-
1
)
{
if
(
errno
==
EINPROGRESS
)
{
io
()
->
registerFdOneShot
(
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"
));
...
...
@@ -738,7 +739,8 @@ Client::Options::maxConnectionsPerHost(int val) {
}
Client
::
Client
()
:
ioIndex
(
0
)
:
reactor_
(
Aio
::
Reactor
::
create
())
,
ioIndex
(
0
)
{
}
...
...
@@ -763,13 +765,14 @@ void
Client
::
init
(
const
Client
::
Options
&
options
)
{
pool
.
init
(
options
.
maxConnectionsPerHost_
);
transport_
.
reset
(
new
Transport
);
io_
.
init
(
options
.
threads_
,
transport_
);
io_
.
start
();
reactor_
->
init
(
Aio
::
AsyncContext
(
options
.
threads_
));
transportKey
=
reactor_
->
addHandler
(
transport_
);
reactor_
->
run
();
}
void
Client
::
shutdown
()
{
io_
.
shutdown
();
reactor_
->
shutdown
();
}
RequestBuilder
...
...
@@ -835,10 +838,10 @@ Client::doRequest(
else
{
if
(
!
conn
->
hasTransport
())
{
auto
index
=
ioIndex
.
fetch_add
(
1
)
%
io_
.
size
(
);
auto
service
=
io_
.
service
(
index
);
auto
transports
=
reactor_
->
handlers
(
transportKey
);
auto
index
=
ioIndex
.
fetch_add
(
1
)
%
transports
.
size
(
);
auto
transport
=
std
::
static_pointer_cast
<
Transport
>
(
service
->
handler
());
auto
transport
=
std
::
static_pointer_cast
<
Transport
>
(
transports
[
index
]);
conn
->
associateTransport
(
transport
);
}
...
...
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