Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

operate

Private Function
std.Io.Threaded.operate
fn operate(userdata: ?*anyopaque, operation: Io.Operation) Io.Cancelable!Io.Operation.Result

Params

  • userdata: ?*anyopaque
  • operation: Io.Operation

File

Io/Threaded.zig:2534
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
fn operate(userdata: ?*anyopaque, operation: Io.Operation) Io.Cancelable!Io.Operation.Result {
    const t: *Threaded = @ptrCast(@alignCast(userdata));
    switch (operation) {
        .file_read_streaming => |o| return .{
            .file_read_streaming = fileReadStreaming(t, o.file, o.data) catch |err| switch (err) {
                error.Canceled => |e| return e,
                else => |e| e,
            },
        },
        .file_write_streaming => |o| return .{
            .file_write_streaming = fileWriteStreaming(t, o.file, o.header, o.data, o.splat) catch |err| switch (err) {
                error.Canceled => |e| return e,
                else => |e| e,
            },
        },
        .device_io_control => |*o| return .{ .device_io_control = try deviceIoControl(o) },
        .net_receive => |*o| return .{ .net_receive = o: {
            if (!have_networking) break :o .{ error.NetworkDown, 0 };
            if (is_windows) break :o netReceiveWindows(t, o.socket_handle, o.message_buffer, o.data_buffer, o.flags);
            netReceivePosix(o.socket_handle, &o.message_buffer[0], o.data_buffer, o.flags, false) catch |err| switch (err) {
                error.Canceled => |e| return e,
                error.WouldBlock => unreachable,
                else => |e| break :o .{ e, 0 },
            };
            break :o .{ null, 1 };
        } },
        .net_send => |*o| return .{
            .net_send = o: {
                if (!have_networking) break :o .{ error.NetworkDown, 0 };
                if (is_windows) break :o netSendWindows(t, o.socket_handle, o.messages, o.flags);
                const send_err, const sent = netSendPosix(t, o.socket_handle, o.messages, o.flags, false);
                if (send_err) |err| switch (err) {
                    error.Canceled => |e| if (sent == 0) {
                        return e;
                    } else {
                        // Leave the `error.Canceled` for later, but don't try to send any more messages.
                        recancelInner();
                        break :o .{ null, sent };
                    },
                    error.WouldBlock => unreachable,
                    else => |e| break :o .{ e, sent },
                };
                break :o .{ null, sent };
            },
        },
        .net_read => |o| return .{
            .net_read = netRead(o.socket_handle, o.data) catch |err| switch (err) {
                error.Canceled => |e| return e,
                else => |e| e,
            },
        },
        .net_write => |o| return .{
            .net_write = (if (is_windows)
                netWriteWindows(o.socket_handle, o.header, o.data, o.splat)
            else
                netWritePosix(o.socket_handle, o.header, o.data, o.splat)) catch |err| switch (err) {
                error.Canceled => |e| return e,
                else => |e| e,
            },
        },
    }
}