aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-04-10 15:58:00 +0530
committerRoopesh Chander <roop@roopc.net>2019-04-10 17:57:36 +0530
commit98ebd552086e3bc5ff2c6f74bdeec80d24dfede1 (patch)
treef2bbb76d5ac7133e4d3a3d9d9c6cd3e23572a43d
parentmacOS: Log view: Stop updating the log once the log view is dismissed (diff)
downloadwireguard-apple-98ebd552086e3bc5ff2c6f74bdeec80d24dfede1.tar.xz
wireguard-apple-98ebd552086e3bc5ff2c6f74bdeec80d24dfede1.zip
Log view: Don't use a global array to store log entries
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/Shared/Logging/ringlogger.c4
-rw-r--r--WireGuard/Shared/Logging/ringlogger.h2
-rw-r--r--WireGuard/WireGuard/UI/LogViewHelper.swift14
3 files changed, 12 insertions, 8 deletions
diff --git a/WireGuard/Shared/Logging/ringlogger.c b/WireGuard/Shared/Logging/ringlogger.c
index 563483a..1edfc8d 100644
--- a/WireGuard/Shared/Logging/ringlogger.c
+++ b/WireGuard/Shared/Logging/ringlogger.c
@@ -107,7 +107,7 @@ err:
return ret;
}
-uint32_t view_lines_from_cursor(const struct log *input_log, uint32_t cursor, void(*cb)(const char *, uint64_t))
+uint32_t view_lines_from_cursor(const struct log *input_log, uint32_t cursor, void *ctx, void(*cb)(const char *, uint64_t, void *))
{
struct log *log;
uint32_t l, i = cursor;
@@ -132,7 +132,7 @@ uint32_t view_lines_from_cursor(const struct log *input_log, uint32_t cursor, vo
else
break;
}
- cb(line->line, line->time_ns);
+ cb(line->line, line->time_ns, ctx);
cursor = (i + 1) % MAX_LINES;
}
free(log);
diff --git a/WireGuard/Shared/Logging/ringlogger.h b/WireGuard/Shared/Logging/ringlogger.h
index 7f5b074..c63f3e4 100644
--- a/WireGuard/Shared/Logging/ringlogger.h
+++ b/WireGuard/Shared/Logging/ringlogger.h
@@ -11,7 +11,7 @@
struct log;
void write_msg_to_log(struct log *log, const char *tag, const char *msg);
int write_log_to_file(const char *file_name, const struct log *input_log);
-uint32_t view_lines_from_cursor(const struct log *input_log, uint32_t cursor, void(*)(const char *, uint64_t));
+uint32_t view_lines_from_cursor(const struct log *input_log, uint32_t cursor, void *ctx, void(*)(const char *, uint64_t, void *));
struct log *open_log(const char *file_name);
void close_log(struct log *log);
diff --git a/WireGuard/WireGuard/UI/LogViewHelper.swift b/WireGuard/WireGuard/UI/LogViewHelper.swift
index cadd667..1d3619b 100644
--- a/WireGuard/WireGuard/UI/LogViewHelper.swift
+++ b/WireGuard/WireGuard/UI/LogViewHelper.swift
@@ -21,7 +21,9 @@ public class LogViewHelper {
}
}
- static var logEntries = [LogEntry]()
+ class LogEntries {
+ var entries: [LogEntry] = []
+ }
init?(logFilePath: String?) {
guard let logFilePath = logFilePath else { return nil }
@@ -34,19 +36,21 @@ public class LogViewHelper {
}
func fetchLogEntriesSinceLastFetch(completion: @escaping ([LogViewHelper.LogEntry]) -> Void) {
- LogViewHelper.logEntries = []
+ var logEntries = LogEntries()
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
guard let self = self else { return }
- let newCursor = view_lines_from_cursor(self.log, self.cursor) { cStr, timestamp in
+ let newCursor = view_lines_from_cursor(self.log, self.cursor, &logEntries) { cStr, timestamp, ctx in
let message = cStr != nil ? String(cString: cStr!) : ""
let date = Date(timeIntervalSince1970: Double(timestamp) / 1000000000)
let dateString = ISO8601DateFormatter.string(from: date, timeZone: TimeZone.current, formatOptions: LogViewHelper.formatOptions)
- LogViewHelper.logEntries.append(LogEntry(timestamp: dateString, message: message))
+ if let logEntries = ctx?.bindMemory(to: LogEntries.self, capacity: 1) {
+ logEntries.pointee.entries.append(LogEntry(timestamp: dateString, message: message))
+ }
}
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
self.cursor = newCursor
- completion(LogViewHelper.logEntries)
+ completion(logEntries.entries)
}
}
}