blob: 9a4aea7cae0373eac0e75af10543bdc14a02b7dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
const is_debug = builtin.mode == .Debug;
/// This creates a debug allocator that can only be referenced in debug mode.
/// You should check for is_debug around every reference to dba.
var dba: DebugAllocator =
if (is_debug)
DebugAllocator.init
else
@compileError("Should not use debug allocator in release mode");
pub fn main() !void {
defer if (is_debug) {
_ = dba.deinit();
};
const gpa = if (is_debug) dba.allocator() else std.heap.smp_allocator;
const args = try std.process.argsAlloc(gpa);
defer std.process.argsFree(gpa, args);
var message = ArrayList(u8).init(gpa);
defer message.deinit();
for (args[1..], 0..) |arg, i| {
try message.appendSlice(arg);
if (i < args.len - 1)
try message.append(' ');
}
try Saprus.init();
defer Saprus.deinit();
// _ = try Saprus.sendInitialConnection(if (message.items.len > 0) message.items else "Hello darkness my old friend", 6868, gpa);
const res: ?SaprusMessage = Saprus.connect(if (message.items.len > 0) message.items else "Hello darkness my old friend", gpa) catch |err| switch (err) {
error.WouldBlock => null,
else => return err,
};
defer if (res) |r| r.deinit(gpa);
if (res) |r| {
std.debug.print("{s}\n", .{r.connection.payload});
} else {
std.debug.print("No response from connection request\n", .{});
}
// try Saprus.sendRelay(if (message.items.len > 0) message.items else "Hello darkness my old friend", gpa);
}
const builtin = @import("builtin");
const std = @import("std");
const DebugAllocator = std.heap.DebugAllocator(.{});
const ArrayList = std.ArrayList;
const Saprus = @import("./saprus.zig");
const SaprusMessage = Saprus.SaprusMessage;
|