Skip to content

Commit 26cbc3c

Browse files
authored
Merge pull request #32 from bernardassan/zig-0.15.2
Update Supported Zig Version to 0.15.2
2 parents d4a0f9b + edd54c2 commit 26cbc3c

File tree

17 files changed

+77
-70
lines changed

17 files changed

+77
-70
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v5
1919
- uses: mlugg/setup-zig@v2
2020
with:
21-
version: 0.15.1
21+
version: 0.15.2
2222
- name: Build Examples
2323
run: zig build -Dexample=all
2424
- name: Run unit tests
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v5
3636
- uses: mlugg/setup-zig@v2
3737
with:
38-
version: 0.15.1
38+
version: 0.15.2
3939
- name: Generate random 64-bit integer
4040
id: random
4141
shell: bash
@@ -54,7 +54,7 @@ jobs:
5454
- uses: actions/checkout@v5
5555
- uses: mlugg/setup-zig@v2
5656
with:
57-
version: 0.15.1
57+
version: 0.15.2
5858
- name: Generate random 64-bit integer
5959
id: random
6060
shell: bash
@@ -70,7 +70,7 @@ jobs:
7070
- uses: actions/checkout@v5
7171
- uses: mlugg/setup-zig@v2
7272
with:
73-
version: 0.15.1
73+
version: 0.15.2
7474
- name: Generate random 64-bit integer
7575
id: random
7676
shell: pwsh

README.md

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tardy is a thread-local, I/O driven runtime for Zig, providing the core implemen
1717
- Coroutines (internally called Frames).
1818

1919
## Installing
20-
Compatible Zig Version: `0.14.0`
20+
Compatible Zig Version: `0.15.2`
2121

