Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Subscribe to ZSocketOption #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/classes/zsocket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ pub const ZSocketOption = union(enum) {
///
/// For more details, see https://libzmq.readthedocs.io/en/latest/zmq_setsockopt.html
RouterHandover: bool,

/// ZMQ_SUBSCRIBE: Establish message filter
///
/// The 'ZMQ_SUBSCRIBE' option shall establish a new message filter on a 'ZMQ_SUB' socket.
/// Newly created 'ZMQ_SUB' sockets shall filter out all incoming messages, therefore you should
/// call this option to establish an initial message filter.
///
/// An empty 'option_value' of length zero shall subscribe to all incoming messages.
/// A non-empty 'option_value' shall subscribe to all messages beginning with the specified prefix.
/// Multiple filters may be attached to a single 'ZMQ_SUB' socket,
/// in which case a message shall be accepted if it matches at least one filter.
Subscribe: []const u8,
};

/// System level socket, which allows for opening outgoing and
Expand Down Expand Up @@ -544,7 +556,9 @@ pub const ZSocket = struct {

result = c.zmq_setsockopt(self.socket_, c.ZMQ_ROUTER_HANDOVER, &v, @sizeOf(@TypeOf(v)));
},

.Subscribe => {
result = c.zmq_setsockopt(self.socket_, c.ZMQ_SUBSCRIBE, opt.Subscribe.ptr, opt.Subscribe.len);
},
//else => return error.UnknownOption,
}

Expand Down Expand Up @@ -608,7 +622,9 @@ pub const ZSocket = struct {
.RouterHandover => {
return error.UnknownOption; // ZMQ_ROUTER_HANDOVER cannot be retrieved
},

.Subscribe => {
return error.UnknownOption; //ZMQ_SUBSCRIBE cannot be retrieved
},
//else => return error.UnknownOption,
}

Expand Down
Loading