Skip to content

Commit

Permalink
better local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Sep 16, 2024
1 parent 7aade76 commit c672a63
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ pub const Response = struct {
}

pub fn chunk(self: *Response, data: []const u8) !void {
const conn = self.conn;
const stream = conn.stream;
const stream = self.conn.stream;
if (!self.chunked) {
self.chunked = true;
const header_buf = try self.prepareHeader();
Expand All @@ -144,7 +143,7 @@ pub const Response = struct {
.{ .len = len + 2, .base = &buf },
.{ .len = data.len, .base = data.ptr },
};
try writeAllIOVec(self.conn, &vec);
try writeAllIOVec(stream.handle, &vec);
}

pub fn clearWriter(self: *Response) void {
Expand All @@ -165,12 +164,12 @@ pub const Response = struct {
}
self.written = true;

const conn = self.conn;
const stream = self.conn.stream;
if (self.chunked) {
// If the response was chunked, then we've already written the header
// the connection is already in blocking mode, but the trailing chunk
// hasn't bene written yet. We'll write that now, and that's it.
return conn.stream.writeAll("\r\n0\r\n\r\n");
return stream.writeAll("\r\n0\r\n\r\n");
}

const header_buf = try self.prepareHeader();
Expand All @@ -183,7 +182,7 @@ pub const Response = struct {
.{ .len = body.len, .base = body.ptr },
};

try writeAllIOVec(conn, &vec);
try writeAllIOVec(stream.handle, &vec);
}

fn prepareHeader(self: *Response) ![]const u8 {
Expand Down Expand Up @@ -407,9 +406,7 @@ pub const Response = struct {
};
};

fn writeAllIOVec(conn: *HTTPConn, vec: []std.posix.iovec_const) !void {
const socket = conn.stream.handle;

fn writeAllIOVec(socket: std.posix.socket_t, vec: []std.posix.iovec_const) !void {
var i: usize = 0;
while (true) {
var n = try std.posix.writev(socket, vec[i..]);
Expand Down

0 comments on commit c672a63

Please sign in to comment.