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
2daa0bb4
Commit
2daa0bb4
authored
Dec 05, 2010
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XSUB accepts (un)subscriptions in form of messages.
Signed-off-by:
Martin Sustrik
<
sustrik@250bpm.com
>
parent
c80e7b80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
16 deletions
+62
-16
sub.cpp
src/sub.cpp
+31
-0
sub.hpp
src/sub.hpp
+4
-0
xsub.cpp
src/xsub.cpp
+25
-15
xsub.hpp
src/xsub.hpp
+2
-1
No files found.
src/sub.cpp
View file @
2daa0bb4
...
...
@@ -17,6 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../include/zmq.h"
#include "sub.hpp"
zmq
::
sub_t
::
sub_t
(
class
ctx_t
*
parent_
,
uint32_t
tid_
)
:
...
...
@@ -27,3 +29,32 @@ zmq::sub_t::sub_t (class ctx_t *parent_, uint32_t tid_) :
zmq
::
sub_t
::~
sub_t
()
{
}
int
zmq
::
sub_t
::
xsetsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
)
{
if
(
option_
!=
ZMQ_SUBSCRIBE
&&
option_
!=
ZMQ_UNSUBSCRIBE
)
{
errno
=
EINVAL
;
return
-
1
;
}
// Create the subscription message.
zmq_msg_t
msg
;
zmq_msg_init_size
(
&
msg
,
optvallen_
+
1
);
unsigned
char
*
data
=
(
unsigned
char
*
)
zmq_msg_data
(
&
msg
);
if
(
option_
==
ZMQ_SUBSCRIBE
)
*
data
=
1
;
else
if
(
option_
==
ZMQ_UNSUBSCRIBE
)
*
data
=
0
;
memcpy
(
data
+
1
,
optval_
,
optvallen_
);
// Pass it further on in the stack.
int
err
;
int
rc
=
xsend
(
&
msg
,
0
);
if
(
rc
!=
0
)
err
=
errno
;
zmq_msg_close
(
&
msg
);
if
(
rc
!=
0
)
errno
=
err
;
return
rc
;
}
src/sub.hpp
View file @
2daa0bb4
...
...
@@ -32,6 +32,10 @@ namespace zmq
sub_t
(
class
ctx_t
*
parent_
,
uint32_t
tid_
);
~
sub_t
();
protected
:
int
xsetsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
);
private
:
sub_t
(
const
sub_t
&
);
...
...
src/xsub.cpp
View file @
2daa0bb4
...
...
@@ -54,24 +54,34 @@ void zmq::xsub_t::process_term (int linger_)
socket_base_t
::
process_term
(
linger_
);
}
int
zmq
::
xsub_t
::
xsetsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
)
int
zmq
::
xsub_t
::
xsend
(
zmq_msg_t
*
msg_
,
int
options_
)
{
if
(
option_
==
ZMQ_SUBSCRIBE
)
{
subscriptions
.
add
((
unsigned
char
*
)
optval_
,
optvallen_
);
return
0
;
}
if
(
option_
==
ZMQ_UNSUBSCRIBE
)
{
if
(
!
subscriptions
.
rm
((
unsigned
char
*
)
optval_
,
optvallen_
))
{
errno
=
EINVAL
;
return
-
1
;
}
return
0
;
size_t
size
=
zmq_msg_size
(
msg_
);
unsigned
char
*
data
=
(
unsigned
char
*
)
zmq_msg_data
(
msg_
);
// Malformed subscriptions are dropped silently.
if
(
size
>=
1
)
{
// Process a subscription.
if
(
*
data
==
1
)
subscriptions
.
add
(
data
+
1
,
size
-
1
);
// Process an unsubscription. Invalid unsubscription is ignored.
if
(
*
data
==
0
)
subscriptions
.
rm
(
data
+
1
,
size
-
1
);
}
errno
=
EINVAL
;
return
-
1
;
int
rc
=
zmq_msg_close
(
msg_
);
zmq_assert
(
rc
==
0
);
rc
=
zmq_msg_init
(
msg_
);
zmq_assert
(
rc
==
0
);
return
0
;
}
bool
zmq
::
xsub_t
::
xhas_out
()
{
// Subscription can be added/removed anytime.
return
true
;
}
int
zmq
::
xsub_t
::
xrecv
(
zmq_msg_t
*
msg_
,
int
flags_
)
...
...
src/xsub.hpp
View file @
2daa0bb4
...
...
@@ -41,7 +41,8 @@ namespace zmq
// Overloads of functions from socket_base_t.
void
xattach_pipes
(
class
reader_t
*
inpipe_
,
class
writer_t
*
outpipe_
,
const
blob_t
&
peer_identity_
);
int
xsetsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
);
int
xsend
(
zmq_msg_t
*
msg_
,
int
options_
);
bool
xhas_out
();
int
xrecv
(
zmq_msg_t
*
msg_
,
int
flags_
);
bool
xhas_in
();
...
...
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