mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
x/os, x/net, os:, fix typos/errors, add missing constants/docs
Add missing constants to ws2_32 such as SIO_BASE_HANDLE. Made all declared constants in ws2_32 comptime_int, and fixed a few broken constants (i.e. GUID's). Fixed a few syscalls not having callconv(WINAPI) in ws2_32. Fixed a typo in std.x.net.tcp.Client. Removed unnecessary @alignCast's for socket addresses in std.x.net.Socket. Added a warning on using timeout methods for std.x.net.Socket. Fixed compilation error spotted by CI in std.os that references std.os.windows.ws2_32.SD_RECEIVE. Renamed std.x.os.Socket.setOption()'s parameter `name: u32` to `code: u32`.
This commit is contained in:
parent
a24101be5b
commit
3d946ef5eb
@ -2758,9 +2758,9 @@ pub const ShutdownHow = enum { recv, send, both };
|
||||
pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
|
||||
if (builtin.os.tag == .windows) {
|
||||
const result = windows.ws2_32.shutdown(sock, switch (how) {
|
||||
.recv => windows.SD_RECEIVE,
|
||||
.send => windows.SD_SEND,
|
||||
.both => windows.SD_BOTH,
|
||||
.recv => windows.ws2_32.SD_RECEIVE,
|
||||
.send => windows.ws2_32.SD_SEND,
|
||||
.both => windows.ws2_32.SD_BOTH,
|
||||
});
|
||||
if (0 != result) switch (windows.ws2_32.WSAGetLastError()) {
|
||||
.WSAECONNABORTED => return error.ConnectionAborted,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -150,7 +150,7 @@ pub const Client = struct {
|
||||
/// Read multiple I/O vectors with a prepended message header from the socket
|
||||
/// with a set of flags specified. It returns the number of bytes that were
|
||||
/// read into the buffer provided.
|
||||
pub fn readVectorized(self: cLIENT, msg: *os.msghdr, flags: u32) !usize {
|
||||
pub fn readVectorized(self: Client, msg: *os.msghdr, flags: u32) !usize {
|
||||
return self.socket.readVectorized(msg, flags);
|
||||
}
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ pub const Socket = struct {
|
||||
var address_len: u32 = @sizeOf(os.sockaddr_storage);
|
||||
|
||||
const socket = Socket{ .fd = try os.accept(self.fd, @ptrCast(*os.sockaddr, &address), &address_len, flags) };
|
||||
const socket_address = Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
|
||||
const socket_address = Socket.Address.fromNative(@ptrCast(*os.sockaddr, &address));
|
||||
|
||||
return Socket.Connection.from(socket, socket_address);
|
||||
}
|
||||
@ -95,7 +95,7 @@ pub const Socket = struct {
|
||||
var address: os.sockaddr_storage = undefined;
|
||||
var address_len: u32 = @sizeOf(os.sockaddr_storage);
|
||||
try os.getsockname(self.fd, @ptrCast(*os.sockaddr, &address), &address_len);
|
||||
return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
|
||||
return Socket.Address.fromNative(@ptrCast(*os.sockaddr, &address));
|
||||
}
|
||||
|
||||
/// Query the address that the socket is connected to.
|
||||
@ -103,7 +103,7 @@ pub const Socket = struct {
|
||||
var address: os.sockaddr_storage = undefined;
|
||||
var address_len: u32 = @sizeOf(os.sockaddr_storage);
|
||||
try os.getpeername(self.fd, @ptrCast(*os.sockaddr, &address), &address_len);
|
||||
return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
|
||||
return Socket.Address.fromNative(@ptrCast(*os.sockaddr, &address));
|
||||
}
|
||||
|
||||
/// Query and return the latest cached error on the socket.
|
||||
@ -146,8 +146,8 @@ pub const Socket = struct {
|
||||
}
|
||||
|
||||
/// Set a socket option.
|
||||
pub fn setOption(self: Socket, level: u32, name: u32, value: []const u8) !void {
|
||||
return os.setsockopt(self.fd, level, name, value);
|
||||
pub fn setOption(self: Socket, level: u32, code: u32, value: []const u8) !void {
|
||||
return os.setsockopt(self.fd, level, code, value);
|
||||
}
|
||||
|
||||
/// Have close() or shutdown() syscalls block until all queued messages in the socket have been successfully
|
||||
@ -208,6 +208,9 @@ pub const Socket = struct {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&size));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
/// set on a non-blocking socket.
|
||||
///
|
||||
/// Set a timeout on the socket that is to occur if no messages are successfully written
|
||||
/// to its bound destination after a specified number of milliseconds. A subsequent write
|
||||
/// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
|
||||
@ -220,6 +223,9 @@ pub const Socket = struct {
|
||||
return self.setOption(os.SOL_SOCKET, os.SO_SNDTIMEO, mem.asBytes(&timeout));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
/// set on a non-blocking socket.
|
||||
///
|
||||
/// Set a timeout on the socket that is to occur if no messages are successfully read
|
||||
/// from its bound destination after a specified number of milliseconds. A subsequent
|
||||
/// read from the socket will thereafter return `error.WouldBlock` should the timeout be
|
||||
|
||||
@ -24,7 +24,7 @@ pub const Socket = struct {
|
||||
pub fn init(domain: u32, socket_type: u32, protocol: u32) !Socket {
|
||||
var filtered_socket_type = socket_type & ~@as(u32, os.SOCK_CLOEXEC);
|
||||
|
||||
var filtered_flags = ws2_32.WSA_FLAG_OVERLAPPED;
|
||||
var filtered_flags: u32 = ws2_32.WSA_FLAG_OVERLAPPED;
|
||||
if (socket_type & os.SOCK_CLOEXEC != 0) {
|
||||
filtered_flags |= ws2_32.WSA_FLAG_NO_HANDLE_INHERIT;
|
||||
}
|
||||
@ -169,7 +169,7 @@ pub const Socket = struct {
|
||||
}
|
||||
|
||||
const socket = Socket.from(rc);
|
||||
const socket_address = Socket.Address.fromNative(@alignCast(4, @ptrCast(*ws2_32.sockaddr, &address)));
|
||||
const socket_address = Socket.Address.fromNative(@ptrCast(*ws2_32.sockaddr, &address));
|
||||
|
||||
return Socket.Connection.from(socket, socket_address);
|
||||
}
|
||||
@ -275,7 +275,7 @@ pub const Socket = struct {
|
||||
};
|
||||
}
|
||||
|
||||
return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
|
||||
return Socket.Address.fromNative(@ptrCast(*os.sockaddr, &address));
|
||||
}
|
||||
|
||||
/// Query the address that the socket is connected to.
|
||||
@ -295,7 +295,7 @@ pub const Socket = struct {
|
||||
};
|
||||
}
|
||||
|
||||
return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
|
||||
return Socket.Address.fromNative(@ptrCast(*os.sockaddr, &address));
|
||||
}
|
||||
|
||||
/// Query and return the latest cached error on the socket.
|
||||
@ -314,8 +314,8 @@ pub const Socket = struct {
|
||||
}
|
||||
|
||||
/// Set a socket option.
|
||||
pub fn setOption(self: Socket, level: u32, name: u32, value: []const u8) !void {
|
||||
const rc = ws2_32.setsockopt(self.fd, @intCast(i32, level), @intCast(i32, name), value.ptr, @intCast(i32, value.len));
|
||||
pub fn setOption(self: Socket, level: u32, code: u32, value: []const u8) !void {
|
||||
const rc = ws2_32.setsockopt(self.fd, @intCast(i32, level), @intCast(i32, code), value.ptr, @intCast(i32, value.len));
|
||||
if (rc == ws2_32.SOCKET_ERROR) {
|
||||
return switch (ws2_32.WSAGetLastError()) {
|
||||
.WSANOTINITIALISED => unreachable,
|
||||
@ -375,6 +375,9 @@ pub const Socket = struct {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_RCVBUF, mem.asBytes(&size));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
/// set on a non-blocking socket.
|
||||
///
|
||||
/// Set a timeout on the socket that is to occur if no messages are successfully written
|
||||
/// to its bound destination after a specified number of milliseconds. A subsequent write
|
||||
/// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
|
||||
@ -382,6 +385,9 @@ pub const Socket = struct {
|
||||
return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_SNDTIMEO, mem.asBytes(&milliseconds));
|
||||
}
|
||||
|
||||
/// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
|
||||
/// set on a non-blocking socket.
|
||||
///
|
||||
/// Set a timeout on the socket that is to occur if no messages are successfully read
|
||||
/// from its bound destination after a specified number of milliseconds. A subsequent
|
||||
/// read from the socket will thereafter return `error.WouldBlock` should the timeout be
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user