2222
Latest Release: `0.3.0`
2323
```
@@ -60,72 +60,82 @@ A basic multi-threaded TCP echo server.
6060

6161
```zig
6262
const std = @import("std");
63-
const log = std.log.scoped(.@"tardy/example/echo");
6463
64+
const AcceptResult = @import("tardy").AcceptResult;
65+
const Cross = @import("tardy").Cross;
6566
const Pool = @import("tardy").Pool;
67+
const RecvResult = @import("tardy").RecvResult;
6668
const Runtime = @import("tardy").Runtime;
67-
const Task = @import("tardy").Task;
68-
const Tardy = @import("tardy").Tardy(.auto);
69-
const Cross = @import("tardy").Cross;
70-
69+
const SendResult = @import("tardy").SendResult;
7170
const Socket = @import("tardy").Socket;
71+
const Task = @import("tardy").Task;
7272
const Timer = @import("tardy").Timer;
7373
74-
const AcceptResult = @import("tardy").AcceptResult;
75-
const RecvResult = @import("tardy").RecvResult;
76-
const SendResult = @import("tardy").SendResult;
74+
const Tardy = @import("tardy").Tardy(.auto);
75+
const log = std.log.scoped(.@"tardy/example/echo");
7776
7877
fn echo_frame(rt: *Runtime, server: *const Socket) !void {
7978
const socket = try server.accept(rt);
8079
defer socket.close_blocking();
8180
82-
// you can use the standard Zig Reader/Writer if you want!
83-
const reader = socket.reader(rt);
84-
const writer = socket.writer(rt);
81+
var sock_reader = socket.reader(rt, &.{});
82+
const sock_r = &sock_reader.interface;
83+
84+
var sock_writer = socket.writer(rt, &.{});
85+
const sock_w = &sock_writer.interface;
86+
defer sock_w.flush() catch unreachable;
8587
8688
log.debug(
87-
"{d} - accepted socket [{}]",
89+
"{d} - accepted socket [{f}]",
8890
.{ std.time.milliTimestamp(), socket.addr },
8991
);
9092
93+
// spawn off a new frame.
9194
try rt.spawn(.{ rt, server }, echo_frame, 1024 * 16);
9295
93-
var buffer: [1024]u8 = undefined;
96+
var buffer: [501]u8 = undefined;
9497
while (true) {
95-
const recv_length = reader.read(&buffer) catch |e| {
96-
log.err("Failed to recv on socket | {}", .{e});
97-
return;
98+
const recv_length = sock_r.readSliceShort(&buffer) catch |e| {
99+
log.err("Failed to recv on socket | {t}", .{e});
100+
break;
98101
};
99102
100-
writer.writeAll(buffer[0..recv_length]) catch |e| {
101-
log.err("Failed to send on socket | {}", .{e});
102-
return;
103+
if (recv_length == 0) return;
104+
105+
sock_w.writeAll(buffer[0..recv_length]) catch |e| {
106+
log.err("Failed to send on socket | {t}", .{e});
107+
break;
103108
};
104109
105110
log.debug("Echoed: {s}", .{buffer[0..recv_length]});
106111
}
107112
}
108113
109114
pub fn main() !void {
110-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
115+
var gpa: std.heap.DebugAllocator(.{}) = .init;
111116
const allocator = gpa.allocator();
112117
defer _ = gpa.deinit();
113118
114-
// tardy by default is
115-
// - multithreaded
116-
// - unbounded in terms of spawnable tasks
117-
var tardy = try Tardy.init(allocator, .{});
119+
var tardy: Tardy = try .init(allocator, .{
120+
.threading = .single,
121+
.pooling = .static,
122+
.size_tasks_initial = 256,
123+
.size_aio_reap_max = 256,
124+
});
118125
defer tardy.deinit();
119126
120-
const server = try Socket.init(.{ .tcp = .{ .host = "127.0.0.1", .port = 9862 } });
127+
const host = "0.0.0.0";
128+
const port = 9862;
129+
130+
const server: Socket = try .init(.{ .tcp = .{ .host = host, .port = port } });
121131
try server.bind();
122-
try server.listen(256);
132+
try server.listen(1024);
123133
124134
try tardy.entry(
125135
&server,
126136
struct {
127137
fn start(rt: *Runtime, tcp_server: *const Socket) !void {
128-
try rt.spawn(.{ rt, tcp_server }, echo_frame, 1024 * 1024 * 4);
138+
try rt.spawn(.{ rt, tcp_server }, echo_frame, 1024 * 16);
129139
}
130140
}.start,
131141
);
@@ -143,7 +153,7 @@ We use Nix Flakes for managing the development environment. Nix Flakes provide a
143153

144154
### Prerequisites
145155
- Install [Nix](https://nixos.org/download/)
146-
```bash
156+
```bash
147157
sh <(curl -L https://nixos.org/nix/install) --daemon
148158
```
149159
- Enable [Flake support](https://nixos.wiki/wiki/Flakes) in your Nix config (`~/.config/nix/nix.conf`): `experimental-features = nix-command flakes`

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const builtin = @import("builtin");
44

55
const AsyncKind = @import("src/aio/lib.zig").AsyncKind;
66

7-
const zig_version = std.SemanticVersion{ .major = 0, .minor = 15, .patch = 1 };
7+
const zig_version = std.SemanticVersion{ .major = 0, .minor = 15, .patch = 2 };
88
comptime {
99
// Compare versions while allowing different pre/patch metadata.
1010
const zig_version_eq = zig_version.major == builtin.zig_version.major and

build.zig.zon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
.name = .tardy,
33
.fingerprint = 0x36d7fa71822bdceb,
44
.version = "0.3.0",
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.15.2",
66
.dependencies = .{},
7-
87
.paths = .{
98
"README.md",
109
"LICENSE",

examples/basic/main.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ fn log_frame(rt: *Runtime) !void {
1717
}
1818

1919
pub fn main() !void {
20-
const allocator = std.heap.page_allocator;
20+
var gpa: std.heap.DebugAllocator(.{}) = .init;
21+
const allocator = gpa.allocator();
22+
defer _ = gpa.deinit();
2123

2224
var tardy: Tardy = try .init(allocator, .{
2325
.threading = .single,

examples/echo/main.zig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@ fn echo_frame(rt: *Runtime, server: *const Socket) !void {
3232
// spawn off a new frame.
3333
try rt.spawn(.{ rt, server }, echo_frame, 1024 * 16);
3434

35-
//TODO: investigate why using readSliceShort with a buffer bigger
36-
// than reader size leads to a connection reset (try to get a repro)
3735
var buffer: [501]u8 = undefined;
3836
while (true) {
3937
const recv_length = sock_r.readSliceShort(&buffer) catch |e| {
4038
log.err("Failed to recv on socket | {t}", .{e});
4139
break;
4240
};
4341

44-
if (recv_length == 0) {
45-
break;
46-
}
42+
if (recv_length == 0) return;
4743

4844
sock_w.writeAll(buffer[0..recv_length]) catch |e| {
4945
log.err("Failed to send on socket | {t}", .{e});

src/aio/apis/epoll.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub const AsyncEpoll = struct {
4646
const events = try allocator.alloc(std.os.linux.epoll_event, options.size_aio_reap_max);
4747
errdefer allocator.free(events);
4848

49-
var jobs = try Pool(Job).init(allocator, size, options.pooling);
49+
var jobs: Pool(Job) = try .init(allocator, size, options.pooling);
5050
errdefer jobs.deinit();
5151

5252
// Queue the wake task.
@@ -65,7 +65,7 @@ pub const AsyncEpoll = struct {
6565

6666
try std.posix.epoll_ctl(epoll_fd, std.os.linux.EPOLL.CTL_ADD, wake_event_fd, &event);
6767

68-
return AsyncEpoll{
68+
return .{
6969
.epoll_fd = epoll_fd,
7070
.wake_event_fd = wake_event_fd,
7171
.events = events,
@@ -463,7 +463,7 @@ pub const AsyncEpoll = struct {
463463
pub fn to_async(self: *AsyncEpoll) Async {
464464
return Async{
465465
.runner = self,
466-
.features = AsyncFeatures.init(&.{
466+
.features = .init(&.{
467467
.timer,
468468
.accept,
469469
.connect,

src/aio/apis/io_uring.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub const AsyncIoUring = struct {
116116
const uring = try allocator.create(std.os.linux.IoUring);
117117
errdefer allocator.destroy(uring);
118118

119-
uring.* = try std.os.linux.IoUring.init_params(submit_size, &params);
119+
uring.* = try .init_params(submit_size, &params);
120120
errdefer uring.deinit();
121121

122122
break :blk uring;
@@ -125,7 +125,7 @@ pub const AsyncIoUring = struct {
125125
const uring = try allocator.create(std.os.linux.IoUring);
126126
errdefer allocator.destroy(uring);
127127

128-
uring.* = try std.os.linux.IoUring.init(submit_size, base_flags);
128+
uring.* = try .init(submit_size, base_flags);
129129
errdefer uring.deinit();
130130

131131
break :blk uring;
@@ -134,7 +134,7 @@ pub const AsyncIoUring = struct {
134134
errdefer allocator.destroy(uring);
135135
errdefer uring.deinit();
136136

137-
var jobs = try Pool(JobBundle).init(allocator, size, options.pooling);
137+
var jobs: Pool(JobBundle) = try .init(allocator, size, options.pooling);
138138
errdefer jobs.deinit();
139139

140140
const index = jobs.borrow_assume_unset(0);

src/aio/apis/kqueue.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub const AsyncKqueue = struct {
4242

4343
const events = try allocator.alloc(std.posix.Kevent, options.size_aio_reap_max);
4444
const changes = try allocator.alloc(std.posix.Kevent, options.size_aio_reap_max);
45-
var jobs = try Pool(Job).init(allocator, options.size_tasks_initial + 1, options.pooling);
45+
var jobs: Pool(Job) = try .init(allocator, options.size_tasks_initial + 1, options.pooling);
4646

4747
const index = jobs.borrow_assume_unset(0);
4848
const item = jobs.get_ptr(index);
@@ -503,7 +503,7 @@ pub const AsyncKqueue = struct {
503503
pub fn to_async(self: *AsyncKqueue) Async {
504504
return Async{
505505
.runner = self,
506-
.features = AsyncFeatures.init(&.{
506+
.features = .init(&.{
507507
.timer,
508508
.accept,
509509
.connect,

src/aio/apis/poll.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub const AsyncPoll = struct {
5353
const server_socket = try std.posix.socket(std.posix.AF.INET, std.posix.SOCK.STREAM, 0);
5454
defer std.posix.close(server_socket);
5555

56-
const addr = std.net.Address.initIp4(.{ 127, 0, 0, 1 }, 0);
56+
const addr: std.net.Address = .initIp4(.{ 127, 0, 0, 1 }, 0);
5757
try std.posix.bind(server_socket, &addr.any, addr.getOsSockLen());
5858

5959
var binded_addr: std.posix.sockaddr = undefined;
@@ -89,10 +89,10 @@ pub const AsyncPoll = struct {
8989
try fd_job_map.put(pipe[0], .{ .index = 0, .type = .wake, .task = 0 });
9090
}
9191

92-
const timers = TimerQueue.init(allocator, {});
92+
const timers: TimerQueue = .init(allocator, {});
9393
errdefer timers.deinit();
9494

95-
return AsyncPoll{
95+
return .{
9696
.allocator = allocator,
9797
.wake_pipe = pipe,
9898
.fd_list = fd_list,
@@ -405,7 +405,7 @@ pub const AsyncPoll = struct {
405405
pub fn to_async(self: *AsyncPoll) Async {
406406
return Async{
407407
.runner = self,
408-
.features = AsyncFeatures.init(&.{
408+
.features = .init(&.{
409409
.timer,
410410
.accept,
411411
.connect,

0 commit comments

Comments
 (0)