Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/app/basic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const SimpleEndpoint = struct {
.{ context.db_connection, e.some_data, arena.ptr, thread_id },
);
try r.sendBody(response_text);
std.Thread.sleep(std.time.ns_per_ms * 300);
std.posix.nanosleep(0, 300 * std.time.ns_per_ms);
}
};

Expand Down
4 changes: 3 additions & 1 deletion examples/http_params/http_params.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub const std_options: std.Options = .{

// We send ourselves a request
fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
var http_client: std.http.Client = .{ .allocator = a };
var thread: std.Io.Threaded = .init(a);
defer thread.deinit();
var http_client: std.http.Client = .{ .allocator = a, .io = thread.io() };
defer http_client.deinit();

const response = try http_client.fetch(.{
Expand Down
8 changes: 4 additions & 4 deletions src/request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ pub fn _internal_sendError(self: *const Request, err: anyerror, err_trace: ?std.
// TODO: let's hope 20k is enough. Maybe just really allocate here
self.h.*.status = errorcode_num;
var buf: [20 * 1024]u8 = undefined;
var writer = std.io.Writer.fixed(&buf);
var writer = std.Io.Writer.fixed(&buf);
try writer.print("ERROR: {any}\n\n", .{err});


if (err_trace) |trace| {
const debugInfo = try std.debug.getSelfDebugInfo();
const ttyConfig: std.io.tty.Config = .no_color;
try std.debug.writeStackTrace(trace, &writer, debugInfo, ttyConfig);
const ttyConfig: std.Io.tty.Config = .no_color;
try std.debug.writeStackTrace(&trace, &writer, ttyConfig);
}

try self.sendBody(writer.buffered());
Expand Down
8 changes: 5 additions & 3 deletions src/tests/test_auth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ const ClientAuthReqHeaderFields = struct {
};

fn makeRequest(a: std.mem.Allocator, url: []const u8, auth: ?ClientAuthReqHeaderFields) !void {
var http_client: std.http.Client = .{ .allocator = a };
var thread: std.Io.Threaded = .init(a);
defer thread.deinit();
var http_client: std.http.Client = .{ .allocator = a, .io = thread.io() };
defer http_client.deinit();

var auth_buf: [256]u8 = undefined;
Expand Down Expand Up @@ -154,15 +156,15 @@ pub const Endpoint = struct {
pub fn get(_: *Endpoint, r: zap.Request) !void {
r.sendBody(HTTP_RESPONSE) catch return;
received_response = HTTP_RESPONSE;
std.Thread.sleep(1 * std.time.ns_per_s);
std.posix.nanosleep(1,0);
zap.stop();
}

pub fn unauthorized(_: *Endpoint, r: zap.Request) !void {
r.setStatus(.unauthorized);
r.sendBody("UNAUTHORIZED ACCESS") catch return;
received_response = "UNAUTHORIZED";
std.Thread.sleep(1 * std.time.ns_per_s);
std.posix.nanosleep(1, 0);
zap.stop();
}
};
Expand Down
4 changes: 3 additions & 1 deletion src/tests/test_http_params.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub const std_options: std.Options = .{
};

fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
var http_client: std.http.Client = .{ .allocator = a };
var thread: std.Io.Threaded = .init(a);
defer thread.deinit();
var http_client: std.http.Client = .{ .allocator = a, .io = thread.io() };
defer http_client.deinit();

_ = try http_client.fetch(.{
Expand Down
4 changes: 3 additions & 1 deletion src/tests/test_recvfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const EXPECTED_FILENAME = "myfile.txt";
var test_error: ?anyerror = null;

fn makeRequest(allocator: std.mem.Allocator, url: []const u8) !void {
var http_client: std.http.Client = .{ .allocator = allocator };
var thread: std.Io.Threaded = .init(allocator);
defer thread.deinit();
var http_client: std.http.Client = .{ .allocator = allocator, .io = thread.io() };
defer http_client.deinit();

const payload_wrong_line_ending = try std.fmt.allocPrint(allocator,
Expand Down
4 changes: 3 additions & 1 deletion src/tests/test_recvfile_notype.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const EXPECTED_FILENAME = "myfile.txt";
var test_error: ?anyerror = null;

fn makeRequest(allocator: std.mem.Allocator, url: []const u8) !void {
var http_client: std.http.Client = .{ .allocator = allocator };
var thread: std.Io.Threaded = .init(allocator);
defer thread.deinit();
var http_client: std.http.Client = .{ .allocator = allocator, .io = thread.io() };
defer http_client.deinit();

const payload_wrong_line_ending = try std.fmt.allocPrint(allocator,
Expand Down
6 changes: 4 additions & 2 deletions src/tests/test_sendfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ var read_len: ?usize = null;
const testfile = @embedFile("testfile.txt");

fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
var http_client: std.http.Client = .{ .allocator = a };
var thread: std.Io.Threaded = .init(a);
defer thread.deinit();
var http_client: std.http.Client = .{ .allocator = a, .io = thread.io() };
defer http_client.deinit();

var response_writer = std.io.Writer.Allocating.init(a);
var response_writer = std.Io.Writer.Allocating.init(a);
defer response_writer.deinit();

_ = try http_client.fetch(.{
Expand Down
2 changes: 1 addition & 1 deletion src/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn stringifyBuf(
value: anytype,
options: std.json.Stringify.Options,
) ![]const u8 {
var w: std.io.Writer = .fixed(buffer);
var w: std.Io.Writer = .fixed(buffer);
if (std.json.Stringify.value(value, options, &w)) {
return w.buffered();
} else |err| { // error
Expand Down
2 changes: 1 addition & 1 deletion src/zap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub const HttpListener = struct {
// in debug2 and debug3 of hello example
// std.debug.print("X\n", .{});
// TODO: still happening?
std.Thread.sleep(500 * std.time.ns_per_ms);
std.posix.nanosleep(0, 500 * std.time.ns_per_ms);

var portbuf: [100]u8 = undefined;
const printed_port = try std.fmt.bufPrintZ(&portbuf, "{d}", .{self.settings.port});
Expand Down
4 changes: 2 additions & 2 deletions tools/announceybot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn sendToDiscord(allocator: std.mem.Allocator, url: []const u8, message: []const
// max size: 100kB
const buf: []u8 = try allocator.alloc(u8, 100 * 1024);
defer allocator.free(buf);
var w: std.io.Writer = .fixed(buf);
var w: std.Io.Writer = .fixed(buf);
try std.json.Stringify.value(.{ .content = message }, .{}, &w);
const string = w.buffered();

Expand Down Expand Up @@ -263,7 +263,7 @@ fn sendToDiscord(allocator: std.mem.Allocator, url: []const u8, message: []const
const desc = chunks.items[it];
const part = message[desc.from..desc.to];

var ww: std.io.Writer = .fixed(buf);
var ww: std.Io.Writer = .fixed(buf);
try std.json.Stringify.value(.{ .content = part }, .{}, &ww);
const part_string = ww.buffered();

Expand Down
Loading