ladybird icon indicating copy to clipboard operation
ladybird copied to clipboard

LibCore: Fix SocketAddress.h compilation errors on Windows

Open stasoid opened this issue 1 year ago • 10 comments

Including winsock2.h in a header file is undesirable for architectural reasons, so I pulled the needed types from ws2def.h and ws2ipdef.h into a separate header.

Files inaddr.h and afunix.h are tiny and can be included directly. They each define a single struct (in_addr and sockaddr_un respectively).

I removed the #if (_WIN32_WINNT < 0x0600) code because it is not relevant for us. It is intended for Windows XP/Windows Server 2003 and earlier, but Ladybird doesn't support 32-bit, and 64-bit Windows XP is very rare.

stasoid avatar Dec 01 '24 05:12 stasoid

@R-Goc Does it work for you?

stasoid avatar Dec 01 '24 16:12 stasoid

It's creating a bit of an issue in system.h and systemWindows.cpp The issue is that when including system.h we include the sockaddr-win needed there to provide the addrinfo related things. However, this will cause a lot of redefinitions as we need to include WinSock2.h to implement sockets.

R-Goc avatar Dec 04 '24 10:12 R-Goc

I addressed this issue. You can include winsock2.h after sockaddr-win.h.

stasoid avatar Dec 04 '24 11:12 stasoid

Ok I'll check. Maybe clang format is moving includes around.

R-Goc avatar Dec 04 '24 11:12 R-Goc

While clang-fromat was indeed moving includes around, turns out the issue is with ws2tcpip.h. Looks like with sockaddr-win.h included the only thing needed from there is gai_strerror(). Though that can be replaced with WSAGetLastError, which would mean different error handling for windows and linux, but I think that's fine. That makes it a bit ugly as getting an error string from windows error messages is a bit difficult, but for now I'll return an int.

R-Goc avatar Dec 04 '24 12:12 R-Goc

Should we just change AF_UNIX in SocketAddress.h to AF_LOCAL? Or define AF_UNIX to AF_LOCAL here?

R-Goc avatar Dec 04 '24 12:12 R-Goc

Yes, sockaddr-win.h doesn't work with ws2tcpip.h. If a declaration from ws2tcpip.h is needed it is supposed to be included in sockaddr-win.h. However, I don't want to include gai_strerror because it is inline and Error::from_windows_error can be used instead.

AF_UNIX is not used anywhere in the codebase, that's why I didn't define it.

stasoid avatar Dec 04 '24 13:12 stasoid

It is in SocketAddress.h. sockaddr-win isn't a replacement for SocketAddress.h

R-Goc avatar Dec 04 '24 15:12 R-Goc

As mentioned on another PR, please make any and all added header files follow the project conventions for naming

ADKaster avatar Dec 09 '24 00:12 ADKaster

@ADKaster I renamed the file.

stasoid avatar Dec 09 '24 13:12 stasoid

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Jan 08 '25 01:01 github-actions[bot]

unstale

stasoid avatar Jan 13 '25 05:01 stasoid