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
c6e4b0ab
Commit
c6e4b0ab
authored
Jun 01, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: zmq_poll implementation is complex
Solution: extract compute_timeout method
parent
3db3bbfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
13 deletions
+28
-13
zmq.cpp
src/zmq.cpp
+28
-13
No files found.
src/zmq.cpp
View file @
c6e4b0ab
...
@@ -792,6 +792,27 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
...
@@ -792,6 +792,27 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
}
}
#endif // ZMQ_HAVE_POLLER
#endif // ZMQ_HAVE_POLLER
#if !defined ZMQ_HAVE_POLLER
#if defined ZMQ_POLL_BASED_ON_POLL
typedef
int
timeout_t
;
static
timeout_t
compute_timeout
(
const
bool
first_pass_
,
const
long
timeout_
,
const
uint64_t
now_
,
const
uint64_t
end_
)
{
if
(
first_pass_
)
return
0
;
else
if
(
timeout_
<
0
)
return
-
1
;
else
return
static_cast
<
timeout_t
>
(
std
::
min
<
uint64_t
>
(
end_
-
now_
,
INT_MAX
));
}
#elif defined ZMQ_POLL_BASED_ON_SELECT
#endif
#endif
int
zmq_poll
(
zmq_pollitem_t
*
items_
,
int
nitems_
,
long
timeout_
)
int
zmq_poll
(
zmq_pollitem_t
*
items_
,
int
nitems_
,
long
timeout_
)
{
{
// TODO: the function implementation can just call zmq_pollfd_poll with
// TODO: the function implementation can just call zmq_pollfd_poll with
...
@@ -820,21 +841,21 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
...
@@ -820,21 +841,21 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
return
usleep
(
timeout_
*
1000
);
return
usleep
(
timeout_
*
1000
);
#endif
#endif
}
}
zmq
::
clock_t
clock
;
uint64_t
now
=
0
;
uint64_t
end
=
0
;
#if defined ZMQ_POLL_BASED_ON_POLL
if
(
!
items_
)
{
if
(
!
items_
)
{
errno
=
EFAULT
;
errno
=
EFAULT
;
return
-
1
;
return
-
1
;
}
}
zmq
::
clock_t
clock
;
uint64_t
now
=
0
;
uint64_t
end
=
0
;
#if defined ZMQ_POLL_BASED_ON_POLL
pollfd
spollfds
[
ZMQ_POLLITEMS_DFLT
];
pollfd
spollfds
[
ZMQ_POLLITEMS_DFLT
];
pollfd
*
pollfds
=
spollfds
;
pollfd
*
pollfds
=
spollfds
;
if
(
nitems_
>
ZMQ_POLLITEMS_DFLT
)
{
if
(
nitems_
>
ZMQ_POLLITEMS_DFLT
)
{
pollfds
=
static_cast
<
pollfd
*>
(
malloc
(
nitems_
*
sizeof
(
pollfd
)));
pollfds
=
static_cast
<
pollfd
*>
(
malloc
(
nitems_
*
sizeof
(
pollfd
)));
// TODO since this function is called by a client, we could return errno == ENOMEM here
alloc_assert
(
pollfds
);
alloc_assert
(
pollfds
);
}
}
...
@@ -866,6 +887,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
...
@@ -866,6 +887,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
#else
#else
// Ensure we do not attempt to select () on more than FD_SETSIZE
// Ensure we do not attempt to select () on more than FD_SETSIZE
// file descriptors.
// file descriptors.
// TODO since this function is called by a client, we could return errno EINVAL/ENOMEM/... here
zmq_assert
(
nitems_
<=
FD_SETSIZE
);
zmq_assert
(
nitems_
<=
FD_SETSIZE
);
fd_set
pollset_in
;
fd_set
pollset_in
;
...
@@ -918,14 +940,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
...
@@ -918,14 +940,7 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
#if defined ZMQ_POLL_BASED_ON_POLL
#if defined ZMQ_POLL_BASED_ON_POLL
// Compute the timeout for the subsequent poll.
// Compute the timeout for the subsequent poll.
int
timeout
;
timeout_t
timeout
=
compute_timeout
(
first_pass
,
timeout_
,
now
,
end
);
if
(
first_pass
)
timeout
=
0
;
else
if
(
timeout_
<
0
)
timeout
=
-
1
;
else
timeout
=
static_cast
<
int
>
(
std
::
min
<
uint64_t
>
(
end
-
now
,
INT_MAX
));
// Wait for events.
// Wait for events.
{
{
...
...
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