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{
31143114/// Initiate a connection on a socket.
31153115pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) ConnectError!void {
31163116 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));
31183118 if (rc == 0) return;
31193119 switch (windows.ws2_32.WSAGetLastError()) {
31203120 .WSAEADDRINUSE => return error.AddressInUse,
lib/std/os/windows.zig+4-14
......@@ -1154,7 +1154,7 @@ pub fn WSASocketW(
11541154}
11551155
11561156pub 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));
11581158}
11591159
11601160pub fn listen(s: ws2_32.SOCKET, backlog: u31) i32 {
......@@ -1173,27 +1173,17 @@ pub fn closesocket(s: ws2_32.SOCKET) !void {
11731173
11741174pub fn accept(s: ws2_32.SOCKET, name: ?*ws2_32.sockaddr, namelen: ?*ws2_32.socklen_t) ws2_32.SOCKET {
11751175 assert((name == null) == (namelen == null));
1176 if (namelen) |name_length| {
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 }
1176 return ws2_32.accept(s, name, @ptrCast(?*i32, namelen));
11841177}
11851178
11861179pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {
1187 var os_namelen: c_int = namelen.*;
1188 const rc = ws2_32.getsockname(s, name, &os_namelen);
1189 namelen.* = @intCast(ws2_32.socklen_t, os_namelen);
1190 return rc;
1180 return ws2_32.getsockname(s, name, @ptrCast(*i32, namelen));
11911181}
11921182
11931183pub 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 {
11941184 var buffer = ws2_32.WSABUF{ .len = @truncate(u31, len), .buf = @intToPtr([*]u8, @ptrToInt(buf)) };
11951185 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) {
11971187 return ws2_32.SOCKET_ERROR;
11981188 } else {
11991189 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:
116116pub const ADDRESS_FAMILY = u16;
117117
118118// 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
121121pub const AF_UNSPEC = 0;
122122pub const AF_UNIX = 1;