Skip to content

notcancername/zlzmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zlzmq

  • Tight Zig wrapper or bindings to libzmq, with some minimal helpers.
  • For a more high-level API, see zzmq.

Using from Zig

$ zig fetch --save 'git+https://github.com/notcancername/zlzmq#master'
const zlzmq_dep = b.dependency("zlzmq", .{});
exe.root_module.addImport("zlzmq", zlzmq_dep.module("zlzmq"));

Vendoring libzmq

To vendor and statically link libzmq, you can use notcancername/libzmq. See that for features and libraries you might want. Note that this is a security risk since it makes updates impossible without recompiling.

$ zig fetch --save 'git+https://github.com/notcancername/libzmq#master'
const libzmq_dep = b.dependency("libzmq", .{ .target = target, .optimize = .optimize, .shared = false });
const libzmq = libzmq_dep.artifact("libzmq");
exe.linkLibrary(libzmq);

Basic mappings

  • Context: used by zmq_ctx_* functions
  • Socket: used by all functions that operate on sockets
  • Message: zmq_msg_t
  • z85: functions that deal with Z85
  • curve: functions for dealing with ZMQ_CURVE authentication and encryption

Echo server

const zmq = @import("zlzmq");

pub fn main() !void {
    const ctx = try zmq.Context.init();
    defer ctx.deinit();

    const rep = try ctx.socket(.rep);
    defer rep.close();

    while (true) {
        var buf: [128]u8 = undefined;
        const len = try rep.recv(&buf, .{});
        if (std.mem.eql(u8, buf[0..len], "quit")) break;
        try rep.send(buf[0..len], .{});
    }
}

About

thin libzmq wrapper for Zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages