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
3db3bbfb
Commit
3db3bbfb
authored
May 31, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: duplication in implementation zmq_poller_poll
Solution: remove duplication
parent
89e5f15a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
119 deletions
+64
-119
zmq.cpp
src/zmq.cpp
+64
-119
No files found.
src/zmq.cpp
View file @
3db3bbfb
...
...
@@ -800,7 +800,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// if poller is present, use that.
return
zmq_poller_poll
(
items_
,
nitems_
,
timeout_
);
#else
#if defined ZMQ_POLL_BASED_ON_POLL
#if defined ZMQ_POLL_BASED_ON_POLL
|| defined ZMQ_POLL_BASED_ON_SELECT
if
(
unlikely
(
nitems_
<
0
))
{
errno
=
EINVAL
;
return
-
1
;
...
...
@@ -811,22 +811,25 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
#if defined ZMQ_HAVE_WINDOWS
Sleep
(
timeout_
>
0
?
timeout_
:
INFINITE
);
return
0
;
#elif defined ZMQ_HAVE_ANDROID
usleep
(
timeout_
*
1000
);
return
0
;
#elif defined ZMQ_HAVE_VXWORKS
struct
timespec
ns_
;
ns_
.
tv_sec
=
timeout_
/
1000
;
ns_
.
tv_nsec
=
timeout_
%
1000
*
1000000
;
return
nanosleep
(
&
ns_
,
0
);
#else
return
usleep
(
timeout_
*
1000
);
#endif
}
zmq
::
clock_t
clock
;
uint64_t
now
=
0
;
uint64_t
end
=
0
;
#if defined ZMQ_POLL_BASED_ON_POLL
if
(
!
items_
)
{
errno
=
EFAULT
;
return
-
1
;
}
zmq
::
clock_t
clock
;
uint64_t
now
=
0
;
uint64_t
end
=
0
;
pollfd
spollfds
[
ZMQ_POLLITEMS_DFLT
];
pollfd
*
pollfds
=
spollfds
;
...
...
@@ -860,11 +863,60 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
|
(
items_
[
i
].
events
&
ZMQ_POLLPRI
?
POLLPRI
:
0
);
}
}
#else
// Ensure we do not attempt to select () on more than FD_SETSIZE
// file descriptors.
zmq_assert
(
nitems_
<=
FD_SETSIZE
);
fd_set
pollset_in
;
FD_ZERO
(
&
pollset_in
);
fd_set
pollset_out
;
FD_ZERO
(
&
pollset_out
);
fd_set
pollset_err
;
FD_ZERO
(
&
pollset_err
);
zmq
::
fd_t
maxfd
=
0
;
// Build the fd_sets for passing to select ().
for
(
int
i
=
0
;
i
!=
nitems_
;
i
++
)
{
// If the poll item is a 0MQ socket we are interested in input on the
// notification file descriptor retrieved by the ZMQ_FD socket option.
if
(
items_
[
i
].
socket
)
{
size_t
zmq_fd_size
=
sizeof
(
zmq
::
fd_t
);
zmq
::
fd_t
notify_fd
;
if
(
zmq_getsockopt
(
items_
[
i
].
socket
,
ZMQ_FD
,
&
notify_fd
,
&
zmq_fd_size
)
==
-
1
)
return
-
1
;
if
(
items_
[
i
].
events
)
{
FD_SET
(
notify_fd
,
&
pollset_in
);
if
(
maxfd
<
notify_fd
)
maxfd
=
notify_fd
;
}
}
// Else, the poll item is a raw file descriptor. Convert the poll item
// events to the appropriate fd_sets.
else
{
if
(
items_
[
i
].
events
&
ZMQ_POLLIN
)
FD_SET
(
items_
[
i
].
fd
,
&
pollset_in
);
if
(
items_
[
i
].
events
&
ZMQ_POLLOUT
)
FD_SET
(
items_
[
i
].
fd
,
&
pollset_out
);
if
(
items_
[
i
].
events
&
ZMQ_POLLERR
)
FD_SET
(
items_
[
i
].
fd
,
&
pollset_err
);
if
(
maxfd
<
items_
[
i
].
fd
)
maxfd
=
items_
[
i
].
fd
;
}
}
fd_set
inset
,
outset
,
errset
;
#endif
bool
first_pass
=
true
;
int
nevents
=
0
;
while
(
true
)
{
#if defined ZMQ_POLL_BASED_ON_POLL
// Compute the timeout for the subsequent poll.
int
timeout
;
if
(
first_pass
)
...
...
@@ -925,119 +977,8 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
nevents
++
;
}
// If timeout is zero, exit immediately whether there are events or not.
if
(
timeout_
==
0
)
break
;
// If there are events to return, we can exit immediately.
if
(
nevents
)
break
;
// At this point we are meant to wait for events but there are none.
// If timeout is infinite we can just loop until we get some events.
if
(
timeout_
<
0
)
{
if
(
first_pass
)
first_pass
=
false
;
continue
;
}
// The timeout is finite and there are no events. In the first pass
// we get a timestamp of when the polling have begun. (We assume that
// first pass have taken negligible time). We also compute the time
// when the polling should time out.
if
(
first_pass
)
{
now
=
clock
.
now_ms
();
end
=
now
+
timeout_
;
if
(
now
==
end
)
break
;
first_pass
=
false
;
continue
;
}
// Find out whether timeout have expired.
now
=
clock
.
now_ms
();
if
(
now
>=
end
)
break
;
}
if
(
pollfds
!=
spollfds
)
free
(
pollfds
);
return
nevents
;
#elif defined ZMQ_POLL_BASED_ON_SELECT
if
(
unlikely
(
nitems_
<
0
))
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
unlikely
(
nitems_
==
0
))
{
if
(
timeout_
==
0
)
return
0
;
#if defined ZMQ_HAVE_WINDOWS
Sleep
(
timeout_
>
0
?
timeout_
:
INFINITE
);
return
0
;
#elif defined ZMQ_HAVE_VXWORKS
struct
timespec
ns_
;
ns_
.
tv_sec
=
timeout_
/
1000
;
ns_
.
tv_nsec
=
timeout_
%
1000
*
1000000
;
return
nanosleep
(
&
ns_
,
0
);
#else
return
usleep
(
timeout_
*
1000
);
#endif
}
zmq
::
clock_t
clock
;
uint64_t
now
=
0
;
uint64_t
end
=
0
;
// Ensure we do not attempt to select () on more than FD_SETSIZE
// file descriptors.
zmq_assert
(
nitems_
<=
FD_SETSIZE
);
fd_set
pollset_in
;
FD_ZERO
(
&
pollset_in
);
fd_set
pollset_out
;
FD_ZERO
(
&
pollset_out
);
fd_set
pollset_err
;
FD_ZERO
(
&
pollset_err
);
zmq
::
fd_t
maxfd
=
0
;
// Build the fd_sets for passing to select ().
for
(
int
i
=
0
;
i
!=
nitems_
;
i
++
)
{
// If the poll item is a 0MQ socket we are interested in input on the
// notification file descriptor retrieved by the ZMQ_FD socket option.
if
(
items_
[
i
].
socket
)
{
size_t
zmq_fd_size
=
sizeof
(
zmq
::
fd_t
);
zmq
::
fd_t
notify_fd
;
if
(
zmq_getsockopt
(
items_
[
i
].
socket
,
ZMQ_FD
,
&
notify_fd
,
&
zmq_fd_size
)
==
-
1
)
return
-
1
;
if
(
items_
[
i
].
events
)
{
FD_SET
(
notify_fd
,
&
pollset_in
);
if
(
maxfd
<
notify_fd
)
maxfd
=
notify_fd
;
}
}
// Else, the poll item is a raw file descriptor. Convert the poll item
// events to the appropriate fd_sets.
else
{
if
(
items_
[
i
].
events
&
ZMQ_POLLIN
)
FD_SET
(
items_
[
i
].
fd
,
&
pollset_in
);
if
(
items_
[
i
].
events
&
ZMQ_POLLOUT
)
FD_SET
(
items_
[
i
].
fd
,
&
pollset_out
);
if
(
items_
[
i
].
events
&
ZMQ_POLLERR
)
FD_SET
(
items_
[
i
].
fd
,
&
pollset_err
);
if
(
maxfd
<
items_
[
i
].
fd
)
maxfd
=
items_
[
i
].
fd
;
}
}
bool
first_pass
=
true
;
int
nevents
=
0
;
fd_set
inset
,
outset
,
errset
;
while
(
true
)
{
// Compute the timeout for the subsequent poll.
timeval
timeout
;
timeval
*
ptimeout
;
...
...
@@ -1125,6 +1066,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
if
(
items_
[
i
].
revents
)
nevents
++
;
}
#endif
// If timeout is zero, exit immediately whether there are events or not.
if
(
timeout_
==
0
)
...
...
@@ -1160,9 +1102,12 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
if
(
now
>=
end
)
break
;
}
#if defined ZMQ_POLL_BASED_ON_POLL
if
(
pollfds
!=
spollfds
)
free
(
pollfds
);
#endif
return
nevents
;
#else
// Exotic platforms that support neither poll() nor select().
errno
=
ENOTSUP
;
...
...
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