| ... | ... | @@ -629,13 +629,57 @@ pub const IO_Uring = struct { |
| 629 | 629 | /// An application need unregister only if it wants to register a new array of file descriptors. |
| 630 | 630 | pub fn register_files(self: *IO_Uring, fds: []const os.fd_t) !void { |
| 631 | 631 | assert(self.fd >= 0); |
| 632 | | comptime assert(@sizeOf(os.fd_t) == @sizeOf(c_int)); |
| 633 | 632 | const res = linux.io_uring_register( |
| 634 | 633 | self.fd, |
| 635 | 634 | .REGISTER_FILES, |
| 636 | 635 | @ptrCast(*const c_void, fds.ptr), |
| 637 | 636 | @intCast(u32, fds.len), |
| 638 | 637 | ); |
| 638 | try handle_registration_result(res); |
| 639 | } |
| 640 | |
| 641 | /// Registers the file descriptor for an eventfd that will be notified of completion events on |
| 642 | /// an io_uring instance. |
| 643 | /// Only a single a eventfd can be registered at any given point in time. |
| 644 | pub fn register_eventfd(self: *IO_Uring, fd: os.fd_t) !void { |
| 645 | assert(self.fd >= 0); |
| 646 | const res = linux.io_uring_register( |
| 647 | self.fd, |
| 648 | .REGISTER_EVENTFD, |
| 649 | @ptrCast(*const c_void, &fd), |
| 650 | 1, |
| 651 | ); |
| 652 | try handle_registration_result(res); |
| 653 | } |
| 654 | |
| 655 | /// Registers the file descriptor for an eventfd that will be notified of completion events on |
| 656 | /// an io_uring instance. Notifications are only posted for events that complete in an async manner. |
| 657 | /// This means that events that complete inline while being submitted do not trigger a notification event. |
| 658 | /// Only a single eventfd can be registered at any given point in time. |
| 659 | pub fn register_eventfd_async(self: *IO_Uring, fd: os.fd_t) !void { |
| 660 | assert(self.fd >= 0); |
| 661 | const res = linux.io_uring_register( |
| 662 | self.fd, |
| 663 | .REGISTER_EVENTFD_ASYNC, |
| 664 | @ptrCast(*const c_void, &fd), |
| 665 | 1, |
| 666 | ); |
| 667 | try handle_registration_result(res); |
| 668 | } |
| 669 | |
| 670 | /// Unregister the registered eventfd file descriptor. |
| 671 | pub fn unregister_eventfd(self: *IO_Uring) !void { |
| 672 | assert(self.fd >= 0); |
| 673 | const res = linux.io_uring_register( |
| 674 | self.fd, |
| 675 | .UNREGISTER_EVENTFD, |
| 676 | null, |
| 677 | 0, |
| 678 | ); |
| 679 | try handle_registration_result(res); |
| 680 | } |
| 681 | |
| 682 | fn handle_registration_result(res: usize) !void { |
| 639 | 683 | switch (linux.getErrno(res)) { |
| 640 | 684 | 0 => {}, |
| 641 | 685 | // One or more fds in the array are invalid, or the kernel does not support sparse sets: |