mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Move tmem allocation in bsdInitalize...
...add bsdExit, change the default config's "version" field to 1.
This commit is contained in:
parent
fb9e126f3a
commit
5b0de6c054
@ -26,7 +26,8 @@ struct bsd_sockaddr_in {
|
||||
};
|
||||
|
||||
const BsdConfig *bsdGetDefaultConfig(void);
|
||||
Result bsdInitialize(TransferMemory* tmem, const BsdConfig *config);
|
||||
Result bsdInitialize(const BsdConfig *config);
|
||||
void bsdExit(void);
|
||||
int bsdGetErrno(void);
|
||||
int bsdConnect(int sockfd, const void* addr, u32 addrlen);
|
||||
int bsdSocket(int domain, int type, int protocol);
|
||||
@ -38,30 +39,9 @@ int bsdRecv(int sockfd, void* buffer, size_t length, int flags);
|
||||
int bsdSetSockOpt(int sockfd, int level, int option_name, const void *option_value, size_t option_size);
|
||||
int bsdWrite(int sockfd, const void* buffer, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Computes the minimal size of the transfer memory to be passed to @ref bsdInitalize.
|
||||
* Should the transfer memory be smaller than that, the BSD sockets service would only send
|
||||
* ZeroWindow packets (for TCP), resulting in a transfer rate not exceeding 1 byte/s.
|
||||
* @param config Pointer to the BSD sockets service configuration.
|
||||
*/
|
||||
static inline size_t bsdGetTransferMemSizeForConfig(const BsdConfig *config)
|
||||
static inline Result bsdInitializeDefault(void)
|
||||
{
|
||||
u32 tcp_tx_buf_max_size = config->tcp_tx_buf_max_size != 0 ? config->tcp_tx_buf_max_size : config->tcp_tx_buf_size;
|
||||
u32 tcp_rx_buf_max_size = config->tcp_rx_buf_max_size != 0 ? config->tcp_rx_buf_max_size : config->tcp_rx_buf_size;
|
||||
u32 sum = tcp_tx_buf_max_size + tcp_rx_buf_max_size + config->udp_tx_buf_size + config->udp_rx_buf_size;
|
||||
|
||||
sum = ((sum + 0xFFF) >> 12) << 12; // page round-up
|
||||
return (size_t)(config->sb_efficiency * sum);
|
||||
}
|
||||
|
||||
static inline size_t bsdGetTransferMemSizeForDefaultConfig(void)
|
||||
{
|
||||
return bsdGetTransferMemSizeForConfig(bsdGetDefaultConfig());
|
||||
}
|
||||
|
||||
static inline Result bsdInitializeDefault(TransferMemory* tmem)
|
||||
{
|
||||
return bsdInitialize(tmem, bsdGetDefaultConfig());
|
||||
return bsdInitialize(bsdGetDefaultConfig());
|
||||
}
|
||||
|
||||
#define BSD_AF_INET 2
|
||||
|
@ -73,4 +73,4 @@ typedef enum {
|
||||
#define DEPRECATED
|
||||
#endif
|
||||
|
||||
#define INVALID_HANDLE ((Handle) -1)
|
||||
#define INVALID_HANDLE ((Handle) 0)
|
||||
|
@ -30,7 +30,7 @@ void envSetup(void* ctx, Handle main_thread, LoaderReturnFn saved_lr)
|
||||
}
|
||||
|
||||
// Detect NSO environment.
|
||||
if (main_thread != INVALID_HANDLE)
|
||||
if (main_thread != -1)
|
||||
{
|
||||
g_mainThreadHandle = main_thread;
|
||||
g_isNso = true;
|
||||
|
@ -7,13 +7,17 @@
|
||||
#include "kernel/shmem.h"
|
||||
#include "kernel/rwlock.h"
|
||||
|
||||
#define EPIPE 32
|
||||
|
||||
static Service g_bsdSrv;
|
||||
static Service g_bsdMonitor;
|
||||
static u64 g_bsdClientPid = -1;
|
||||
static int g_Errno = 0;
|
||||
|
||||
static TransferMemory g_bsdTmem;
|
||||
|
||||
static const BsdConfig g_defaultBsdConfig = {
|
||||
.version = 2,
|
||||
.version = 1,
|
||||
|
||||
.tcp_tx_buf_size = 0x8000,
|
||||
.tcp_rx_buf_size = 0x10000,
|
||||
@ -26,7 +30,20 @@ static const BsdConfig g_defaultBsdConfig = {
|
||||
.sb_efficiency = 4,
|
||||
};
|
||||
|
||||
#define EPIPE 32
|
||||
/*
|
||||
This function computes the minimal size of the transfer memory to be passed to @ref bsdInitalize.
|
||||
Should the transfer memory be smaller than that, the BSD sockets service would only send
|
||||
ZeroWindow packets (for TCP), resulting in a transfer rate not exceeding 1 byte/s.
|
||||
*/
|
||||
static size_t _bsdGetTransferMemSizeForConfig(const BsdConfig *config)
|
||||
{
|
||||
u32 tcp_tx_buf_max_size = config->tcp_tx_buf_max_size != 0 ? config->tcp_tx_buf_max_size : config->tcp_tx_buf_size;
|
||||
u32 tcp_rx_buf_max_size = config->tcp_rx_buf_max_size != 0 ? config->tcp_rx_buf_max_size : config->tcp_rx_buf_size;
|
||||
u32 sum = tcp_tx_buf_max_size + tcp_rx_buf_max_size + config->udp_tx_buf_size + config->udp_rx_buf_size;
|
||||
|
||||
sum = ((sum + 0xFFF) >> 12) << 12; // page round-up
|
||||
return (size_t)(config->sb_efficiency * sum);
|
||||
}
|
||||
|
||||
static Result _bsdRegisterClient(Service* srv, TransferMemory* tmem, const BsdConfig *config, u64* pid_out) {
|
||||
IpcCommand c;
|
||||
@ -108,28 +125,43 @@ const BsdConfig *bsdGetDefaultConfig(void) {
|
||||
return &g_defaultBsdConfig;
|
||||
}
|
||||
|
||||
Result bsdInitialize(TransferMemory* tmem, const BsdConfig *config) {
|
||||
Result bsdInitialize(const BsdConfig *config) {
|
||||
const char* bsd_srv = "bsd:s";
|
||||
|
||||
if(serviceIsActive(&g_bsdSrv) || serviceIsActive(&g_bsdMonitor))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
||||
|
||||
Result rc = smGetService(&g_bsdSrv, bsd_srv);
|
||||
|
||||
if (R_FAILED(rc)) {
|
||||
bsd_srv = "bsd:u";
|
||||
rc = smGetService(&g_bsdSrv, bsd_srv);
|
||||
}
|
||||
if(R_FAILED(rc)) goto error;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = smGetService(&g_bsdMonitor, bsd_srv);
|
||||
rc = smGetService(&g_bsdMonitor, bsd_srv);
|
||||
if(R_FAILED(rc)) goto error;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = _bsdRegisterClient(&g_bsdSrv, tmem, config, &g_bsdClientPid);
|
||||
rc = tmemCreate(&g_bsdTmem, _bsdGetTransferMemSizeForConfig(config), 0);
|
||||
if(R_FAILED(rc)) goto error;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc = _bsdStartMonitor(&g_bsdMonitor, g_bsdClientPid);
|
||||
}
|
||||
}
|
||||
}
|
||||
rc = _bsdRegisterClient(&g_bsdSrv, &g_bsdTmem, config, &g_bsdClientPid);
|
||||
if(R_FAILED(rc)) goto error;
|
||||
|
||||
rc = _bsdStartMonitor(&g_bsdMonitor, g_bsdClientPid);
|
||||
if(R_FAILED(rc)) goto error;
|
||||
|
||||
return rc;
|
||||
|
||||
error:
|
||||
bsdExit();
|
||||
return rc;
|
||||
}
|
||||
|
||||
void bsdExit(void) {
|
||||
serviceClose(&g_bsdMonitor);
|
||||
serviceClose(&g_bsdSrv);
|
||||
tmemClose(&g_bsdTmem);
|
||||
}
|
||||
|
||||
int bsdGetErrno(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user