tangled
alpha
login
or
join now
rockorager.dev
/
comlink
2
fork
atom
an experimental irc client
2
fork
atom
overview
issues
pulls
pipelines
ui: log connection errors to the network message view
rockorager.dev
1 year ago
b97f0d72
ff49ab89
verified
This commit was signed with the committer's
known signature
.
rockorager.dev
SSH Key Fingerprint:
SHA256:qn/Fjy7CpbcogGEPB14Y53hLnQleZNFY9lkQnuudFLs=
+36
-8
1 changed file
expand all
collapse all
unified
split
src
irc.zig
+36
-8
src/irc.zig
···
317
self.completer_shown = false;
318
319
if (std.mem.startsWith(u8, local, "/")) {
320
-
try self.client.app.handleCommand(.{ .channel = self }, local);
0
0
0
321
} else {
322
try self.client.print("PRIVMSG {s} :{s}\r\n", .{ self.name, local });
323
}
···
2687
}
2688
}
2689
2690
-
pub fn readThread(self: *Client) !void {
2691
-
defer self.status.store(.disconnected, .unordered);
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2692
0
2693
self.connect() catch |err| {
2694
-
log.warn("couldn't connect: {}", .{err});
2695
return;
2696
};
2697
-
2698
try self.queueWrite("CAP LS 302\r\n");
2699
2700
const cap_names = std.meta.fieldNames(Capabilities);
···
2717
// WouldBlock means our socket timeout expired
2718
switch (err) {
2719
error.WouldBlock => {},
2720
-
else => return err,
0
0
0
2721
}
2722
2723
if (retries == keepalive_retries) {
···
2727
}
2728
2729
if (retries == 0) {
2730
-
try self.configureKeepalive(keepalive_interval);
0
0
0
2731
}
2732
retries += 1;
2733
try self.queueWrite("PING comlink\r\n");
···
2738
// If we did a connection retry, we reset the state
2739
if (retries > 0) {
2740
retries = 0;
2741
-
try self.configureKeepalive(keepalive_idle);
0
0
0
2742
}
2743
self.read_buf_mutex.lock();
2744
defer self.read_buf_mutex.unlock();
···
317
self.completer_shown = false;
318
319
if (std.mem.startsWith(u8, local, "/")) {
320
+
self.client.app.handleCommand(.{ .channel = self }, local) catch {
321
+
log.warn("invalid command: {s}", .{input});
322
+
return;
323
+
};
324
} else {
325
try self.client.print("PRIVMSG {s} :{s}\r\n", .{ self.name, local });
326
}
···
2690
}
2691
}
2692
2693
+
fn warn(self: *Client, comptime fmt: []const u8, args: anytype) void {
2694
+
self.read_buf.appendSlice(":comlink WARN ") catch {};
2695
+
self.read_buf.writer().print(fmt, args) catch {};
2696
+
self.read_buf.appendSlice("\r\n") catch {};
2697
+
}
2698
+
2699
+
pub fn readThread(self: *Client) void {
2700
+
defer self.status.store(.disconnected, .release);
2701
+
2702
+
// We push this off to another function that can enforces it only fails for allocation
2703
+
// errors
2704
+
self._readThread() catch |err| {
2705
+
switch (err) {
2706
+
error.OutOfMemory => {},
2707
+
}
2708
+
log.err("out of memory", .{});
2709
+
};
2710
+
}
2711
2712
+
fn _readThread(self: *Client) Allocator.Error!void {
2713
self.connect() catch |err| {
2714
+
self.warn("* CONNECTION_ERROR :Error while connecting to server: {}", .{err});
2715
return;
2716
};
0
2717
try self.queueWrite("CAP LS 302\r\n");
2718
2719
const cap_names = std.meta.fieldNames(Capabilities);
···
2736
// WouldBlock means our socket timeout expired
2737
switch (err) {
2738
error.WouldBlock => {},
2739
+
else => {
2740
+
self.warn("* CONNECTION_ERROR :{}", .{err});
2741
+
return;
2742
+
},
2743
}
2744
2745
if (retries == keepalive_retries) {
···
2749
}
2750
2751
if (retries == 0) {
2752
+
self.configureKeepalive(keepalive_interval) catch |err2| {
2753
+
self.warn("* INTERNAL_ERROR :Couldn't configure socket: {}", .{err2});
2754
+
return;
2755
+
};
2756
}
2757
retries += 1;
2758
try self.queueWrite("PING comlink\r\n");
···
2763
// If we did a connection retry, we reset the state
2764
if (retries > 0) {
2765
retries = 0;
2766
+
self.configureKeepalive(keepalive_idle) catch |err2| {
2767
+
self.warn("* INTERNAL_ERROR :Couldn't configure socket: {}", .{err2});
2768
+
return;
2769
+
};
2770
}
2771
self.read_buf_mutex.lock();
2772
defer self.read_buf_mutex.unlock();