From c0ab61eb1da56d22f64c1c30f30392f632ccf4d0 Mon Sep 17 00:00:00 2001 From: ZeroSkill1 Date: Sat, 9 May 2026 12:06:24 +0300 Subject: [PATCH] Add link3dsDisconnectFromHost() --- libctru/include/3ds/3dslink.h | 14 +++++++++++--- libctru/source/3dslink.c | 7 +++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libctru/include/3ds/3dslink.h b/libctru/include/3ds/3dslink.h index 234f941f4..b9eb217d5 100644 --- a/libctru/include/3ds/3dslink.h +++ b/libctru/include/3ds/3dslink.h @@ -16,10 +16,12 @@ extern struct in_addr __3dslink_host; /** * @brief Connects to the 3dslink host, setting up an output stream. - * @param[in] redirStdout Whether to redirect stdout to nxlink output. - * @param[in] redirStderr Whether to redirect stderr to nxlink output. + * @param[in] redirStdout Whether to redirect stdout to 3dslink output. + * @param[in] redirStderr Whether to redirect stderr to 3dslink output. * @return Socket fd on success, negative number on failure. - * @note The socket should be closed with close() during application cleanup. + * @note SOC must be initialized (\ref socInit or \ref socInitMulti) before calling this function. + * @note The connection should be closed with link3dsDisconnectFromHost() during application cleanup. + * @note Do not call \ref socExit until link3dsDisconnectFromHost() has been called. */ int link3dsConnectToHost(bool redirStdout, bool redirStderr); @@ -32,3 +34,9 @@ static inline int link3dsStdio(void) { static inline int link3dsStdioForDebug(void) { return link3dsConnectToHost(false, true); } + +/** + * @brief Disconnects from the 3dslink host. + * @note Do not call \ref socExit until this has been called. + */ +void link3dsDisconnectFromHost(); \ No newline at end of file diff --git a/libctru/source/3dslink.c b/libctru/source/3dslink.c index 8dc038137..b6fc1a193 100644 --- a/libctru/source/3dslink.c +++ b/libctru/source/3dslink.c @@ -46,3 +46,10 @@ int link3dsConnectToHost(bool redirStdout, bool redirStderr) return sock; } + +void link3dsDisconnectFromHost() +{ + close(sock); + close(STDOUT_FILENO); + close(STDERR_FILENO); +} \ No newline at end of file