| ... | @@ -457,6 +457,22 @@ pub const IO_Uring = struct { | ... | @@ -457,6 +457,22 @@ pub const IO_Uring = struct { |
| 457 | return sqe; | 457 | return sqe; |
| 458 | } | 458 | } |
| 459 | | 459 | |
| | 460 | /// Queues (but does not submit) an SQE to perform a `epoll_ctl(2)`. |
| | 461 | /// Returns a pointer to the SQE. |
| | 462 | pub fn epoll_ctl( |
| | 463 | self: *IO_Uring, |
| | 464 | user_data: u64, |
| | 465 | epfd: os.fd_t, |
| | 466 | fd: os.fd_t, |
| | 467 | op: u32, |
| | 468 | ev: ?*linux.epoll_event, |
| | 469 | ) !*io_uring_sqe { |
| | 470 | const sqe = try self.get_sqe(); |
| | 471 | io_uring_prep_epoll_ctl(sqe, epfd, fd, op, ev); |
| | 472 | sqe.user_data = user_data; |
| | 473 | return sqe; |
| | 474 | } |
| | 475 | |
| 460 | /// Queues (but does not submit) an SQE to perform a `recv(2)`. | 476 | /// Queues (but does not submit) an SQE to perform a `recv(2)`. |
| 461 | /// Returns a pointer to the SQE. | 477 | /// Returns a pointer to the SQE. |
| 462 | pub fn recv( | 478 | pub fn recv( |
| ... | @@ -558,6 +574,33 @@ pub const IO_Uring = struct { | ... | @@ -558,6 +574,33 @@ pub const IO_Uring = struct { |
| 558 | return sqe; | 574 | return sqe; |
| 559 | } | 575 | } |
| 560 | | 576 | |
| | 577 | /// Queues (but does not submit) an SQE to perform a `poll(2)`. |
| | 578 | /// Returns a pointer to the SQE. |
| | 579 | pub fn poll_add( |
| | 580 | self: *IO_Uring, |
| | 581 | user_data: u64, |
| | 582 | fd: os.fd_t, |
| | 583 | poll_mask: u32, |
| | 584 | ) !*io_uring_sqe { |
| | 585 | const sqe = try self.get_sqe(); |
| | 586 | io_uring_prep_poll_add(sqe, fd, poll_mask); |
| | 587 | sqe.user_data = user_data; |
| | 588 | return sqe; |
| | 589 | } |
| | 590 | |
| | 591 | /// Queues (but does not submit) an SQE to remove an existing poll operation. |
| | 592 | /// Returns a pointer to the SQE. |
| | 593 | pub fn poll_remove( |
| | 594 | self: *IO_Uring, |
| | 595 | user_data: u64, |
| | 596 | target_user_data: u64, |
| | 597 | ) !*io_uring_sqe { |
| | 598 | const sqe = try self.get_sqe(); |
| | 599 | io_uring_prep_poll_remove(sqe, target_user_data); |
| | 600 | sqe.user_data = user_data; |
| | 601 | return sqe; |
| | 602 | } |
| | 603 | |
| 561 | /// Queues (but does not submit) an SQE to perform an `fallocate(2)`. | 604 | /// Queues (but does not submit) an SQE to perform an `fallocate(2)`. |
| 562 | /// Returns a pointer to the SQE. | 605 | /// Returns a pointer to the SQE. |
| 563 | pub fn fallocate( | 606 | pub fn fallocate( |
| ... | @@ -776,7 +819,7 @@ pub fn io_uring_prep_rw( | ... | @@ -776,7 +819,7 @@ pub fn io_uring_prep_rw( |
| 776 | op: linux.IORING_OP, | 819 | op: linux.IORING_OP, |
| 777 | sqe: *io_uring_sqe, | 820 | sqe: *io_uring_sqe, |
| 778 | fd: os.fd_t, | 821 | fd: os.fd_t, |
| 779 | addr: anytype, | 822 | addr: u64, |
| 780 | len: usize, | 823 | len: usize, |
| 781 | offset: u64, | 824 | offset: u64, |
| 782 | ) void { | 825 | ) void { |
| ... | @@ -786,7 +829,7 @@ pub fn io_uring_prep_rw( | ... | @@ -786,7 +829,7 @@ pub fn io_uring_prep_rw( |
| 786 | .ioprio = 0, | 829 | .ioprio = 0, |
| 787 | .fd = fd, | 830 | .fd = fd, |
| 788 | .off = offset, | 831 | .off = offset, |
| 789 | .addr = @ptrToInt(addr), | 832 | .addr = addr, |
| 790 | .len = @intCast(u32, len), | 833 | .len = @intCast(u32, len), |
| 791 | .rw_flags = 0, | 834 | .rw_flags = 0, |
| 792 | .user_data = 0, | 835 | .user_data = 0, |
| ... | @@ -798,11 +841,11 @@ pub fn io_uring_prep_rw( | ... | @@ -798,11 +841,11 @@ pub fn io_uring_prep_rw( |
| 798 | } | 841 | } |
| 799 | | 842 | |
| 800 | pub fn io_uring_prep_read(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []u8, offset: u64) void { | 843 | pub fn io_uring_prep_read(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []u8, offset: u64) void { |
| 801 | io_uring_prep_rw(.READ, sqe, fd, buffer.ptr, buffer.len, offset); | 844 | io_uring_prep_rw(.READ, sqe, fd, @ptrToInt(buffer.ptr), buffer.len, offset); |
| 802 | } | 845 | } |
| 803 | | 846 | |
| 804 | pub fn io_uring_prep_write(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []const u8, offset: u64) void { | 847 | pub fn io_uring_prep_write(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []const u8, offset: u64) void { |
| 805 | io_uring_prep_rw(.WRITE, sqe, fd, buffer.ptr, buffer.len, offset); | 848 | io_uring_prep_rw(.WRITE, sqe, fd, @ptrToInt(buffer.ptr), buffer.len, offset); |
| 806 | } | 849 | } |
| 807 | | 850 | |
| 808 | pub fn io_uring_prep_readv( | 851 | pub fn io_uring_prep_readv( |
| ... | @@ -811,7 +854,7 @@ pub fn io_uring_prep_readv( | ... | @@ -811,7 +854,7 @@ pub fn io_uring_prep_readv( |
| 811 | iovecs: []const os.iovec, | 854 | iovecs: []const os.iovec, |
| 812 | offset: u64, | 855 | offset: u64, |
| 813 | ) void { | 856 | ) void { |
| 814 | io_uring_prep_rw(.READV, sqe, fd, iovecs.ptr, iovecs.len, offset); | 857 | io_uring_prep_rw(.READV, sqe, fd, @ptrToInt(iovecs.ptr), iovecs.len, offset); |
| 815 | } | 858 | } |
| 816 | | 859 | |
| 817 | pub fn io_uring_prep_writev( | 860 | pub fn io_uring_prep_writev( |
| ... | @@ -820,7 +863,7 @@ pub fn io_uring_prep_writev( | ... | @@ -820,7 +863,7 @@ pub fn io_uring_prep_writev( |
| 820 | iovecs: []const os.iovec_const, | 863 | iovecs: []const os.iovec_const, |
| 821 | offset: u64, | 864 | offset: u64, |
| 822 | ) void { | 865 | ) void { |
| 823 | io_uring_prep_rw(.WRITEV, sqe, fd, iovecs.ptr, iovecs.len, offset); | 866 | io_uring_prep_rw(.WRITEV, sqe, fd, @ptrToInt(iovecs.ptr), iovecs.len, offset); |
| 824 | } | 867 | } |
| 825 | | 868 | |
| 826 | pub fn io_uring_prep_accept( | 869 | pub fn io_uring_prep_accept( |
| ... | @@ -832,7 +875,7 @@ pub fn io_uring_prep_accept( | ... | @@ -832,7 +875,7 @@ pub fn io_uring_prep_accept( |
| 832 | ) void { | 875 | ) void { |
| 833 | // `addr` holds a pointer to `sockaddr`, and `addr2` holds a pointer to socklen_t`. | 876 | // `addr` holds a pointer to `sockaddr`, and `addr2` holds a pointer to socklen_t`. |
| 834 | // `addr2` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32). | 877 | // `addr2` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32). |
| 835 | io_uring_prep_rw(.ACCEPT, sqe, fd, addr, 0, @ptrToInt(addrlen)); | 878 | io_uring_prep_rw(.ACCEPT, sqe, fd, @ptrToInt(addr), 0, @ptrToInt(addrlen)); |
| 836 | sqe.rw_flags = flags; | 879 | sqe.rw_flags = flags; |
| 837 | } | 880 | } |
| 838 | | 881 | |
| ... | @@ -843,16 +886,26 @@ pub fn io_uring_prep_connect( | ... | @@ -843,16 +886,26 @@ pub fn io_uring_prep_connect( |
| 843 | addrlen: os.socklen_t, | 886 | addrlen: os.socklen_t, |
| 844 | ) void { | 887 | ) void { |
| 845 | // `addrlen` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32). | 888 | // `addrlen` maps to `sqe.off` (u64) instead of `sqe.len` (which is only a u32). |
| 846 | io_uring_prep_rw(.CONNECT, sqe, fd, addr, 0, addrlen); | 889 | io_uring_prep_rw(.CONNECT, sqe, fd, @ptrToInt(addr), 0, addrlen); |
| | 890 | } |
| | 891 | |
| | 892 | pub fn io_uring_prep_epoll_ctl( |
| | 893 | sqe: *io_uring_sqe, |
| | 894 | epfd: os.fd_t, |
| | 895 | fd: os.fd_t, |
| | 896 | op: u32, |
| | 897 | ev: ?*linux.epoll_event, |
| | 898 | ) void { |
| | 899 | io_uring_prep_rw(.EPOLL_CTL, sqe, epfd, @ptrToInt(ev), op, @intCast(u64, fd)); |
| 847 | } | 900 | } |
| 848 | | 901 | |
| 849 | pub fn io_uring_prep_recv(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []u8, flags: u32) void { | 902 | pub fn io_uring_prep_recv(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []u8, flags: u32) void { |
| 850 | io_uring_prep_rw(.RECV, sqe, fd, buffer.ptr, buffer.len, 0); | 903 | io_uring_prep_rw(.RECV, sqe, fd, @ptrToInt(buffer.ptr), buffer.len, 0); |
| 851 | sqe.rw_flags = flags; | 904 | sqe.rw_flags = flags; |
| 852 | } | 905 | } |
| 853 | | 906 | |
| 854 | pub fn io_uring_prep_send(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []const u8, flags: u32) void { | 907 | pub fn io_uring_prep_send(sqe: *io_uring_sqe, fd: os.fd_t, buffer: []const u8, flags: u32) void { |
| 855 | io_uring_prep_rw(.SEND, sqe, fd, buffer.ptr, buffer.len, 0); | 908 | io_uring_prep_rw(.SEND, sqe, fd, @ptrToInt(buffer.ptr), buffer.len, 0); |
| 856 | sqe.rw_flags = flags; | 909 | sqe.rw_flags = flags; |
| 857 | } | 910 | } |
| 858 | | 911 | |
| ... | @@ -863,7 +916,7 @@ pub fn io_uring_prep_openat( | ... | @@ -863,7 +916,7 @@ pub fn io_uring_prep_openat( |
| 863 | flags: u32, | 916 | flags: u32, |
| 864 | mode: os.mode_t, | 917 | mode: os.mode_t, |
| 865 | ) void { | 918 | ) void { |
| 866 | io_uring_prep_rw(.OPENAT, sqe, fd, path, mode, 0); | 919 | io_uring_prep_rw(.OPENAT, sqe, fd, @ptrToInt(path), mode, 0); |
| 867 | sqe.rw_flags = flags; | 920 | sqe.rw_flags = flags; |
| 868 | } | 921 | } |
| 869 | | 922 | |
| ... | @@ -891,7 +944,7 @@ pub fn io_uring_prep_timeout( | ... | @@ -891,7 +944,7 @@ pub fn io_uring_prep_timeout( |
| 891 | count: u32, | 944 | count: u32, |
| 892 | flags: u32, | 945 | flags: u32, |
| 893 | ) void { | 946 | ) void { |
| 894 | io_uring_prep_rw(.TIMEOUT, sqe, -1, ts, 1, count); | 947 | io_uring_prep_rw(.TIMEOUT, sqe, -1, @ptrToInt(ts), 1, count); |
| 895 | sqe.rw_flags = flags; | 948 | sqe.rw_flags = flags; |
| 896 | } | 949 | } |
| 897 | | 950 | |
| ... | @@ -913,6 +966,22 @@ pub fn io_uring_prep_timeout_remove(sqe: *io_uring_sqe, timeout_user_data: u64, | ... | @@ -913,6 +966,22 @@ pub fn io_uring_prep_timeout_remove(sqe: *io_uring_sqe, timeout_user_data: u64, |
| 913 | }; | 966 | }; |
| 914 | } | 967 | } |
| 915 | | 968 | |
| | 969 | pub fn io_uring_prep_poll_add( |
| | 970 | sqe: *io_uring_sqe, |
| | 971 | fd: os.fd_t, |
| | 972 | poll_mask: u32, |
| | 973 | ) void { |
| | 974 | io_uring_prep_rw(.POLL_ADD, sqe, fd, @ptrToInt(@as(?*c_void, null)), 0, 0); |
| | 975 | sqe.rw_flags = std.mem.nativeToLittle(u32, poll_mask); |
| | 976 | } |
| | 977 | |
| | 978 | pub fn io_uring_prep_poll_remove( |
| | 979 | sqe: *io_uring_sqe, |
| | 980 | target_user_data: u64, |
| | 981 | ) void { |
| | 982 | io_uring_prep_rw(.POLL_REMOVE, sqe, -1, target_user_data, 0, 0); |
| | 983 | } |
| | 984 | |
| 916 | pub fn io_uring_prep_fallocate( | 985 | pub fn io_uring_prep_fallocate( |
| 917 | sqe: *io_uring_sqe, | 986 | sqe: *io_uring_sqe, |
| 918 | fd: os.fd_t, | 987 | fd: os.fd_t, |