Fix ConnectionServer
This commit is contained in:
parent
053de35d33
commit
fd27199813
1 changed files with 15 additions and 2 deletions
|
@ -17,8 +17,21 @@ pub const ConnectionServer = struct {
|
|||
next_conn_id: std.atomic.Atomic(Connection.Id) = std.atomic.Atomic(Connection.Id).init(1),
|
||||
handler: Handler,
|
||||
|
||||
// todo accept is a bad name
|
||||
pub fn accept(self: *ConnectionServer, stream: std.net.Stream, address: std.net.Address) void {
|
||||
pub fn run(self: *ConnectionServer, addr: std.net.Address) noreturn {
|
||||
var srv = std.net.StreamServer.init(.{ .reuse_address = true });
|
||||
defer srv.deinit();
|
||||
|
||||
try srv.listen(addr);
|
||||
|
||||
while (true) {
|
||||
const conn = try srv.accept();
|
||||
self.handle(conn.stream, conn.address);
|
||||
}
|
||||
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn handle(self: *ConnectionServer, stream: std.net.Stream, address: std.net.Address) void {
|
||||
const conn = Connection{
|
||||
.id = self.next_conn_id.fetchAdd(1, .SeqCst),
|
||||
.address = address,
|
||||
|
|
Loading…
Reference in a new issue