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
8d7bf668
Commit
8d7bf668
authored
Sep 26, 2010
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common base for all pollers created; the only thing it handles at the moment is 'load'
parent
cf815e8c
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
125 additions
and
86 deletions
+125
-86
Makefile.am
src/Makefile.am
+2
-0
devpoll.cpp
src/devpoll.cpp
+2
-11
devpoll.hpp
src/devpoll.hpp
+2
-7
epoll.cpp
src/epoll.cpp
+2
-10
epoll.hpp
src/epoll.hpp
+2
-7
kqueue.cpp
src/kqueue.cpp
+5
-10
kqueue.hpp
src/kqueue.hpp
+2
-7
poll.cpp
src/poll.cpp
+2
-10
poll.hpp
src/poll.hpp
+2
-7
poller_base.cpp
src/poller_base.cpp
+44
-0
poller_base.hpp
src/poller_base.hpp
+56
-0
select.cpp
src/select.cpp
+2
-10
select.hpp
src/select.hpp
+2
-7
No files found.
src/Makefile.am
View file @
8d7bf668
...
...
@@ -89,6 +89,7 @@ libzmq_la_SOURCES = \
platform.hpp
\
poll.hpp
\
poller.hpp
\
poller_base.hpp
\
pair.hpp
\
pub.hpp
\
pull.hpp
\
...
...
@@ -148,6 +149,7 @@ libzmq_la_SOURCES = \
pgm_socket.cpp
\
pipe.cpp
\
poll.cpp
\
poller_base.cpp
\
pull.cpp
\
push.cpp
\
pub.cpp
\
...
...
src/devpoll.cpp
View file @
8d7bf668
...
...
@@ -56,10 +56,6 @@ zmq::devpoll_t::devpoll_t () :
zmq
::
devpoll_t
::~
devpoll_t
()
{
worker
.
stop
();
// Make sure there are no fds registered on shutdown.
zmq_assert
(
load
.
get
()
==
0
);
close
(
devpoll_fd
);
}
...
...
@@ -84,7 +80,7 @@ zmq::devpoll_t::handle_t zmq::devpoll_t::add_fd (fd_t fd_,
pending_list
.
push_back
(
fd_
);
// Increase the load metric of the thread.
load
.
ad
d
(
1
);
adjust_loa
d
(
1
);
return
fd_
;
}
...
...
@@ -97,7 +93,7 @@ void zmq::devpoll_t::rm_fd (handle_t handle_)
fd_table
[
handle_
].
valid
=
false
;
// Decrease the load metric of the thread.
load
.
sub
(
1
);
adjust_load
(
-
1
);
}
void
zmq
::
devpoll_t
::
set_pollin
(
handle_t
handle_
)
...
...
@@ -140,11 +136,6 @@ void zmq::devpoll_t::cancel_timer (i_poll_events *events_, int id_)
timers
.
erase
(
it
);
}
int
zmq
::
devpoll_t
::
get_load
()
{
return
load
.
get
();
}
void
zmq
::
devpoll_t
::
start
()
{
worker
.
start
(
worker_routine
,
this
);
...
...
src/devpoll.hpp
View file @
8d7bf668
...
...
@@ -28,14 +28,14 @@
#include "fd.hpp"
#include "thread.hpp"
#include "
atomic_counter
.hpp"
#include "
poller_base
.hpp"
namespace
zmq
{
// Implements socket polling mechanism using the "/dev/poll" interface.
class
devpoll_t
class
devpoll_t
:
public
poller_base_t
{
public
:
...
...
@@ -53,7 +53,6 @@ namespace zmq
void
reset_pollout
(
handle_t
handle_
);
void
add_timer
(
int
timeout_
,
struct
i_poll_events
*
events_
,
int
id_
);
void
cancel_timer
(
struct
i_poll_events
*
events_
,
int
id_
);
int
get_load
();
void
start
();
void
stop
();
...
...
@@ -94,10 +93,6 @@ namespace zmq
// Handle of the physical thread doing the I/O work.
thread_t
worker
;
// Load of the poller. Currently number of file descriptors
// registered with the poller.
atomic_counter_t
load
;
devpoll_t
(
const
devpoll_t
&
);
void
operator
=
(
const
devpoll_t
&
);
};
...
...
src/epoll.cpp
View file @
8d7bf668
...
...
@@ -45,9 +45,6 @@ zmq::epoll_t::~epoll_t ()
// Wait till the worker thread exits.
worker
.
stop
();
// Make sure there are no fds registered on shutdown.
zmq_assert
(
load
.
get
()
==
0
);
close
(
epoll_fd
);
for
(
retired_t
::
iterator
it
=
retired
.
begin
();
it
!=
retired
.
end
();
it
++
)
delete
*
it
;
...
...
@@ -71,7 +68,7 @@ zmq::epoll_t::handle_t zmq::epoll_t::add_fd (fd_t fd_, i_poll_events *events_)
errno_assert
(
rc
!=
-
1
);
// Increase the load metric of the thread.
load
.
ad
d
(
1
);
adjust_loa
d
(
1
);
return
pe
;
}
...
...
@@ -85,7 +82,7 @@ void zmq::epoll_t::rm_fd (handle_t handle_)
retired
.
push_back
(
pe
);
// Decrease the load metric of the thread.
load
.
sub
(
1
);
adjust_load
(
-
1
);
}
void
zmq
::
epoll_t
::
set_pollin
(
handle_t
handle_
)
...
...
@@ -133,11 +130,6 @@ void zmq::epoll_t::cancel_timer (i_poll_events *events_, int id_)
timers
.
erase
(
it
);
}
int
zmq
::
epoll_t
::
get_load
()
{
return
load
.
get
();
}
void
zmq
::
epoll_t
::
start
()
{
worker
.
start
(
worker_routine
,
this
);
...
...
src/epoll.hpp
View file @
8d7bf668
...
...
@@ -29,7 +29,7 @@
#include "fd.hpp"
#include "thread.hpp"
#include "
atomic_counter
.hpp"
#include "
poller_base
.hpp"
namespace
zmq
{
...
...
@@ -37,7 +37,7 @@ namespace zmq
// This class implements socket polling mechanism using the Linux-specific
// epoll mechanism.
class
epoll_t
class
epoll_t
:
public
poller_base_t
{
public
:
...
...
@@ -55,7 +55,6 @@ namespace zmq
void
reset_pollout
(
handle_t
handle_
);
void
add_timer
(
int
timeout_
,
struct
i_poll_events
*
events_
,
int
id_
);
void
cancel_timer
(
struct
i_poll_events
*
events_
,
int
id_
);
int
get_load
();
void
start
();
void
stop
();
...
...
@@ -91,10 +90,6 @@ namespace zmq
// Handle of the physical thread doing the I/O work.
thread_t
worker
;
// Load of the poller. Currently number of file descriptors
// registered with the poller.
atomic_counter_t
load
;
epoll_t
(
const
epoll_t
&
);
void
operator
=
(
const
epoll_t
&
);
};
...
...
src/kqueue.cpp
View file @
8d7bf668
...
...
@@ -54,10 +54,6 @@ zmq::kqueue_t::kqueue_t () :
zmq
::
kqueue_t
::~
kqueue_t
()
{
worker
.
stop
();
// Make sure there are no fds registered on shutdown.
zmq_assert
(
load
.
get
()
==
0
);
close
(
kqueue_fd
);
}
...
...
@@ -74,7 +70,7 @@ void zmq::kqueue_t::kevent_delete (fd_t fd_, short filter_)
{
struct
kevent
ev
;
EV_SET
(
&
ev
,
fd_
,
filter_
,
EV_DELETE
,
0
,
0
,
(
kevent_udata_t
)
NULL
);
EV_SET
(
&
ev
,
fd_
,
filter_
,
EV_DELETE
,
0
,
0
,
(
kevent_udata_t
)
NULL
);
int
rc
=
kevent
(
kqueue_fd
,
&
ev
,
1
,
NULL
,
0
,
NULL
);
errno_assert
(
rc
!=
-
1
);
}
...
...
@@ -90,6 +86,8 @@ zmq::kqueue_t::handle_t zmq::kqueue_t::add_fd (fd_t fd_,
pe
->
flag_pollout
=
0
;
pe
->
reactor
=
reactor_
;
adjust_load
(
1
);
return
pe
;
}
...
...
@@ -102,6 +100,8 @@ void zmq::kqueue_t::rm_fd (handle_t handle_)
kevent_delete
(
pe
->
fd
,
EVFILT_WRITE
);
pe
->
fd
=
retired_fd
;
retired
.
push_back
(
pe
);
adjust_load
(
-
1
);
}
void
zmq
::
kqueue_t
::
set_pollin
(
handle_t
handle_
)
...
...
@@ -144,11 +144,6 @@ void zmq::kqueue_t::cancel_timer (i_poll_events *events_, int id_)
timers
.
erase
(
it
);
}
int
zmq
::
kqueue_t
::
get_load
()
{
return
load
.
get
();
}
void
zmq
::
kqueue_t
::
start
()
{
worker
.
start
(
worker_routine
,
this
);
...
...
src/kqueue.hpp
View file @
8d7bf668
...
...
@@ -29,7 +29,7 @@
#include "fd.hpp"
#include "thread.hpp"
#include "
atomic_counter
.hpp"
#include "
poller_base
.hpp"
namespace
zmq
{
...
...
@@ -37,7 +37,7 @@ namespace zmq
// Implements socket polling mechanism using the BSD-specific
// kqueue interface.
class
kqueue_t
class
kqueue_t
:
public
poller_base_t
{
public
:
...
...
@@ -55,7 +55,6 @@ namespace zmq
void
reset_pollout
(
handle_t
handle_
);
void
add_timer
(
int
timeout_
,
struct
i_poll_events
*
events_
,
int
id_
);
void
cancel_timer
(
struct
i_poll_events
*
events_
,
int
id_
);
int
get_load
();
void
start
();
void
stop
();
...
...
@@ -98,10 +97,6 @@ namespace zmq
// Handle of the physical thread doing the I/O work.
thread_t
worker
;
// Load of the poller. Currently number of file descriptors
// registered with the poller.
atomic_counter_t
load
;
kqueue_t
(
const
kqueue_t
&
);
void
operator
=
(
const
kqueue_t
&
);
};
...
...
src/poll.cpp
View file @
8d7bf668
...
...
@@ -54,9 +54,6 @@ zmq::poll_t::poll_t () :
zmq
::
poll_t
::~
poll_t
()
{
worker
.
stop
();
// Make sure there are no fds registered on shutdown.
zmq_assert
(
load
.
get
()
==
0
);
}
zmq
::
poll_t
::
handle_t
zmq
::
poll_t
::
add_fd
(
fd_t
fd_
,
i_poll_events
*
events_
)
...
...
@@ -69,7 +66,7 @@ zmq::poll_t::handle_t zmq::poll_t::add_fd (fd_t fd_, i_poll_events *events_)
fd_table
[
fd_
].
events
=
events_
;
// Increase the load metric of the thread.
load
.
ad
d
(
1
);
adjust_loa
d
(
1
);
return
fd_
;
}
...
...
@@ -85,7 +82,7 @@ void zmq::poll_t::rm_fd (handle_t handle_)
retired
=
true
;
// Decrease the load metric of the thread.
load
.
sub
(
1
);
adjust_load
(
-
1
);
}
void
zmq
::
poll_t
::
set_pollin
(
handle_t
handle_
)
...
...
@@ -124,11 +121,6 @@ void zmq::poll_t::cancel_timer (i_poll_events *events_, int id_)
timers
.
erase
(
it
);
}
int
zmq
::
poll_t
::
get_load
()
{
return
load
.
get
();
}
void
zmq
::
poll_t
::
start
()
{
worker
.
start
(
worker_routine
,
this
);
...
...
src/poll.hpp
View file @
8d7bf668
...
...
@@ -34,7 +34,7 @@
#include "fd.hpp"
#include "thread.hpp"
#include "
atomic_counter
.hpp"
#include "
poller_base
.hpp"
namespace
zmq
{
...
...
@@ -42,7 +42,7 @@ namespace zmq
// Implements socket polling mechanism using the POSIX.1-2001
// poll() system call.
class
poll_t
class
poll_t
:
public
poller_base_t
{
public
:
...
...
@@ -60,7 +60,6 @@ namespace zmq
void
reset_pollout
(
handle_t
handle_
);
void
add_timer
(
int
timeout_
,
struct
i_poll_events
*
events_
,
int
id_
);
void
cancel_timer
(
struct
i_poll_events
*
events_
,
int
id_
);
int
get_load
();
void
start
();
void
stop
();
...
...
@@ -98,10 +97,6 @@ namespace zmq
// Handle of the physical thread doing the I/O work.
thread_t
worker
;
// Load of the poller. Currently number of file descriptors
// registered with the poller.
atomic_counter_t
load
;
poll_t
(
const
poll_t
&
);
void
operator
=
(
const
poll_t
&
);
};
...
...
src/poller_base.cpp
0 → 100644
View file @
8d7bf668
/*
Copyright (c) 2007-2010 iMatix Corporation
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the Lesser GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "poller_base.hpp"
#include "err.hpp"
zmq
::
poller_base_t
::
poller_base_t
()
{
}
zmq
::
poller_base_t
::~
poller_base_t
()
{
// Make sure there are no fds registered on shutdown.
zmq_assert
(
get_load
()
==
0
);
}
int
zmq
::
poller_base_t
::
get_load
()
{
return
load
.
get
();
}
void
zmq
::
poller_base_t
::
adjust_load
(
int
amount_
)
{
if
(
amount_
>
0
)
load
.
add
(
amount_
);
else
if
(
amount_
<
0
)
load
.
sub
(
-
amount_
);
}
src/poller_base.hpp
0 → 100644
View file @
8d7bf668
/*
Copyright (c) 2007-2010 iMatix Corporation
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the Lesser GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ZMQ_POLLER_BASE_HPP_INCLUDED__
#define __ZMQ_POLLER_BASE_HPP_INCLUDED__
#include "atomic_counter.hpp"
namespace
zmq
{
class
poller_base_t
{
public
:
poller_base_t
();
~
poller_base_t
();
// Returns load of the poller. Note that this function can be
// invoked from a different thread!
int
get_load
();
protected
:
// Called by individual poller implementations to manage the load.
void
adjust_load
(
int
amount_
);
private
:
// Load of the poller. Currently the number of file descriptors
// registered.
atomic_counter_t
load
;
poller_base_t
(
const
poller_base_t
&
);
void
operator
=
(
const
poller_base_t
&
);
};
}
#endif
src/select.cpp
View file @
8d7bf668
...
...
@@ -54,9 +54,6 @@ zmq::select_t::select_t () :
zmq
::
select_t
::~
select_t
()
{
worker
.
stop
();
// Make sure there are no fds registered on shutdown.
zmq_assert
(
load
.
get
()
==
0
);
}
zmq
::
select_t
::
handle_t
zmq
::
select_t
::
add_fd
(
fd_t
fd_
,
i_poll_events
*
events_
)
...
...
@@ -77,7 +74,7 @@ zmq::select_t::handle_t zmq::select_t::add_fd (fd_t fd_, i_poll_events *events_)
maxfd
=
fd_
;
// Increase the load metric of the thread.
load
.
ad
d
(
1
);
adjust_loa
d
(
1
);
return
fd_
;
}
...
...
@@ -113,7 +110,7 @@ void zmq::select_t::rm_fd (handle_t handle_)
}
// Decrease the load metric of the thread.
load
.
sub
(
1
);
adjust_load
(
-
1
);
}
void
zmq
::
select_t
::
set_pollin
(
handle_t
handle_
)
...
...
@@ -148,11 +145,6 @@ void zmq::select_t::cancel_timer (i_poll_events *events_, int id_)
timers
.
erase
(
it
);
}
int
zmq
::
select_t
::
get_load
()
{
return
load
.
get
();
}
void
zmq
::
select_t
::
start
()
{
worker
.
start
(
worker_routine
,
this
);
...
...
src/select.hpp
View file @
8d7bf668
...
...
@@ -36,7 +36,7 @@
#include "fd.hpp"
#include "thread.hpp"
#include "
atomic_counter
.hpp"
#include "
poller_base
.hpp"
namespace
zmq
{
...
...
@@ -44,7 +44,7 @@ namespace zmq
// Implements socket polling mechanism using POSIX.1-2001 select()
// function.
class
select_t
class
select_t
:
public
poller_base_t
{
public
:
...
...
@@ -62,7 +62,6 @@ namespace zmq
void
reset_pollout
(
handle_t
handle_
);
void
add_timer
(
int
timeout_
,
struct
i_poll_events
*
events_
,
int
id_
);
void
cancel_timer
(
struct
i_poll_events
*
events_
,
int
id_
);
int
get_load
();
void
start
();
void
stop
();
...
...
@@ -109,10 +108,6 @@ namespace zmq
// Handle of the physical thread doing the I/O work.
thread_t
worker
;
// Load of the poller. Currently number of file descriptors
// registered with the poller.
atomic_counter_t
load
;
select_t
(
const
select_t
&
);
void
operator
=
(
const
select_t
&
);
};
...
...
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