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
c9ddf189
Unverified
Commit
c9ddf189
authored
Oct 14, 2018
by
Dennis Jenkins
Committed by
GitHub
Oct 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #321 from knowledge4igor/code_improvements_5
Several code improvements
parents
8e612353
0533ed57
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
39 deletions
+51
-39
include/pistache/client.h
include/pistache/client.h
+2
-2
include/pistache/reactor.h
include/pistache/reactor.h
+17
-14
include/pistache/transport.h
include/pistache/transport.h
+5
-2
src/common/reactor.cc
src/common/reactor.cc
+27
-21
No files found.
include/pistache/client.h
View file @
c9ddf189
...
...
@@ -170,8 +170,8 @@ public:
typedef
std
::
function
<
void
()
>
OnResponseParsed
;
void
onReady
(
const
Aio
::
FdSet
&
fds
);
void
registerPoller
(
Polling
::
Epoll
&
poller
);
void
onReady
(
const
Aio
::
FdSet
&
fds
)
override
;
void
registerPoller
(
Polling
::
Epoll
&
poller
)
override
;
Async
::
Promise
<
void
>
asyncConnect
(
const
std
::
shared_ptr
<
Connection
>&
connection
,
const
struct
sockaddr
*
address
,
socklen_t
addr_len
);
...
...
include/pistache/reactor.h
View file @
c9ddf189
...
...
@@ -10,20 +10,17 @@
#pragma once
#include <thread>
#include <mutex>
#include <atomic>
#include <memory>
#include <unordered_map>
#include <sys/time.h>
#include <sys/resource.h>
#include <pistache/flags.h>
#include <pistache/os.h>
#include <pistache/net.h>
#include <pistache/prototype.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <thread>
#include <memory>
#include <vector>
namespace
Pistache
{
namespace
Aio
{
...
...
@@ -58,8 +55,8 @@ public:
Polling
::
Tag
getTag
()
const
{
return
this
->
tag
;
}
};
typedef
std
::
vector
<
Entry
>::
iterator
iterator
;
typedef
std
::
vector
<
Entry
>::
const_iterator
const_iterator
;
using
iterator
=
std
::
vector
<
Entry
>::
iterator
;
using
const_iterator
=
std
::
vector
<
Entry
>::
const_iterator
;
size_t
size
()
const
{
return
events_
.
size
();
...
...
@@ -171,7 +168,7 @@ public:
class
SyncContext
:
public
ExecutionContext
{
public:
Reactor
::
Impl
*
makeImpl
(
Reactor
*
reactor
)
const
;
Reactor
::
Impl
*
makeImpl
(
Reactor
*
reactor
)
const
override
;
};
class
AsyncContext
:
public
ExecutionContext
{
...
...
@@ -180,7 +177,7 @@ public:
:
threads_
(
threads
)
{
}
Reactor
::
Impl
*
makeImpl
(
Reactor
*
reactor
)
const
;
Reactor
::
Impl
*
makeImpl
(
Reactor
*
reactor
)
const
override
;
static
AsyncContext
singleThreaded
();
...
...
@@ -194,6 +191,12 @@ public:
friend
class
SyncImpl
;
friend
class
AsyncImpl
;
Handler
()
:
reactor_
(
nullptr
)
,
context_
()
,
key_
()
{
}
struct
Context
{
friend
class
SyncImpl
;
...
...
@@ -204,7 +207,7 @@ public:
};
virtual
void
onReady
(
const
FdSet
&
fds
)
=
0
;
virtual
void
registerPoller
(
Polling
::
Epoll
&
poller
)
{
UNUSED
(
poller
)
}
virtual
void
registerPoller
(
Polling
::
Epoll
&
/*poller*/
)
{
}
Reactor
*
reactor
()
const
{
return
reactor_
;
...
...
include/pistache/transport.h
View file @
c9ddf189
...
...
@@ -12,7 +12,10 @@
#include <pistache/async.h>
#include <pistache/stream.h>
#include <chrono>
#include <deque>
#include <memory>
#include <unordered_map>
namespace
Pistache
{
namespace
Tcp
{
...
...
@@ -26,10 +29,10 @@ public:
void
init
(
const
std
::
shared_ptr
<
Tcp
::
Handler
>&
handler
);
void
registerPoller
(
Polling
::
Epoll
&
poller
);
void
registerPoller
(
Polling
::
Epoll
&
poller
)
override
;
void
handleNewPeer
(
const
std
::
shared_ptr
<
Peer
>&
peer
);
void
onReady
(
const
Aio
::
FdSet
&
fds
);
void
onReady
(
const
Aio
::
FdSet
&
fds
)
override
;
template
<
typename
Buf
>
Async
::
Promise
<
ssize_t
>
asyncWrite
(
Fd
fd
,
const
Buf
&
buffer
,
int
flags
=
0
)
{
...
...
src/common/reactor.cc
View file @
c9ddf189
...
...
@@ -5,7 +5,13 @@
*/
#include <pistache/reactor.h>
#include <array>
#include <atomic>
#include <memory>
#include <mutex>
#include <unordered_map>
#include <vector>
namespace
Pistache
{
namespace
Aio
{
...
...
@@ -69,7 +75,7 @@ public:
}
Reactor
::
Key
addHandler
(
const
std
::
shared_ptr
<
Handler
>&
handler
,
bool
setKey
=
true
)
{
const
std
::
shared_ptr
<
Handler
>&
handler
,
bool
setKey
=
true
)
override
{
handler
->
registerPoller
(
poller
);
...
...
@@ -85,7 +91,7 @@ public:
return
handlers_
[
key
.
data
()];
}
std
::
vector
<
std
::
shared_ptr
<
Handler
>>
handlers
(
const
Reactor
::
Key
&
key
)
const
{
std
::
vector
<
std
::
shared_ptr
<
Handler
>>
handlers
(
const
Reactor
::
Key
&
key
)
const
override
{
std
::
vector
<
std
::
shared_ptr
<
Handler
>>
res
;
res
.
push_back
(
handler
(
key
));
...
...
@@ -97,7 +103,7 @@ public:
Fd
fd
,
Polling
::
NotifyOn
interest
,
Polling
::
Tag
tag
,
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
{
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
override
{
auto
pollTag
=
encodeTag
(
key
,
tag
);
poller
.
addFd
(
fd
,
interest
,
pollTag
,
mode
);
...
...
@@ -108,7 +114,7 @@ public:
Fd
fd
,
Polling
::
NotifyOn
interest
,
Polling
::
Tag
tag
,
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
{
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
override
{
auto
pollTag
=
encodeTag
(
key
,
tag
);
poller
.
addFdOneShot
(
fd
,
interest
,
pollTag
,
mode
);
...
...
@@ -119,13 +125,13 @@ public:
Fd
fd
,
Polling
::
NotifyOn
interest
,
Polling
::
Tag
tag
,
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
{
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
override
{
auto
pollTag
=
encodeTag
(
key
,
tag
);
poller
.
rearmFd
(
fd
,
interest
,
pollTag
,
mode
);
}
void
runOnce
()
{
void
runOnce
()
override
{
if
(
handlers_
.
empty
())
throw
std
::
runtime_error
(
"You need to set at least one handler"
);
...
...
@@ -147,7 +153,7 @@ public:
}
}
void
run
()
{
void
run
()
override
{
handlers_
.
forEachHandler
([](
const
std
::
shared_ptr
<
Handler
>
handler
)
{
handler
->
context_
.
tid
=
std
::
this_thread
::
get_id
();
});
...
...
@@ -156,7 +162,7 @@ public:
runOnce
();
}
void
shutdown
()
{
void
shutdown
()
override
{
shutdown_
.
store
(
true
);
shutdownFd
.
notify
();
}
...
...
@@ -341,7 +347,7 @@ public:
}
Reactor
::
Key
addHandler
(
const
std
::
shared_ptr
<
Handler
>&
handler
,
bool
)
{
const
std
::
shared_ptr
<
Handler
>&
handler
,
bool
)
override
{
Reactor
::
Key
keys
[
SyncImpl
::
MaxHandlers
()];
...
...
@@ -361,7 +367,7 @@ public:
return
Reactor
::
Key
(
data
);
}
std
::
vector
<
std
::
shared_ptr
<
Handler
>>
handlers
(
const
Reactor
::
Key
&
key
)
const
{
std
::
vector
<
std
::
shared_ptr
<
Handler
>>
handlers
(
const
Reactor
::
Key
&
key
)
const
override
{
uint32_t
idx
;
uint32_t
marker
;
...
...
@@ -385,7 +391,7 @@ public:
Fd
fd
,
Polling
::
NotifyOn
interest
,
Polling
::
Tag
tag
,
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
{
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
override
{
dispatchCall
(
key
,
&
SyncImpl
::
registerFd
,
fd
,
interest
,
tag
,
mode
);
}
...
...
@@ -394,7 +400,7 @@ public:
Fd
fd
,
Polling
::
NotifyOn
interest
,
Polling
::
Tag
tag
,
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
{
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
override
{
dispatchCall
(
key
,
&
SyncImpl
::
registerFdOneShot
,
fd
,
interest
,
tag
,
mode
);
}
...
...
@@ -403,19 +409,19 @@ public:
Fd
fd
,
Polling
::
NotifyOn
interest
,
Polling
::
Tag
tag
,
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
{
Polling
::
Mode
mode
=
Polling
::
Mode
::
Level
)
override
{
dispatchCall
(
key
,
&
SyncImpl
::
modifyFd
,
fd
,
interest
,
tag
,
mode
);
}
void
runOnce
()
{
void
runOnce
()
override
{
}
void
run
()
{
void
run
()
override
{
for
(
auto
&
wrk
:
workers_
)
wrk
->
run
();
}
void
shutdown
()
{
void
shutdown
()
override
{
for
(
auto
&
wrk
:
workers_
)
wrk
->
shutdown
();
}
...
...
@@ -455,21 +461,21 @@ private:
}
~
Worker
()
{
if
(
thread
)
thread
->
join
();
if
(
thread
.
joinable
()
)
thread
.
join
();
}
void
run
()
{
thread
.
reset
(
new
std
::
thread
([
=
]()
{
thread
=
std
::
thread
([
=
]()
{
sync
->
run
();
})
)
;
});
}
void
shutdown
()
{
sync
->
shutdown
();
}
std
::
unique_ptr
<
std
::
thread
>
thread
;
std
::
thread
thread
;
std
::
unique_ptr
<
SyncImpl
>
sync
;
};
...
...
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