Skip to content

Commit

Permalink
sockets(windows): fix all compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alaviss committed Feb 14, 2024
1 parent 07092af commit b8b7ad8
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/sys/private/sockets_windows.nim
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ template acceptCommon(listener: SocketFD, conn: var Handle[SocketFD],

# TODO : cache this data
let lendpoint = getLocalEndpoint(listener)
let addressFamily =
let addressFamily: int32 =
case lendpoint.kind
of V4: AF_INET
of V6: AF_INET6
Expand Down Expand Up @@ -488,14 +488,13 @@ template acceptCommon(listener: SocketFD, conn: var Handle[SocketFD],
)

# Copy the remote address
remote =
case remoteAddr.ss_family
of AF_INET:
IPEndpoint(kind: V4, v4: cast[ptr IP4Endpoint](remoteAddr)[])
of AF_INET6:
IPEndpoint(kind: V6, v6: cast[ptr IP6Endpoint](remoteAddr)[])
else:
doAssert false, "Unexpected remote address family: " & $remoteAddr.ss_family
case remoteAddr.sa_family
of AF_INET:
remote = IPEndpoint(kind: V4, v4: cast[ptr IP4Endpoint](remoteAddr)[])
of AF_INET6:
remote = IPEndpoint(kind: V6, v6: cast[ptr IP6Endpoint](remoteAddr)[])
else:
doAssert false, "Unexpected remote address family: " & $remoteAddr.sa_family

# Update the connection attributes so that other functions can be used on the
# socket.
Expand Down Expand Up @@ -537,14 +536,13 @@ proc getLocalEndpoint(fd: SocketFD): IPEndpoint =
assert endpointLen <= sizeof(saddr):
"The length of the endpoint structure is bigger than expected size. This is a nim-sys bug."

result =
case saddr.ss_family
of AF_INET:
IPEndpoint(kind: V4, v4: cast[IP4Endpoint](saddr)[])
of AF_INET6:
IPEndpoint(kind: V6, v6: cast[IP6Endpoint](saddr)[])
else:
doAssert false, "Unexpected local address family: " & $saddr.ss_family
case saddr.ss_family
of AF_INET:
result = IPEndpoint(kind: V4, v4: cast[ptr IP4Endpoint](addr saddr)[])
of AF_INET6:
result = IPEndpoint(kind: V6, v6: cast[ptr IP6Endpoint](addr saddr)[])
else:
doAssert false, "Unexpected local address family: " & $saddr.ss_family

proc initWinsock() =
## Initializes winsock for use with sys/sockets
Expand Down

0 comments on commit b8b7ad8

Please sign in to comment.