ladybird
ladybird copied to clipboard
LibCore: Fix SocketAddress.h compilation errors on Windows
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.
@R-Goc Does it work for you?
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.
I addressed this issue. You can include winsock2.h after sockaddr-win.h.
Ok I'll check. Maybe clang format is moving includes around.
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.
Should we just change AF_UNIX in SocketAddress.h to AF_LOCAL? Or define AF_UNIX to AF_LOCAL here?
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.
It is in SocketAddress.h. sockaddr-win isn't a replacement for SocketAddress.h
As mentioned on another PR, please make any and all added header files follow the project conventions for naming
@ADKaster I renamed the file.
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!
unstale