Skip to content

Commit

Permalink
AK: Simplify usage of windows.h and winsock2.h
Browse files Browse the repository at this point in the history
Use <AK/Windows.h> instead of windows.h/winsock2.h
to avoid timeval-related errors.

Note: winsock2.h includes windows.h
  • Loading branch information
stasoid committed Dec 9, 2024
1 parent 18132a0 commit 4c7b143
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 1 addition & 3 deletions AK/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include <AK/Time.h>

#ifdef AK_OS_WINDOWS
# define timeval dummy_timeval
# include <windows.h>
# undef timeval
# include <AK/Windows.h>
#endif

namespace AK {
Expand Down
17 changes: 17 additions & 0 deletions AK/Windows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024, stasoid <stasoid@yahoo.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <AK/Platform.h>

#ifdef AK_OS_WINDOWS // needed for Swift
# define timeval dummy_timeval
# include <winsock2.h>
# undef timeval
# pragma comment(lib, "ws2_32.lib")
# include <io.h>
#endif
2 changes: 0 additions & 2 deletions Libraries/LibCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,4 @@ if (WIN32)
find_package(pthread REQUIRED)
target_include_directories(LibCore PRIVATE ${PTHREAD_INCLUDE_DIR})
target_link_libraries(LibCore PRIVATE ${PTHREAD_LIBRARY})

target_link_libraries(LibCore PRIVATE ws2_32.lib)
endif()
4 changes: 2 additions & 2 deletions Libraries/LibCore/EventLoopImplementationWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <LibCore/EventLoopImplementationWindows.h>
#include <LibCore/Notifier.h>
#include <LibCore/ThreadEventQueue.h>
#include <WinSock2.h>
#include <io.h>
// This comment stops clang-format from changing header order
#include <AK/Windows.h>

struct Handle {
HANDLE handle = NULL;
Expand Down

0 comments on commit 4c7b143

Please sign in to comment.