Skip to content

Commit

Permalink
chore: ensure compilation across examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Dec 21, 2024
1 parent 10952bf commit abce536
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/multithread/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn hi_handler(ctx: *Context) !void {
}

fn redir_handler(ctx: *Context) !void {
ctx.response.headers.putAssumeCapacity("Location", "/hi/redirect");
ctx.response.headers.put_assume_capacity("Location", "/hi/redirect");

try ctx.respond(.{
.status = .@"Permanent Redirect",
Expand Down
2 changes: 1 addition & 1 deletion src/core/case_string_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn CaseStringMap(comptime T: type) type {
entry.item.* = .{ .key = name, .hash = name_hash, .data = data };
}

pub fn get(self: *Self, name: []const u8) ?T {
pub fn get(self: *const Self, name: []const u8) ?T {
const name_hash = hash(name);

var iter = self.pool.iterator();
Expand Down
2 changes: 1 addition & 1 deletion src/http/router/fs_dir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn FsDir(Server: type, AppState: type) type {
.{etag_hash},
);

provision.response.headers.putAssumeCapacity("ETag", calc_etag);
provision.response.headers.put_assume_capacity("ETag", calc_etag);

// If we have an ETag on the request...
if (provision.request.headers.get("If-None-Match")) |etag| {
Expand Down
4 changes: 2 additions & 2 deletions src/http/router/route.zig
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn Route(comptime Server: type, comptime AppState: type) type {
.{std.time.s_per_day * 30},
);

ctx.response.headers.putAssumeCapacity("Cache-Control", cache_control);
ctx.response.headers.put_assume_capacity("Cache-Control", cache_control);

// If our static item is greater than 1KB,
// it might be more beneficial to using caching.
Expand All @@ -177,7 +177,7 @@ pub fn Route(comptime Server: type, comptime AppState: type) type {
"\"{d}\"",
.{std.hash.Wyhash.hash(0, bytes)},
);
ctx.response.headers.putAssumeCapacity("ETag", etag[0..]);
ctx.response.headers.put_assume_capacity("ETag", etag[0..]);

if (ctx.request.headers.get("If-None-Match")) |match| {
if (std.mem.eql(u8, etag, match)) {
Expand Down
24 changes: 6 additions & 18 deletions src/http/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ pub fn Server(comptime security: Security, comptime AppState: type) type {
fn recv_task(rt: *Runtime, result: RecvResult, provision: *Provision) !void {
assert(provision.job == .recv);

const length = result.unwrap() catch |e| {
// recv_count is how many bytes we have read off the socket
const recv_count = result.unwrap() catch |e| {
if (e != error.Closed) {
log.warn("socket recv failed | {}", .{e});
}
Expand All @@ -369,18 +370,8 @@ pub fn Server(comptime security: Security, comptime AppState: type) type {

const recv_job = &provision.job.recv;

// If the socket is closed.
if (length <= 0) {
provision.job = .close;
try rt.net.close(provision, close_task, provision.socket);
return;
}

log.debug("{d} - recv triggered", .{provision.index});

// recv_count is how many bytes we have read off the socket
const recv_count: usize = @intCast(length);

// this is how many http bytes we have received
const http_bytes_count: usize = blk: {
if (comptime security == .tls) {
Expand Down Expand Up @@ -468,7 +459,7 @@ pub fn Server(comptime security: Security, comptime AppState: type) type {
try handshake_inner_task(rt, length, provision);
}

fn handshake_inner_task(rt: *Runtime, length: i32, provision: *Provision) !void {
fn handshake_inner_task(rt: *Runtime, length: usize, provision: *Provision) !void {
assert(security == .tls);
if (comptime security == .tls) {
const tls_slice = rt.storage.get("__zzz_tls_slice", []TLSType);
Expand All @@ -488,11 +479,9 @@ pub fn Server(comptime security: Security, comptime AppState: type) type {
return error.TLSHandshakeTooManyCycles;
}

const hs_length: usize = @intCast(length);

const hstate = switch (handshake_job.state) {
.recv => tls_ptr.*.?.continue_handshake(.{ .recv = @intCast(hs_length) }),
.send => tls_ptr.*.?.continue_handshake(.{ .send = @intCast(hs_length) }),
.recv => tls_ptr.*.?.continue_handshake(.{ .recv = length }),
.send => tls_ptr.*.?.continue_handshake(.{ .send = length }),
} catch |e| {
log.err("{d} - tls handshake failed={any}", .{ provision.index, e });
provision.job = .close;
Expand Down Expand Up @@ -618,7 +607,7 @@ pub fn Server(comptime security: Security, comptime AppState: type) type {
assert(provision.job == .send);
const config = rt.storage.get_const_ptr("__zzz_config", ServerConfig);

const length = result.unwrap() catch |e| {
const send_count = result.unwrap() catch |e| {
// If the socket is closed.
if (e != error.ConnectionReset) {
log.warn("socket send failed: {}", .{e});
Expand All @@ -631,7 +620,6 @@ pub fn Server(comptime security: Security, comptime AppState: type) type {
const send_job = &provision.job.send;

log.debug("{d} - send triggered", .{provision.index});
const send_count: usize = @intCast(length);
log.debug("{d} - sent length: {d}", .{ provision.index, send_count });

switch (comptime security) {
Expand Down
4 changes: 2 additions & 2 deletions src/tls/bear.zig
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,9 @@ pub const TLS = struct {

pub const HandshakeInput = union(enum) {
// this is the length of the recv to ack.
recv: u32,
recv: usize,
// this is the length of the send to ack.
send: u32,
send: usize,
};

const HandshakeState = union(enum) {
Expand Down

0 comments on commit abce536

Please sign in to comment.