Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
f00f4645
Unverified
Commit
f00f4645
authored
Apr 20, 2020
by
Luca Boccassi
Committed by
GitHub
Apr 20, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3866 from gummif/gfa/poller-refactoring
Problem: poller item lookup can be simplified
parents
d882e807
0b32fb36
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
55 deletions
+52
-55
socket_poller.cpp
src/socket_poller.cpp
+32
-44
socket_poller.hpp
src/socket_poller.hpp
+20
-11
No files found.
src/socket_poller.cpp
View file @
f00f4645
...
...
@@ -41,6 +41,18 @@ static bool is_thread_safe (const zmq::socket_base_t &socket_)
return
socket_
.
is_thread_safe
();
}
// compare elements to value
template
<
class
It
,
class
T
,
class
Pred
>
static
It
find_if2
(
It
b_
,
It
e_
,
const
T
&
value
,
Pred
pred
)
{
for
(;
b_
!=
e_
;
++
b_
)
{
if
(
pred
(
*
b_
,
value
))
{
break
;
}
}
return
b_
;
}
zmq
::
socket_poller_t
::
socket_poller_t
()
:
_tag
(
0xCAFEBABE
),
_signaler
(
NULL
)
...
...
@@ -101,12 +113,10 @@ int zmq::socket_poller_t::add (socket_base_t *socket_,
void
*
user_data_
,
short
events_
)
{
for
(
items_t
::
iterator
it
=
_items
.
begin
(),
end
=
_items
.
end
();
it
!=
end
;
++
it
)
{
if
(
it
->
socket
==
socket_
)
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
find_if2
(
_items
.
begin
(),
_items
.
end
(),
socket_
,
&
is_socket
)
!=
_items
.
end
())
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
is_thread_safe
(
*
socket_
))
{
...
...
@@ -151,12 +161,10 @@ int zmq::socket_poller_t::add (socket_base_t *socket_,
int
zmq
::
socket_poller_t
::
add_fd
(
fd_t
fd_
,
void
*
user_data_
,
short
events_
)
{
for
(
items_t
::
iterator
it
=
_items
.
begin
(),
end
=
_items
.
end
();
it
!=
end
;
++
it
)
{
if
(
!
it
->
socket
&&
it
->
fd
==
fd_
)
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
find_if2
(
_items
.
begin
(),
_items
.
end
(),
fd_
,
&
is_fd
)
!=
_items
.
end
())
{
errno
=
EINVAL
;
return
-
1
;
}
const
item_t
item
=
{
...
...
@@ -183,15 +191,10 @@ int zmq::socket_poller_t::add_fd (fd_t fd_, void *user_data_, short events_)
int
zmq
::
socket_poller_t
::
modify
(
const
socket_base_t
*
socket_
,
short
events_
)
{
const
items_t
::
iterator
end
=
_items
.
end
();
items_t
::
iterator
it
;
for
(
it
=
_items
.
begin
();
it
!=
end
;
++
it
)
{
if
(
it
->
socket
==
socket_
)
break
;
}
const
items_t
::
iterator
it
=
find_if2
(
_items
.
begin
(),
_items
.
end
(),
socket_
,
&
is_socket
);
if
(
it
==
end
)
{
if
(
it
==
_items
.
end
()
)
{
errno
=
EINVAL
;
return
-
1
;
}
...
...
@@ -205,15 +208,10 @@ int zmq::socket_poller_t::modify (const socket_base_t *socket_, short events_)
int
zmq
::
socket_poller_t
::
modify_fd
(
fd_t
fd_
,
short
events_
)
{
const
items_t
::
iterator
end
=
_items
.
end
();
items_t
::
iterator
it
;
const
items_t
::
iterator
it
=
find_if2
(
_items
.
begin
(),
_items
.
end
(),
fd_
,
&
is_fd
)
;
for
(
it
=
_items
.
begin
();
it
!=
end
;
++
it
)
{
if
(
!
it
->
socket
&&
it
->
fd
==
fd_
)
break
;
}
if
(
it
==
end
)
{
if
(
it
==
_items
.
end
())
{
errno
=
EINVAL
;
return
-
1
;
}
...
...
@@ -227,15 +225,10 @@ int zmq::socket_poller_t::modify_fd (fd_t fd_, short events_)
int
zmq
::
socket_poller_t
::
remove
(
socket_base_t
*
socket_
)
{
const
items_t
::
iterator
end
=
_items
.
end
();
items_t
::
iterator
it
;
for
(
it
=
_items
.
begin
();
it
!=
end
;
++
it
)
{
if
(
it
->
socket
==
socket_
)
break
;
}
const
items_t
::
iterator
it
=
find_if2
(
_items
.
begin
(),
_items
.
end
(),
socket_
,
&
is_socket
);
if
(
it
==
end
)
{
if
(
it
==
_items
.
end
()
)
{
errno
=
EINVAL
;
return
-
1
;
}
...
...
@@ -252,15 +245,10 @@ int zmq::socket_poller_t::remove (socket_base_t *socket_)
int
zmq
::
socket_poller_t
::
remove_fd
(
fd_t
fd_
)
{
const
items_t
::
iterator
end
=
_items
.
end
();
items_t
::
iterator
it
;
for
(
it
=
_items
.
begin
();
it
!=
end
;
++
it
)
{
if
(
!
it
->
socket
&&
it
->
fd
==
fd_
)
break
;
}
const
items_t
::
iterator
it
=
find_if2
(
_items
.
begin
(),
_items
.
end
(),
fd_
,
&
is_fd
);
if
(
it
==
end
)
{
if
(
it
==
_items
.
end
()
)
{
errno
=
EINVAL
;
return
-
1
;
}
...
...
src/socket_poller.hpp
View file @
f00f4645
...
...
@@ -86,6 +86,17 @@ class socket_poller_t
bool
check_tag
()
const
;
private
:
typedef
struct
item_t
{
socket_base_t
*
socket
;
fd_t
fd
;
void
*
user_data
;
short
events
;
#if defined ZMQ_POLL_BASED_ON_POLL
int
pollfd_index
;
#endif
}
item_t
;
static
void
zero_trail_events
(
zmq
::
socket_poller_t
::
event_t
*
events_
,
int
n_events_
,
int
found_
);
...
...
@@ -103,6 +114,15 @@ class socket_poller_t
uint64_t
&
now_
,
uint64_t
&
end_
,
bool
&
first_pass_
);
static
bool
is_socket
(
const
item_t
&
item
,
const
socket_base_t
*
socket_
)
{
return
item
.
socket
==
socket_
;
}
static
bool
is_fd
(
const
item_t
&
item
,
fd_t
fd_
)
{
return
!
item
.
socket
&&
item
.
fd
==
fd_
;
}
int
rebuild
();
// Used to check whether the object is a socket_poller.
...
...
@@ -111,17 +131,6 @@ class socket_poller_t
// Signaler used for thread safe sockets polling
signaler_t
*
_signaler
;
typedef
struct
item_t
{
socket_base_t
*
socket
;
fd_t
fd
;
void
*
user_data
;
short
events
;
#if defined ZMQ_POLL_BASED_ON_POLL
int
pollfd_index
;
#endif
}
item_t
;
// List of sockets
typedef
std
::
vector
<
item_t
>
items_t
;
items_t
_items
;
...
...
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