| ... | @@ -529,7 +529,7 @@ test "sendmsg/recvmsg" { | ... | @@ -529,7 +529,7 @@ test "sendmsg/recvmsg" { |
| 529 | .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), | 529 | .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), |
| 530 | }; | 530 | }; |
| 531 | | 531 | |
| 532 | const server = try posix.socket(address_server.family, posix.SOCK.DGRAM, 0); | 532 | const server = try socket(address_server.family, posix.SOCK.DGRAM, 0); |
| 533 | defer posix.close(server); | 533 | defer posix.close(server); |
| 534 | try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEPORT, &mem.toBytes(@as(c_int, 1))); | 534 | try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEPORT, &mem.toBytes(@as(c_int, 1))); |
| 535 | try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); | 535 | try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); |
| ... | @@ -539,7 +539,7 @@ test "sendmsg/recvmsg" { | ... | @@ -539,7 +539,7 @@ test "sendmsg/recvmsg" { |
| 539 | var slen: posix.socklen_t = @sizeOf(linux.sockaddr.in); | 539 | var slen: posix.socklen_t = @sizeOf(linux.sockaddr.in); |
| 540 | try posix.getsockname(server, addrAny(&address_server), &slen); | 540 | try posix.getsockname(server, addrAny(&address_server), &slen); |
| 541 | | 541 | |
| 542 | const client = try posix.socket(address_server.family, posix.SOCK.DGRAM, 0); | 542 | const client = try socket(address_server.family, posix.SOCK.DGRAM, 0); |
| 543 | defer posix.close(client); | 543 | defer posix.close(client); |
| 544 | | 544 | |
| 545 | const buffer_send = [_]u8{42} ** 128; | 545 | const buffer_send = [_]u8{42} ** 128; |
| ... | @@ -1033,7 +1033,7 @@ test "shutdown" { | ... | @@ -1033,7 +1033,7 @@ test "shutdown" { |
| 1033 | | 1033 | |
| 1034 | // Socket bound, expect shutdown to work | 1034 | // Socket bound, expect shutdown to work |
| 1035 | { | 1035 | { |
| 1036 | const server = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1036 | const server = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1037 | defer posix.close(server); | 1037 | defer posix.close(server); |
| 1038 | try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); | 1038 | try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); |
| 1039 | try posix.bind(server, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 1039 | try posix.bind(server, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| ... | @@ -1066,7 +1066,7 @@ test "shutdown" { | ... | @@ -1066,7 +1066,7 @@ test "shutdown" { |
| 1066 | | 1066 | |
| 1067 | // Socket not bound, expect to fail with ENOTCONN | 1067 | // Socket not bound, expect to fail with ENOTCONN |
| 1068 | { | 1068 | { |
| 1069 | const server = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1069 | const server = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1070 | defer posix.close(server); | 1070 | defer posix.close(server); |
| 1071 | | 1071 | |
| 1072 | const shutdown_sqe = ring.shutdown(0x445445445, server, linux.SHUT.RD) catch |err| switch (err) { | 1072 | const shutdown_sqe = ring.shutdown(0x445445445, server, linux.SHUT.RD) catch |err| switch (err) { |
| ... | @@ -1753,7 +1753,7 @@ test "accept multishot" { | ... | @@ -1753,7 +1753,7 @@ test "accept multishot" { |
| 1753 | var nr: usize = 4; // number of clients to connect | 1753 | var nr: usize = 4; // number of clients to connect |
| 1754 | while (nr > 0) : (nr -= 1) { | 1754 | while (nr > 0) : (nr -= 1) { |
| 1755 | // connect client | 1755 | // connect client |
| 1756 | const client = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1756 | const client = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1757 | errdefer posix.close(client); | 1757 | errdefer posix.close(client); |
| 1758 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 1758 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| 1759 | | 1759 | |
| ... | @@ -1862,7 +1862,7 @@ test "accept_direct" { | ... | @@ -1862,7 +1862,7 @@ test "accept_direct" { |
| 1862 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | 1862 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1863 | | 1863 | |
| 1864 | // connect | 1864 | // connect |
| 1865 | const client = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1865 | const client = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1866 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 1866 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| 1867 | defer posix.close(client); | 1867 | defer posix.close(client); |
| 1868 | | 1868 | |
| ... | @@ -1896,7 +1896,7 @@ test "accept_direct" { | ... | @@ -1896,7 +1896,7 @@ test "accept_direct" { |
| 1896 | _ = try ring.accept_direct(accept_userdata, listener_socket, null, null, 0); | 1896 | _ = try ring.accept_direct(accept_userdata, listener_socket, null, null, 0); |
| 1897 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | 1897 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1898 | // connect | 1898 | // connect |
| 1899 | const client = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1899 | const client = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1900 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 1900 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| 1901 | defer posix.close(client); | 1901 | defer posix.close(client); |
| 1902 | // completion with error | 1902 | // completion with error |
| ... | @@ -1946,7 +1946,7 @@ test "accept_multishot_direct" { | ... | @@ -1946,7 +1946,7 @@ test "accept_multishot_direct" { |
| 1946 | | 1946 | |
| 1947 | for (registered_fds) |_| { | 1947 | for (registered_fds) |_| { |
| 1948 | // connect | 1948 | // connect |
| 1949 | const client = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1949 | const client = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1950 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 1950 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| 1951 | defer posix.close(client); | 1951 | defer posix.close(client); |
| 1952 | | 1952 | |
| ... | @@ -1961,7 +1961,7 @@ test "accept_multishot_direct" { | ... | @@ -1961,7 +1961,7 @@ test "accept_multishot_direct" { |
| 1961 | // Multishot is terminated (more flag is not set). | 1961 | // Multishot is terminated (more flag is not set). |
| 1962 | { | 1962 | { |
| 1963 | // connect | 1963 | // connect |
| 1964 | const client = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 1964 | const client = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 1965 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 1965 | try posix.connect(client, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| 1966 | defer posix.close(client); | 1966 | defer posix.close(client); |
| 1967 | // completion with error | 1967 | // completion with error |
| ... | @@ -2617,7 +2617,7 @@ pub fn createSocketTestHarness(ring: *IoUring) !SocketTestHarness { | ... | @@ -2617,7 +2617,7 @@ pub fn createSocketTestHarness(ring: *IoUring) !SocketTestHarness { |
| 2617 | _ = try ring.accept(0xaaaaaaaa, listener_socket, &accept_addr, &accept_addr_len, 0); | 2617 | _ = try ring.accept(0xaaaaaaaa, listener_socket, &accept_addr, &accept_addr_len, 0); |
| 2618 | | 2618 | |
| 2619 | // Create a TCP client socket | 2619 | // Create a TCP client socket |
| 2620 | const client = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 2620 | const client = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 2621 | errdefer posix.close(client); | 2621 | errdefer posix.close(client); |
| 2622 | _ = try ring.connect(0xcccccccc, client, addrAny(&address), @sizeOf(linux.sockaddr.in)); | 2622 | _ = try ring.connect(0xcccccccc, client, addrAny(&address), @sizeOf(linux.sockaddr.in)); |
| 2623 | | 2623 | |
| ... | @@ -2657,7 +2657,7 @@ pub fn createSocketTestHarness(ring: *IoUring) !SocketTestHarness { | ... | @@ -2657,7 +2657,7 @@ pub fn createSocketTestHarness(ring: *IoUring) !SocketTestHarness { |
| 2657 | | 2657 | |
| 2658 | fn createListenerSocket(address: *linux.sockaddr.in) !posix.socket_t { | 2658 | fn createListenerSocket(address: *linux.sockaddr.in) !posix.socket_t { |
| 2659 | const kernel_backlog = 1; | 2659 | const kernel_backlog = 1; |
| 2660 | const listener_socket = try posix.socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); | 2660 | const listener_socket = try socket(address.family, posix.SOCK.STREAM | posix.SOCK.CLOEXEC, 0); |
| 2661 | errdefer posix.close(listener_socket); | 2661 | errdefer posix.close(listener_socket); |
| 2662 | | 2662 | |
| 2663 | try posix.setsockopt(listener_socket, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); | 2663 | try posix.setsockopt(listener_socket, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(c_int, 1))); |
| ... | @@ -2695,3 +2695,11 @@ inline fn skipKernelLessThan(required: std.SemanticVersion) !void { | ... | @@ -2695,3 +2695,11 @@ inline fn skipKernelLessThan(required: std.SemanticVersion) !void { |
| 2695 | fn addrAny(addr: *linux.sockaddr.in) *linux.sockaddr { | 2695 | fn addrAny(addr: *linux.sockaddr.in) *linux.sockaddr { |
| 2696 | return @ptrCast(addr); | 2696 | return @ptrCast(addr); |
| 2697 | } | 2697 | } |
| | 2698 | |
| | 2699 | fn socket(domain: u32, socket_type: u32, protocol: u32) !posix.socket_t { |
| | 2700 | const rc = posix.system.socket(domain, socket_type, protocol); |
| | 2701 | switch (posix.errno(rc)) { |
| | 2702 | .SUCCESS => return @intCast(rc), |
| | 2703 | else => return error.SocketCreationFailure, |
| | 2704 | } |
| | 2705 | } |