diff --git a/examples/app/basic.zig b/examples/app/basic.zig index d59b062..e41ccfc 100644 --- a/examples/app/basic.zig +++ b/examples/app/basic.zig @@ -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); } }; diff --git a/examples/http_params/http_params.zig b/examples/http_params/http_params.zig index 512ec22..bcfc228 100644 --- a/examples/http_params/http_params.zig +++ b/examples/http_params/http_params.zig @@ -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(.{ diff --git a/src/request.zig b/src/request.zig index 8ddb904..572750c 100644 --- a/src/request.zig +++ b/src/request.zig @@ -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()); diff --git a/src/tests/test_auth.zig b/src/tests/test_auth.zig index ec87be2..67bf772 100644 --- a/src/tests/test_auth.zig +++ b/src/tests/test_auth.zig @@ -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; @@ -154,7 +156,7 @@ 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(); } @@ -162,7 +164,7 @@ pub const Endpoint = struct { 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(); } }; diff --git a/src/tests/test_http_params.zig b/src/tests/test_http_params.zig index eefb76e..5a3db60 100644 --- a/src/tests/test_http_params.zig +++ b/src/tests/test_http_params.zig @@ -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(.{ diff --git a/src/tests/test_recvfile.zig b/src/tests/test_recvfile.zig index e2da327..875d601 100644 --- a/src/tests/test_recvfile.zig +++ b/src/tests/test_recvfile.zig @@ -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, diff --git a/src/tests/test_recvfile_notype.zig b/src/tests/test_recvfile_notype.zig index aa4162c..9f0ab72 100644 --- a/src/tests/test_recvfile_notype.zig +++ b/src/tests/test_recvfile_notype.zig @@ -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, diff --git a/src/tests/test_sendfile.zig b/src/tests/test_sendfile.zig index f13cbdd..5b6bfc7 100644 --- a/src/tests/test_sendfile.zig +++ b/src/tests/test_sendfile.zig @@ -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(.{ diff --git a/src/util.zig b/src/util.zig index 27e86d8..3c82a6d 100644 --- a/src/util.zig +++ b/src/util.zig @@ -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 diff --git a/src/zap.zig b/src/zap.zig index 4e20ddd..984d629 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -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}); diff --git a/tools/announceybot.zig b/tools/announceybot.zig index 9fa8b96..4c331b9 100644 --- a/tools/announceybot.zig +++ b/tools/announceybot.zig @@ -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(); @@ -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();