-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(instead of czmq)
- Loading branch information
Showing
13 changed files
with
835 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
set -e | ||
|
||
zig build test --summary all | ||
#zig test src/zzmq.zig -lc -lzmq | ||
|
||
zig fmt . > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM alpine:3.19 as builder | ||
|
||
RUN apk add --no-cache g++ gcc cmake make musl-dev | ||
|
||
# add the pre-processed source package (note: this is not the raw source code from Git!) | ||
ADD https://github.com/zeromq/libzmq/releases/download/v4.3.5/zeromq-4.3.5.tar.gz /tmp/source.tgz | ||
|
||
WORKDIR /build | ||
|
||
RUN tar -xzf /tmp/source.tgz --strip-components=1 | ||
|
||
RUN ./configure --prefix=/build/output | ||
RUN make install | ||
|
||
|
||
|
||
# copy the build output | ||
FROM alpine:3.19 | ||
|
||
COPY --from=builder /build/output /build/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
IMAGE=zzmq_libzmq_345345345 | ||
|
||
DOCKER_BUILDKIT=1 docker build . -t $IMAGE | ||
|
||
if [ -d output ]; then | ||
rm -rf output | ||
fi | ||
|
||
mkdir -p output | ||
|
||
docker run -v "$PWD/output:/mnt" $IMAGE sh -c "cp -rf /build/output/* /mnt/ && chown $(id -u):$(id -g) -R /mnt/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const std = @import("std"); | ||
const c = @import("../zmq.zig").c; | ||
|
||
/// Version information of the `libzmq` in use. | ||
pub const ZVersion = struct { | ||
major: u16, | ||
minor: u16, | ||
patch: u16, | ||
}; | ||
|
||
/// Creates a new ZermoMQ context. | ||
/// | ||
/// Multiple contextes can exist independently, e.g. for libraries. | ||
/// | ||
/// A 0MQ 'context' is thread safe and may be shared among as many application threads as necessary, | ||
/// without any additional locking required on the part of the caller. | ||
pub const ZContext = struct { | ||
allocator_: std.mem.Allocator, | ||
ctx_: *anyopaque, | ||
|
||
pub fn init(allocator: std.mem.Allocator) !ZContext { | ||
// check the libzmq version 4.x | ||
if (ZContext.version().major != 4) { | ||
return error.LibZmqVersionMismatch; | ||
} | ||
|
||
// try creating the socket, early | ||
var s = c.zmq_ctx_new() orelse { | ||
switch (c.zmq_errno()) { | ||
c.EMFILE => return error.MaxOpenFilesExceeded, | ||
else => return error.ContextCreateFailed, | ||
} | ||
}; | ||
errdefer { | ||
c.zmq_ctx_term(s); | ||
} | ||
|
||
// done | ||
return .{ | ||
.allocator_ = allocator, | ||
.ctx_ = s, | ||
}; | ||
} | ||
|
||
/// Destroy the socket and clean up | ||
pub fn deinit(self: *ZContext) void { | ||
_ = c.zmq_ctx_term(self.ctx_); | ||
} | ||
|
||
/// Returns the version of the `libzmq` shared library. | ||
pub fn version() ZVersion { | ||
var major: c_int = undefined; | ||
var minor: c_int = undefined; | ||
var patch: c_int = undefined; | ||
|
||
c.zmq_version(&major, &minor, &patch); | ||
|
||
return .{ | ||
.major = @intCast(major), | ||
.minor = @intCast(minor), | ||
.patch = @intCast(patch), | ||
}; | ||
} | ||
}; | ||
|
||
test "ZContext - roundtrip" { | ||
const allocator = std.testing.allocator; | ||
|
||
var incoming = try ZContext.init(allocator); | ||
defer incoming.deinit(); | ||
} | ||
|
||
test "ZContext - version" { | ||
const v = ZContext.version(); | ||
|
||
std.log.info("Version: {}.{}.{}", .{ v.major, v.minor, v.patch }); | ||
|
||
try std.testing.expectEqual(@as(u16, 4), v.major); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.