authorgravatar for BarabasGitHub@users.noreply.github.comBas van den Berg <BarabasGitHub@users.noreply.github.com> 2020-09-08 12:24:39+02:00
committergravatar for BarabasGitHub@users.noreply.github.comBas van den Berg <BarabasGitHub@users.noreply.github.com> 2020-09-08 12:24:39+02:00
log44f877d18bef6c82d727efeb5ff78ea97d3307bf
treec45f058e71c77d05e8f7efb5b83d8d136bdc3521
parent857613fb65d2ba2d24d9f26d8b3fefd73f8abda6

change socklen_t to u32 and add appropriate casts when calling WSA


3 files changed, 6 insertions(+), 16 deletions(-)

lib/std/os.zig+1-1
...@@ -3114,7 +3114,7 @@ pub const ConnectError = error{...@@ -3114,7 +3114,7 @@ pub const ConnectError = error{
3114/// Initiate a connection on a socket.3114/// Initiate a connection on a socket.
3115pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) ConnectError!void {3115pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) ConnectError!void {
3116 if (builtin.os.tag == .windows) {3116 if (builtin.os.tag == .windows) {
3117 const rc = windows.ws2_32.connect(sock, sock_addr, len);3117 const rc = windows.ws2_32.connect(sock, sock_addr, @intCast(i32, len));
3118 if (rc == 0) return;3118 if (rc == 0) return;
3119 switch (windows.ws2_32.WSAGetLastError()) {3119 switch (windows.ws2_32.WSAGetLastError()) {
3120 .WSAEADDRINUSE => return error.AddressInUse,3120 .WSAEADDRINUSE => return error.AddressInUse,
lib/std/os/windows.zig+4-14
...@@ -1154,7 +1154,7 @@ pub fn WSASocketW(...@@ -1154,7 +1154,7 @@ pub fn WSASocketW(
1154}1154}
11551155
1156pub fn bind(s: ws2_32.SOCKET, name: *const ws2_32.sockaddr, namelen: ws2_32.socklen_t) i32 {1156pub fn bind(s: ws2_32.SOCKET, name: *const ws2_32.sockaddr, namelen: ws2_32.socklen_t) i32 {
1157 return ws2_32.bind(s, name, namelen);1157 return ws2_32.bind(s, name, @intCast(i32, namelen));
1158}1158}
11591159
1160pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 {1160pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 {
...@@ -1173,27 +1173,17 @@ pub fn closesocket(s: ws2_32.SOCKET) !void {...@@ -1173,27 +1173,17 @@ pub fn closesocket(s: ws2_32.SOCKET) !void {
11731173
1174pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET {1174pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET {
1175 assert((name == null) == (namelen == null));1175 assert((name == null) == (namelen == null));
1176 if (namelen) |name_length| {1176 return ws2_32.accept(s, name, @ptrCast(?*i32, namelen));
1177 var os_namelen: c_int = name_length.*;
1178 const sock = ws2_32.accept(s, name, &os_namelen);
1179 name_length.* = @intCast(ws2_32.socklen_t, os_namelen);
1180 return sock;
1181 } else {
1182 return ws2_32.accept(s, null, null);
1183 }
1184}1177}
11851178
1186pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {1179pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {
1187 var os_namelen: c_int = namelen.*;1180 return ws2_32.getsockname(s, name, @ptrCast(*i32, namelen));
1188 const rc = ws2_32.getsockname(s, name, &os_namelen);
1189 namelen.* = @intCast(ws2_32.socklen_t, os_namelen);
1190 return rc;
1191}1181}
11921182
1193pub fn sendto(s: ws2_32.SOCKET, buf: [*]const u8, len: usize, flags: u32, to: ?*const ws2_32.sockaddr, to_len: ws2_32.socklen_t) i32 {1183pub fn sendto(s: ws2_32.SOCKET, buf: [*]const u8, len: usize, flags: u32, to: ?*const ws2_32.sockaddr, to_len: ws2_32.socklen_t) i32 {
1194 var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = @intToPtr([*]u8, @ptrToInt(buf)) };1184 var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = @intToPtr([*]u8, @ptrToInt(buf)) };
1195 var bytes_send: DWORD = undefined;1185 var bytes_send: DWORD = undefined;
1196 if (ws2_32.WSASendTo(s, @ptrCast([*]ws2_32.WSABUF, &buffer), 1, &bytes_send, flags, to, to_len, null, null) == ws2_32.SOCKET_ERROR) {1186 if (ws2_32.WSASendTo(s, @ptrCast([*]ws2_32.WSABUF, &buffer), 1, &bytes_send, flags, to, @intCast(i32, to_len), null, null) == ws2_32.SOCKET_ERROR) {
1197 return ws2_32.SOCKET_ERROR;1187 return ws2_32.SOCKET_ERROR;
1198 } else {1188 } else {
1199 return @as(i32, @intCast(u31, bytes_send));1189 return @as(i32, @intCast(u31, bytes_send));
lib/std/os/windows/ws2_32.zig+1-1
...@@ -116,7 +116,7 @@ pub const WSAOVERLAPPED_COMPLETION_ROUTINE = fn (dwError: DWORD, cbTransferred:...@@ -116,7 +116,7 @@ pub const WSAOVERLAPPED_COMPLETION_ROUTINE = fn (dwError: DWORD, cbTransferred:
116pub const ADDRESS_FAMILY = u16;116pub const ADDRESS_FAMILY = u16;
117117
118// Microsoft use the signed c_int for this, but it should never be negative118// Microsoft use the signed c_int for this, but it should never be negative
119pub const socklen_t = u31;119pub const socklen_t = u32;
120120
121pub const AF_UNSPEC = 0;121pub const AF_UNSPEC = 0;
122pub const AF_UNIX = 1;122pub const AF_UNIX = 1;