fixes for windows

This commit is contained in:
Dale Weiler
2021-10-24 10:54:46 -04:00
parent 357d085ffb
commit 37d3a8a861
2 changed files with 19 additions and 11 deletions
+10 -2
View File
@@ -2,9 +2,17 @@ package ENet
when ODIN_OS == "windows" { when ODIN_OS == "windows" {
when ODIN_ARCH == "amd64" { when ODIN_ARCH == "amd64" {
foreign import ENet "lib/enet64.lib" foreign import ENet {
"lib/enet64.lib",
"system:Ws2_32.lib",
"system:Winmm.lib",
}
} else { } else {
foreign import ENet "lib/enet.lib" foreign import ENet {
"lib/enet.lib",
"system:Ws2_32.lib",
"system:Winmm.lib",
}
} }
} else { } else {
foreign import ENet "system:enet" foreign import ENet "system:enet"
+9 -9
View File
@@ -4,7 +4,7 @@ package ENet
// When we implement the appropriate bindings for Windows, the section separated // When we implement the appropriate bindings for Windows, the section separated
// by `{` and `}` here can be removed in favor of using the bindings. // by `{` and `}` here can be removed in favor of using the bindings.
// { // {
foreign WinSock2 import "system:Ws2_32.lib" foreign import WinSock2 "system:Ws2_32.lib"
@(private="file", default_calling_convention="c") @(private="file", default_calling_convention="c")
foreign WinSock2 { foreign WinSock2 {
@@ -15,7 +15,7 @@ foreign WinSock2 {
@(private="file") FD_SETSIZE :: 64 @(private="file") FD_SETSIZE :: 64
@(private="file") fs_set :: struct { @(private="file") fd_set :: struct {
fd_count: u32, fd_count: u32,
fd_array: [FD_SETSIZE]SOCKET, fd_array: [FD_SETSIZE]SOCKET,
} }
@@ -44,18 +44,18 @@ foreign WinSock2 {
s.fd_count += 1 s.fd_count += 1
} }
@(private="file") FD_ZERO proc #force_inline (s: ^fd_set) { @(private="file") FD_ZERO :: #force_inline proc (s: ^fd_set) {
s.fd_count = 0 s.fd_count = 0
} }
@(private="file") FD_ISSET proc #force_inline (fd: SOCKET, s: ^fd_set) -> bool { @(private="file") FD_ISSET :: #force_inline proc (fd: SOCKET, s: ^fd_set) -> bool {
return __WSAFDIsSet(fd, s) != 0 return __WSAFDIsSet(fd, s) != 0
} }
// } // }
Socket :: distinct Socket Socket :: distinct SOCKET
SOCKET_NULL :: Socket(~0) SOCKET_NULL :: Socket(~uintptr(0))
Buffer :: struct { Buffer :: struct {
data: rawptr, data: rawptr,
@@ -69,13 +69,13 @@ SOCKETSET_EMPTY :: #force_inline proc(sockset: ^SocketSet) {
} }
SOCKETSET_ADD :: #force_inline proc(sockset: ^SocketSet, socket: Socket) { SOCKETSET_ADD :: #force_inline proc(sockset: ^SocketSet, socket: Socket) {
FD_SET(i32(socket), cast(^fd_set)sockset) FD_SET(SOCKET(socket), cast(^fd_set)sockset)
} }
SOCKETSET_REMOVE :: #force_inline proc(sockset: ^SocketSet, socket: Socket) { SOCKETSET_REMOVE :: #force_inline proc(sockset: ^SocketSet, socket: Socket) {
FD_CLR(i32(socket), cast(^fd_set)sockset) FD_CLR(SOCKET(socket), cast(^fd_set)sockset)
} }
SOCKSET_CHECK :: #force_inline proc(sockset: ^SocketSet, socket: Socket) -> bool { SOCKSET_CHECK :: #force_inline proc(sockset: ^SocketSet, socket: Socket) -> bool {
return FD_ISSET(i32(socket), cast(^fd_set)sockset) return FD_ISSET(SOCKET(socket), cast(^fd_set)sockset)
} }