forked from karlseguin/http.zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc44e87
commit 48a98a4
Showing
4 changed files
with
288 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const std = @import("std"); | ||
|
||
const Self = @This(); | ||
|
||
pub const Conn = struct { | ||
stream: std.net.Stream, | ||
last_request: i64, | ||
address: std.net.Address, | ||
next: ?*Conn = null, | ||
prev: ?*Conn = null, | ||
|
||
pub const List = Self.List; | ||
}; | ||
|
||
const List = struct { | ||
len: usize = 0, | ||
head: ?*Conn = null, | ||
tail: ?*Conn = null, | ||
|
||
pub fn insert(self: *List, node: *Conn) void { | ||
if (self.tail) |tail| { | ||
tail.next = node; | ||
node.prev = tail; | ||
self.tail = node; | ||
} else { | ||
self.head = node; | ||
self.tail = node; | ||
} | ||
self.len += 1; | ||
node.next = null; | ||
} | ||
|
||
pub fn remove(self: *List, node: *Conn) void { | ||
if (node.prev) |prev| { | ||
prev.next = node.next; | ||
} else { | ||
self.head = node.next; | ||
} | ||
|
||
if (node.next) |next| { | ||
next.prev = node.prev; | ||
} else { | ||
self.tail = node.prev; | ||
} | ||
self.len -= 1; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.