Skip to content

Commit

Permalink
fixed #9
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Jul 23, 2024
1 parent c0858be commit 4270da2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn _main() !void {
\\
\\ stop stop z daemon
\\
\\v20240726 https://github.com/txthinking/z
\\v20240727 https://github.com/txthinking/z
\\
\\
;
Expand Down
78 changes: 42 additions & 36 deletions src/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -210,61 +210,67 @@ fn _handle(self: *Server, conn: std.net.Server.Connection) !void {
try self.endHandle(conn);
return;
}
if (p.value.len == 2 and std.mem.eql(u8, p.value[0], "s")) {
const id = try std.fmt.parseInt(i64, p.value[1], 10);
self.mutex.lock();
defer self.mutex.unlock();
for (self.processes.items) |v| {
if (v.id == id) {
_ = try v.process.kill();
if (p.value.len > 1 and std.mem.eql(u8, p.value[0], "s")) {
for (p.value[1..]) |v0| {
const id = try std.fmt.parseInt(i64, v0, 10);
self.mutex.lock();
defer self.mutex.unlock();
for (self.processes.items) |v| {
if (v.id == id) {
_ = try v.process.kill();
}
}
}
try self.endHandle(conn);
return;
}
if (p.value.len == 2 and std.mem.eql(u8, p.value[0], "r")) {
const id = try std.fmt.parseInt(i64, p.value[1], 10);
if (p.value.len > 1 and std.mem.eql(u8, p.value[0], "r")) {
self.mutex.lock();
defer self.mutex.unlock();
for (self.processes.items) |v| {
if (v.id == id) {
_ = try v.process.kill();
for (p.value[1..]) |v0| {
const id = try std.fmt.parseInt(i64, v0, 10);
for (self.processes.items) |v| {
if (v.id == id) {
_ = try v.process.kill();
}
}
}
std.time.sleep(2 * std.time.ns_per_s);
var cmd: ?Command = null;
for (self.commands.items) |v| {
if (v.id == id) {
cmd = v;
std.time.sleep(2 * std.time.ns_per_s);
var cmd: ?Command = null;
for (self.commands.items) |v| {
if (v.id == id) {
cmd = v;
}
}
if (cmd) |cmd1| {
const thread = try std.Thread.spawn(.{}, Server.run, .{ self, cmd1 });
thread.detach();
}
}
if (cmd) |cmd1| {
const thread = try std.Thread.spawn(.{}, Server.run, .{ self, cmd1 });
thread.detach();
}
try self.endHandle(conn);
return;
}
if (p.value.len == 2 and std.mem.eql(u8, p.value[0], "d")) {
const id = try std.fmt.parseInt(i64, p.value[1], 10);
if (p.value.len > 1 and std.mem.eql(u8, p.value[0], "d")) {
self.mutex.lock();
defer self.mutex.unlock();
for (self.processes.items) |v| {
if (v.id == id) {
_ = try v.process.kill();
for (p.value[1..]) |v0| {
const id = try std.fmt.parseInt(i64, v0, 10);
for (self.processes.items) |v| {
if (v.id == id) {
_ = try v.process.kill();
}
}
}
std.time.sleep(1 * std.time.ns_per_s);
for (self.commands.items, 0..) |v, i| {
if (v.id == id) {
const cmd = self.commands.orderedRemove(i);
for (cmd.args) |vv| {
self.allocator.free(vv);
for (self.commands.items, 0..) |v, i| {
if (v.id == id) {
const cmd = self.commands.orderedRemove(i);
for (cmd.args) |vv| {
self.allocator.free(vv);
}
self.allocator.free(cmd.args);
break;
}
self.allocator.free(cmd.args);
break;
}
}
std.time.sleep(1 * std.time.ns_per_s);
try self.saveCommands();
try self.endHandle(conn);
return;
Expand Down

0 comments on commit 4270da2

Please sign in to comment.