-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And re-organize some methods based on that change
- Loading branch information
1 parent
4f3571c
commit f9c33c0
Showing
3 changed files
with
69 additions
and
61 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,46 @@ | ||
const std = @import("std"); | ||
const sig = @import("../../sig.zig"); | ||
|
||
const connection = @import("connection.zig"); | ||
const requests = @import("requests.zig"); | ||
|
||
const ServerCtx = sig.rpc.server.Context; | ||
|
||
pub const AcceptAndServeConnectionError = | ||
connection.AcceptHandledError || | ||
connection.SetSocketSync || | ||
std.mem.Allocator.Error || | ||
std.http.Server.ReceiveHeadError || | ||
requests.HandleRequestError; | ||
|
||
pub fn acceptAndServeConnection(server_ctx: *ServerCtx) !void { | ||
const conn = connection.acceptHandled( | ||
server_ctx.tcp, | ||
.blocking, | ||
) catch |err| switch (err) { | ||
error.WouldBlock => return, | ||
else => |e| return e, | ||
}; | ||
defer conn.stream.close(); | ||
|
||
if (!connection.have_accept4) { | ||
// make sure the accepted socket is in blocking mode | ||
try connection.setSocketSync(conn.stream.handle, .blocking); | ||
} | ||
|
||
server_ctx.wait_group.start(); | ||
defer server_ctx.wait_group.finish(); | ||
|
||
const buffer = try server_ctx.allocator.alloc(u8, server_ctx.read_buffer_size); | ||
defer server_ctx.allocator.free(buffer); | ||
|
||
var http_server = std.http.Server.init(conn, buffer); | ||
var request = try http_server.receiveHead(); | ||
|
||
try requests.handleRequest( | ||
server_ctx.logger, | ||
&request, | ||
server_ctx.snapshot_dir, | ||
server_ctx.latest_snapshot_gen_info, | ||
); | ||
} |
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