Skip to content

Commit

Permalink
Split networking code into its own target (melonDS-emu#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG authored Jul 14, 2024
1 parent a812a43 commit 94ba7c1
Show file tree
Hide file tree
Showing 213 changed files with 159 additions and 108 deletions.
18 changes: 18 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Vendored Dependencies
src/frontend/glad/** linguist-vendored
src/frontend/qt_sdl/gif-h/** linguist-vendored
src/frontend/qt_sdl/toml/** linguist-vendored
src/net/libslirp/** linguist-vendored
src/net/pcap/** linguist-vendored
src/sha1/** linguist-vendored
src/teakra/** linguist-vendored
src/tiny-AES-c/** linguist-vendored
src/xxhash/** linguist-vendored

# A handful of custom files embedded in the vendored dependencies

## Ad-hoc CMakeLists.txt for melonDS
!src/net/libslirp/src/CMakeLists.txt -linguist-vendored

## glib stub
!src/net/libslirp/src/glib/** -linguist-vendored
3 changes: 3 additions & 0 deletions src/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ Semaphore* Semaphore_Create();
void Semaphore_Free(Semaphore* sema);
void Semaphore_Reset(Semaphore* sema);
void Semaphore_Wait(Semaphore* sema);
/// Waits for the semaphore to be signaled, or until the timeout (in milliseconds) expires.
/// If the timeout is 0, then don't wait; return immediately if the semaphore is not signaled.
bool Semaphore_TryWait(Semaphore* sema, int timeout_ms = 0);
void Semaphore_Post(Semaphore* sema, int count = 1);

struct Mutex;
Expand Down
1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_icmp6/ndp.pcap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_ip-header/dhcp.pkt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_ip-header/nc-ident.pcap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_tcp-d

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_tcp-h

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_tcp6-d

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_tcp6-h

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp-h

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp/dhcp.pkt

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp/dhcp_capture.pcap

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp/tftp-get-blah.pkt

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp/tftp_capture.pcap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp6-h

This file was deleted.

1 change: 0 additions & 1 deletion src/frontend/libslirp/fuzzing/IN_udp6/tftp_capture.pcap

This file was deleted.

This file was deleted.

20 changes: 5 additions & 15 deletions src/frontend/qt_sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ set(SOURCES_QT_SDL
ROMInfoDialog.cpp
RAMInfoDialog.cpp
TitleManagerDialog.cpp
PacketDispatcher.cpp
Net.cpp
Net_PCap.cpp
Net_Slirp.cpp
LocalMP.cpp
OSD_shaders.h
font.h
Platform.cpp
Expand Down Expand Up @@ -93,16 +88,11 @@ add_compile_definitions(ARCHIVE_SUPPORT_ENABLED)

add_executable(melonDS ${SOURCES_QT_SDL})

option(USE_SYSTEM_LIBSLIRP "Use system libslirp instead of the bundled version" OFF)
if (USE_SYSTEM_LIBSLIRP)
pkg_check_modules(Slirp REQUIRED IMPORTED_TARGET slirp)
target_link_libraries(melonDS PRIVATE PkgConfig::Slirp)
else()
add_subdirectory("../libslirp"
"${CMAKE_BINARY_DIR}/libslirp"
EXCLUDE_FROM_ALL)
target_link_libraries(melonDS PRIVATE slirp)
endif()
add_subdirectory("../../net"
"${CMAKE_BINARY_DIR}/net"
)

target_link_libraries(melonDS PRIVATE net-utils)

if (WIN32)
target_link_libraries(melonDS PUBLIC opengl32)
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/qt_sdl/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ void Semaphore_Wait(Semaphore* sema)
((QSemaphore*) sema)->acquire();
}

bool Semaphore_TryWait(Semaphore* sema, int timeout_ms)
{
if (!timeout_ms)
return ((QSemaphore*)sema)->tryAcquire(1);

return ((QSemaphore*)sema)->tryAcquire(1, timeout_ms);
}

void Semaphore_Post(Semaphore* sema, int count)
{
((QSemaphore*) sema)->release(count);
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/qt_sdl/WifiSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "main.h"

#include "Net.h"
#include "Net_PCap.h"

#include "WifiSettingsDialog.h"
#include "ui_WifiSettingsDialog.h"
Expand Down Expand Up @@ -109,7 +110,10 @@ void WifiSettingsDialog::done(int r)
}

Net_PCap::DeInit();
Net::Init();
Config::Table cfg = Config::GetGlobalTable();
bool direct = cfg.GetBool("LAN.DirectMode");
std::string devicename = cfg.GetString("LAN.Device");
Net::Init(direct, devicename.c_str());

QDialog::done(r);

Expand Down
7 changes: 6 additions & 1 deletion src/frontend/qt_sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ int main(int argc, char** argv)
}

LocalMP::Init();
Net::Init();
{
Config::Table cfg = Config::GetGlobalTable();
bool direct = cfg.GetBool("LAN.DirectMode");
std::string devicename = cfg.GetString("LAN.Device");
Net::Init(direct, devicename.c_str());
}

createEmuInstance();

Expand Down
20 changes: 20 additions & 0 deletions src/net/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_library(net-utils STATIC
Net.cpp
Net_PCap.cpp
Net_Slirp.cpp
PacketDispatcher.cpp
LocalMP.cpp
)

target_include_directories(net-utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(net-utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")


option(USE_SYSTEM_LIBSLIRP "Use system libslirp instead of the bundled version" OFF)
if (USE_SYSTEM_LIBSLIRP)
pkg_check_modules(Slirp REQUIRED IMPORTED_TARGET slirp)
target_link_libraries(net-utils PRIVATE PkgConfig::Slirp)
else()
add_subdirectory(libslirp EXCLUDE_FROM_ALL)
target_link_libraries(net-utils PRIVATE slirp)
endif()
Loading

0 comments on commit 94ba7c1

Please sign in to comment.