mirror of
https://git.robbyzambito.me/zits
synced 2026-02-04 03:34:48 +00:00
some cleanup and freeing
This commit is contained in:
@@ -68,9 +68,8 @@ pub const ClientState = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if the value was put in the clients buffer to process, else false.
|
/// Return true if the value was put in the clients buffer to process, else false.
|
||||||
pub fn send(self: *ClientState, io: std.Io, msg: Message) (std.Io.Cancelable || std.Io.QueueClosedError)!bool {
|
pub fn send(self: *ClientState, io: std.Io, msg: Message) (std.Io.Cancelable || std.Io.QueueClosedError)!void {
|
||||||
try self.recv_queue.putOne(io, msg);
|
try self.recv_queue.putOne(io, msg);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(self: *ClientState, allocator: std.mem.Allocator) !Message {
|
pub fn next(self: *ClientState, allocator: std.mem.Allocator) !Message {
|
||||||
|
|||||||
@@ -111,22 +111,35 @@ fn handleConnection(
|
|||||||
switch (msg) {
|
switch (msg) {
|
||||||
.ping => {
|
.ping => {
|
||||||
// Respond to ping with pong.
|
// Respond to ping with pong.
|
||||||
for (0..5) |_| {
|
try client_state.send(io, .pong);
|
||||||
if (try client_state.send(io, .pong)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {}
|
|
||||||
},
|
},
|
||||||
.@"pub" => |@"pub"| {
|
.@"pub" => |pb| {
|
||||||
try server.publishMessage(io, @"pub");
|
defer {
|
||||||
|
allocator.free(pb.payload);
|
||||||
|
allocator.free(pb.subject);
|
||||||
|
if (pb.reply_to) |r| {
|
||||||
|
allocator.free(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try server.publishMessage(io, pb);
|
||||||
if (client_state.connect.connect.verbose) {
|
if (client_state.connect.connect.verbose) {
|
||||||
_ = try client_state.send(io, .@"+ok");
|
try client_state.send(io, .@"+ok");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.sub => |sub| {
|
.sub => |sub| {
|
||||||
|
defer {
|
||||||
|
allocator.free(sub.subject);
|
||||||
|
allocator.free(sub.sid);
|
||||||
|
if (sub.queue_group) |q| {
|
||||||
|
allocator.free(q);
|
||||||
|
}
|
||||||
|
}
|
||||||
try server.subscribe(allocator, id, sub);
|
try server.subscribe(allocator, id, sub);
|
||||||
},
|
},
|
||||||
.unsub => |unsub| {
|
.unsub => |unsub| {
|
||||||
|
defer {
|
||||||
|
allocator.free(unsub.sid);
|
||||||
|
}
|
||||||
try server.unsubscribe(id, unsub);
|
try server.unsubscribe(id, unsub);
|
||||||
},
|
},
|
||||||
else => |e| {
|
else => |e| {
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ pub const Message = union(MessageType) {
|
|||||||
// Parse byte count
|
// Parse byte count
|
||||||
const byte_count = blk: {
|
const byte_count = blk: {
|
||||||
var byte_count_list: std.ArrayList(u8) = try .initCapacity(alloc, 64);
|
var byte_count_list: std.ArrayList(u8) = try .initCapacity(alloc, 64);
|
||||||
|
defer byte_count_list.deinit(alloc);
|
||||||
while (in.peekByte()) |byte| {
|
while (in.peekByte()) |byte| {
|
||||||
if (std.ascii.isWhitespace(byte)) {
|
if (std.ascii.isWhitespace(byte)) {
|
||||||
try expectStreamBytes(in, "\r\n");
|
try expectStreamBytes(in, "\r\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user