mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Make nxlink stdio more flexible, see details:
- Added nxlinkConnectToHost with separate flags for redirecting stdout/err - Added nxlinkStdioForDebug, which only redirects stderr - (nxlinkStdio now just calls nxlinkConnectToHost)
This commit is contained in:
parent
4c9b2ac048
commit
4b7921a221
@ -5,6 +5,7 @@
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
|
||||
struct in_addr;
|
||||
|
||||
@ -15,8 +16,20 @@ extern struct in_addr __nxlink_host;
|
||||
#define NXLINK_CLIENT_PORT 28771 ///< nxlink TCP client port
|
||||
|
||||
/**
|
||||
* @brief Sets up stdout/stderr redirection to the nxlink host.
|
||||
* @brief Connects to the nxlink 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.
|
||||
* @return Socket fd on success, negative number on failure.
|
||||
* @note The socket should be closed with close() during application cleanup.
|
||||
*/
|
||||
int nxlinkStdio(void);
|
||||
int nxlinkConnectToHost(bool redirStdout, bool redirStderr);
|
||||
|
||||
/// Same as \ref nxlinkConnectToHost but redirecting both stdout/stderr.
|
||||
NX_INLINE int nxlinkStdio(void) {
|
||||
return nxlinkConnectToHost(true, true);
|
||||
}
|
||||
|
||||
/// Same as \ref nxlinkConnectToHost but redirecting only stderr.
|
||||
NX_INLINE int nxlinkStdioForDebug(void) {
|
||||
return nxlinkConnectToHost(false, true);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
static int sock = -1;
|
||||
|
||||
int nxlinkStdio(void)
|
||||
int nxlinkConnectToHost(bool redirStdout, bool redirStderr)
|
||||
{
|
||||
int ret = -1;
|
||||
struct sockaddr_in srv_addr;
|
||||
@ -30,12 +30,17 @@ int nxlinkStdio(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// redirect stdout
|
||||
fflush(stdout);
|
||||
dup2(sock, STDOUT_FILENO);
|
||||
// redirect stderr
|
||||
fflush(stderr);
|
||||
dup2(sock, STDERR_FILENO);
|
||||
if (redirStdout) {
|
||||
// redirect stdout
|
||||
fflush(stdout);
|
||||
dup2(sock, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
if (redirStderr) {
|
||||
// redirect stderr
|
||||
fflush(stderr);
|
||||
dup2(sock, STDERR_FILENO);
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user