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
da2bc60a
Commit
da2bc60a
authored
Oct 22, 2015
by
somdoron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing zmq_pollfd as it is replaced by zmq_poller
parent
0650b59b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
223 deletions
+61
-223
Makefile.am
Makefile.am
+0
-4
zmq.h
include/zmq.h
+0
-18
socket_poller.cpp
src/socket_poller.cpp
+0
-0
socket_poller.hpp
src/socket_poller.hpp
+52
-32
zmq.cpp
src/zmq.cpp
+0
-0
CMakeLists.txt
tests/CMakeLists.txt
+0
-1
test_poller.cpp
tests/test_poller.cpp
+9
-4
test_thread_safe_polling.cpp
tests/test_thread_safe_polling.cpp
+0
-164
No files found.
Makefile.am
View file @
da2bc60a
...
...
@@ -367,7 +367,6 @@ test_apps = \
tests/test_socketopt_hwm
\
tests/test_heartbeats
\
tests/test_stream_exceeds_buffer
\
tests/test_thread_safe_polling
\
tests/test_poller
tests_test_system_SOURCES
=
tests/test_system.cpp
...
...
@@ -573,9 +572,6 @@ tests_test_heartbeats_LDADD = src/libzmq.la
tests_test_stream_exceeds_buffer_SOURCES
=
tests/test_stream_exceeds_buffer.cpp
tests_test_stream_exceeds_buffer_LDADD
=
src/libzmq.la
tests_test_thread_safe_polling_SOURCES
=
tests/test_thread_safe_polling.cpp
tests_test_thread_safe_polling_LDADD
=
src/libzmq.la
tests_test_poller_SOURCES
=
tests/test_poller.cpp
tests_test_poller_LDADD
=
src/libzmq.la
...
...
include/zmq.h
View file @
da2bc60a
...
...
@@ -383,8 +383,6 @@ ZMQ_EXPORT int zmq_send (void *s, const void *buf, size_t len, int flags);
ZMQ_EXPORT
int
zmq_send_const
(
void
*
s
,
const
void
*
buf
,
size_t
len
,
int
flags
);
ZMQ_EXPORT
int
zmq_recv
(
void
*
s
,
void
*
buf
,
size_t
len
,
int
flags
);
ZMQ_EXPORT
int
zmq_socket_monitor
(
void
*
s
,
const
char
*
addr
,
int
events
);
ZMQ_EXPORT
int
zmq_add_pollfd
(
void
*
s
,
void
*
p
);
ZMQ_EXPORT
int
zmq_remove_pollfd
(
void
*
s
,
void
*
p
);
/******************************************************************************/
/* I/O multiplexing. */
...
...
@@ -411,22 +409,6 @@ typedef struct zmq_pollitem_t
ZMQ_EXPORT
int
zmq_poll
(
zmq_pollitem_t
*
items
,
int
nitems
,
long
timeout
);
/******************************************************************************/
/* Pollfd polling on thread safe socket */
/******************************************************************************/
ZMQ_EXPORT
void
*
zmq_pollfd_new
();
ZMQ_EXPORT
int
zmq_pollfd_close
(
void
*
p
);
ZMQ_EXPORT
void
zmq_pollfd_recv
(
void
*
p
);
ZMQ_EXPORT
int
zmq_pollfd_wait
(
void
*
p
,
int
timeout_
);
ZMQ_EXPORT
int
zmq_pollfd_poll
(
void
*
p
,
zmq_pollitem_t
*
items
,
int
nitems
,
long
timeout
);
#if defined _WIN32
ZMQ_EXPORT
SOCKET
zmq_pollfd_fd
(
void
*
p
);
#else
ZMQ_EXPORT
int
zmq_pollfd_fd
(
void
*
p
);
#endif
/******************************************************************************/
/* Poller polling on sockets,fd and threaf safe sockets */
/******************************************************************************/
...
...
src/socket_poller.cpp
View file @
da2bc60a
This diff is collapsed.
Click to expand it.
src/socket_poller.hpp
View file @
da2bc60a
...
...
@@ -30,10 +30,23 @@
#ifndef __ZMQ_SOCKET_POLLER_HPP_INCLUDED__
#define __ZMQ_SOCKET_POLLER_HPP_INCLUDED__
#include "poller.hpp"
#if defined ZMQ_POLL_BASED_ON_POLL
#include <poll.h>
#endif
#if defined ZMQ_HAVE_WINDOWS
#include "windows.hpp"
#else
#include <unistd.h>
#endif
#include <vector>
#include <algorithm>
#include "../include/zmq.h"
#include "socket_base.hpp"
#include "signaler.hpp"
namespace
zmq
{
...
...
@@ -46,28 +59,19 @@ namespace zmq
typedef
struct
event_t
{
void
*
socket
;
#if defined _WIN32
SOCKET
fd
;
#else
int
fd
;
#endif
socket_base_t
*
socket
;
fd_t
fd
;
void
*
user_data
;
short
events
;
}
event_t
;
int
add
(
void
*
socket
,
void
*
user_data
,
short
events
);
int
modify
(
void
*
socket
,
short
events
);
int
remove
(
void
*
socket
);
#if defined _WIN32
int
add_fd
(
SOCKET
fd
,
void
*
user_data
,
short
events
);
int
modify_fd
(
SOCKET
fd
,
short
events
);
int
remove_fd
(
SOCKET
fd
);
#else
int
add_fd
(
int
fd
,
void
*
user_data
,
short
events
);
int
modify_fd
(
int
fd
,
short
events
);
int
remove_fd
(
int
fd
);
#endif
int
add
(
socket_base_t
*
socket
,
void
*
user_data
,
short
events
);
int
modify
(
socket_base_t
*
socket
,
short
events
);
int
remove
(
socket_base_t
*
socket
);
int
add_fd
(
fd_t
fd
,
void
*
user_data
,
short
events
);
int
modify_fd
(
fd_t
fd
,
short
events
);
int
remove_fd
(
fd_t
fd
);
int
wait
(
event_t
*
event
,
long
timeout
);
...
...
@@ -75,29 +79,45 @@ namespace zmq
bool
check_tag
();
private
:
void
rebuild
();
int
rebuild
();
// Used to check whether the object is a socket_poller.
uint32_t
tag
;
//
Pollfd
used for thread safe sockets polling
void
*
pollfd
;
//
Signaler
used for thread safe sockets polling
signaler_t
signaler
;
// List of sockets
typedef
std
::
vector
<
event_t
>
events_t
;
events_t
events
;
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
;
// Current zmq_poll set
zmq_pollitem_t
*
poll_set
;
// List of sockets
typedef
std
::
vector
<
item_t
>
items_t
;
items_t
items
;
//
Matching set to events
event_t
*
poll_events
;
//
Does the pollset needs rebuilding?
bool
need_rebuild
;
// Should the signaler be used for the thread safe polling?
bool
use_signaler
;
// Size of the pollset
int
poll_size
;
// Does the pollset needs rebuilding?
bool
need_rebuild
;
#if defined ZMQ_POLL_BASED_ON_POLL
pollfd
*
pollfds
;
#elif defined ZMQ_POLL_BASED_ON_SELECT
fd_set
pollset_in
;
fd_set
pollset_out
;
fd_set
pollset_err
;
zmq
::
fd_t
maxfd
;
#endif
socket_poller_t
(
const
socket_poller_t
&
);
const
socket_poller_t
&
operator
=
(
const
socket_poller_t
&
);
...
...
src/zmq.cpp
View file @
da2bc60a
This diff is collapsed.
Click to expand it.
tests/CMakeLists.txt
View file @
da2bc60a
...
...
@@ -52,7 +52,6 @@ set(tests
test_client_server
test_sockopt_hwm
test_heartbeats
test_thread_safe_polling
test_poller
)
if
(
NOT WIN32
)
...
...
tests/test_poller.cpp
View file @
da2bc60a
...
...
@@ -67,7 +67,7 @@ int main (void)
// Send a message
char
data
[
1
]
=
{
'H'
};
rc
=
zmq_send_const
(
vent
,
data
,
1
,
0
);
assert
(
rc
==
1
);
assert
(
rc
==
1
);
// We expect a message only on the sink
zmq_poller_event_t
event
;
...
...
@@ -77,7 +77,12 @@ int main (void)
assert
(
event
.
user_data
==
sink
);
rc
=
zmq_recv
(
sink
,
data
,
1
,
0
);
assert
(
rc
==
1
);
// We expect timed out
rc
=
zmq_poller_wait
(
poller
,
&
event
,
0
);
assert
(
rc
==
-
1
);
assert
(
errno
==
ETIMEDOUT
);
// Stop polling sink
rc
=
zmq_poller_remove
(
poller
,
sink
);
assert
(
rc
==
0
);
...
...
@@ -127,7 +132,7 @@ int main (void)
assert
(
event
.
socket
==
server
);
assert
(
event
.
user_data
==
NULL
);
assert
(
event
.
events
==
ZMQ_POLLOUT
);
// Destory poller, sockets and ctx
rc
=
zmq_poller_close
(
poller
);
assert
(
rc
==
0
);
...
...
@@ -141,7 +146,7 @@ int main (void)
assert
(
rc
==
0
);
rc
=
zmq_close
(
client
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_
shutdown
(
ctx
);
rc
=
zmq_ctx_
term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
...
...
tests/test_thread_safe_polling.cpp
deleted
100644 → 0
View file @
0650b59b
/*
Copyright (c) 2007-2015 Contributors as noted in the AUTHORS file
This file is part of libzmq, the ZeroMQ core engine in C++.
libzmq is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
As a special exception, the Contributors give you permission to link
this library with independent modules to produce an executable,
regardless of the license terms of these independent modules, and to
copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the
terms and conditions of the license of that module. An independent
module is a module which is not derived from or based on this library.
If you modify this library, you must extend this exception to your
version of the library.
libzmq 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 GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testutil.hpp"
void
worker
(
void
*
s
);
int
main
(
void
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_SERVER
);
void
*
server2
=
zmq_socket
(
ctx
,
ZMQ_SERVER
);
void
*
pollfd
=
zmq_pollfd_new
();
int
rc
;
rc
=
zmq_add_pollfd
(
server
,
pollfd
);
assert
(
rc
==
0
);
rc
=
zmq_add_pollfd
(
server2
,
pollfd
);
assert
(
rc
==
0
);
zmq_pollitem_t
items
[]
=
{
{
server
,
0
,
ZMQ_POLLIN
,
0
},
{
server2
,
0
,
ZMQ_POLLIN
,
0
}};
rc
=
zmq_bind
(
server
,
"tcp://127.0.0.1:5560"
);
assert
(
rc
==
0
);
rc
=
zmq_bind
(
server2
,
"tcp://127.0.0.1:5561"
);
assert
(
rc
==
0
);
void
*
t
=
zmq_threadstart
(
worker
,
ctx
);
assert
(
rc
==
0
);
rc
=
zmq_pollfd_poll
(
pollfd
,
items
,
2
,
-
1
);
assert
(
rc
==
1
);
assert
(
items
[
0
].
revents
==
ZMQ_POLLIN
);
assert
(
items
[
1
].
revents
==
0
);
zmq_msg_t
msg
;
rc
=
zmq_msg_init
(
&
msg
);
rc
=
zmq_msg_recv
(
&
msg
,
server
,
ZMQ_DONTWAIT
);
assert
(
rc
==
1
);
rc
=
zmq_pollfd_poll
(
pollfd
,
items
,
2
,
-
1
);
assert
(
rc
==
1
);
assert
(
items
[
0
].
revents
==
0
);
assert
(
items
[
1
].
revents
==
ZMQ_POLLIN
);
rc
=
zmq_msg_recv
(
&
msg
,
server2
,
ZMQ_DONTWAIT
);
assert
(
rc
==
1
);
rc
=
zmq_pollfd_poll
(
pollfd
,
items
,
2
,
0
);
assert
(
rc
==
0
);
assert
(
items
[
0
].
revents
==
0
);
assert
(
items
[
1
].
revents
==
0
);
zmq_threadclose
(
t
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_remove_pollfd
(
server
,
pollfd
);
assert
(
rc
==
0
);
rc
=
zmq_remove_pollfd
(
server2
,
pollfd
);
assert
(
rc
==
0
);
rc
=
zmq_pollfd_close
(
pollfd
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
server
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
server2
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
}
void
worker
(
void
*
ctx
)
{
void
*
client
=
zmq_socket
(
ctx
,
ZMQ_CLIENT
);
int
rc
=
zmq_connect
(
client
,
"tcp://127.0.0.1:5560"
);
assert
(
rc
==
0
);
msleep
(
100
);
zmq_msg_t
msg
;
rc
=
zmq_msg_init_size
(
&
msg
,
1
);
assert
(
rc
==
0
);
char
*
data
=
(
char
*
)
zmq_msg_data
(
&
msg
);
data
[
0
]
=
1
;
rc
=
zmq_msg_send
(
&
msg
,
client
,
0
);
assert
(
rc
==
1
);
rc
=
zmq_disconnect
(
client
,
"tcp://127.0.0.1:5560"
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
client
,
"tcp://127.0.0.1:5561"
);
assert
(
rc
==
0
);
msleep
(
100
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_init_size
(
&
msg
,
1
);
assert
(
rc
==
0
);
data
=
(
char
*
)
zmq_msg_data
(
&
msg
);
data
[
0
]
=
1
;
rc
=
zmq_msg_send
(
&
msg
,
client
,
0
);
assert
(
rc
==
1
);
rc
=
zmq_msg_close
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
client
);
assert
(
rc
==
0
);
}
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