diff options
Diffstat (limited to 'src/replica.zig')
| -rw-r--r-- | src/replica.zig | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/replica.zig b/src/replica.zig index 1499d166..b88b1328 100644 --- a/src/replica.zig +++ b/src/replica.zig @@ -56,17 +56,6 @@ const unit_head = head_len + 16; pub const Unit = struct { origin: u16, seq: u32, real_ns: i64 = 0, mono_ns: i64 = 0, tape: []const u8 }; -pub fn parseUnit(msg: []const u8) ?Unit { - if (msg.len < unit_head) return null; - return .{ - .origin = std.mem.readInt(u16, msg[0..2], .little), - .seq = std.mem.readInt(u32, msg[2..6], .little), - .real_ns = std.mem.readInt(i64, msg[6..14], .little), - .mono_ns = std.mem.readInt(i64, msg[14..22], .little), - .tape = msg[unit_head..], - }; -} - fn clockNs(id: std.c.clockid_t) i64 { var ts: std.c.timespec = undefined; if (std.c.clock_gettime(id, &ts) != 0) return 0; @@ -626,6 +615,17 @@ const Pending = struct { seq: u32, msg: []u8, spec: ?[]u8 = null, sent_ns: u64 = /// units it shows, so those before it are not replayed over it. const View = struct { at: ?usize = null, after: usize = 0 }; +pub fn parseUnit(msg: []const u8) ?Unit { + if (msg.len < unit_head) return null; + return .{ + .origin = std.mem.readInt(u16, msg[0..2], .little), + .seq = std.mem.readInt(u32, msg[2..6], .little), + .real_ns = std.mem.readInt(i64, msg[6..14], .little), + .mono_ns = std.mem.readInt(i64, msg[14..22], .little), + .tape = msg[unit_head..], + }; +} + pub const Replica = struct { gpa: Allocator, id: u16, @@ -1484,17 +1484,6 @@ pub const Framer = struct { } }; -/// The process at the other end of unix socket `fd` (Linux's SO_PEERCRED), -/// or 0: a client's through ssh is ssh's. -fn peerPid(fd: c_int) libc.pid_t { - if (comptime builtin.os.tag != .linux) return 0; - const Cred = extern struct { pid: libc.pid_t, uid: libc.uid_t, gid: libc.gid_t }; - var cred: Cred = undefined; - var len: libc.socklen_t = @sizeOf(Cred); - if (libc.getsockopt(fd, libc.SOL.SOCKET, libc.SO.PEERCRED, &cred, &len) != 0) return 0; - return cred.pid; -} - pub const Peer = struct { peers: *Peers, fd: c_int, @@ -1814,6 +1803,17 @@ pub fn dying() void { }; } +/// The process at the other end of unix socket `fd` (Linux's SO_PEERCRED), +/// or 0: a client's through ssh is ssh's. +fn peerPid(fd: c_int) libc.pid_t { + if (comptime builtin.os.tag != .linux) return 0; + const Cred = extern struct { pid: libc.pid_t, uid: libc.uid_t, gid: libc.gid_t }; + var cred: Cred = undefined; + var len: libc.socklen_t = @sizeOf(Cred); + if (libc.getsockopt(fd, libc.SOL.SOCKET, libc.SO.PEERCRED, &cred, &len) != 0) return 0; + return cred.pid; +} + pub const Peers = struct { gpa: Allocator = std.heap.c_allocator, io: std.Io = undefined, |
