Skip to content

Commit

Permalink
nn_nets2: Add somemopt (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts authored Nov 30, 2023
1 parent 8cf1780 commit af0ccf4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cafe/nn_nets2.def
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ icmp_close_handle
icmp_create_handle
icmp_last_code_type
icmp_ping

:TEXT_WRAP
somemopt
8 changes: 8 additions & 0 deletions include/nn/nets2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

/**
* \defgroup nn_nets2 nn_nets2
* Network functions 2.
*/

#include <nn/nets2/somemopt.h>
68 changes: 68 additions & 0 deletions include/nn/nets2/somemopt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once
#include <wut.h>

/**
* \defgroup nn_nets2_somemopt
* \ingroup nn_nets2
* User provided socket memory options.
* @{
*/

#ifdef __cplusplus
extern "C" {
#endif

typedef enum SOMemOptRequest
{
//! Initialize buffer managment from user-provided buffer.
//! This is a blocking request, which only returns once nsysnet is shut down/the application quits.
SOMEMOPT_REQUEST_INIT = 1,
//! Return the amount of bytes used for buffer management.
SOMEMOPT_REQUEST_GET_BYTES_USED = 2,
//! Wait for buffer management initialization to be done.
SOMEMOPT_REQUEST_WAIT_FOR_INIT = 3,
//! Cancel pending wait for init.
SOMEMOPT_REQUEST_CANCEL_WAIT = 4,
} SOMemOptRequest;

typedef enum SOMemOptFlags
{
SOMEMOPT_FLAGS_NONE = 0,
//! Changes the distribution between small and big buffers to 50-50 instead of 80-20.
SOMEMOPT_FLAGS_BIG_BUFFERS = 1 << 0,
} SOMemOptFlags;

/**
* Perform a somemopt request.
*
* \param request
* The request to perform.
*
* \param buffer
* A 0x40 aligned buffer for \link SOMEMOPT_REQUEST_INIT \endlink.
*
* \param size
* The size of the buffer for \link SOMEMOPT_REQUEST_INIT \endlink.
* Minimum size is \c 0x20000 bytes, maximum size is \c 0x300000.
*
* \param flags
* A combination of flags.
*
* \return
* -1 on error.
*/
int
somemopt(SOMemOptRequest request,
void *buffer,
uint32_t size,
SOMemOptFlags flags);

int
RPLWRAP(somemopt)(SOMemOptRequest request,
void *buffer,
uint32_t size,
SOMemOptFlags flags);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define SO_UNKNOWN101A 0x101A // tcp related
#define SO_UNKNOWN101B 0x101B // tcp related
#define SO_NOSLOWSTART 0x4000 // disable slowstart
#define SO_RUSRBUF 0x10000 // ?
#define SO_RUSRBUF 0x10000 // enable somemopt provided memory for receive buffer

typedef uint32_t socklen_t;
typedef uint16_t sa_family_t;
Expand Down
13 changes: 13 additions & 0 deletions libraries/wutsocket/somemopt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "wut_socket.h"

#include <nn/nets2.h>

int
somemopt(SOMemOptRequest request,
void *buffer,
uint32_t size,
SOMemOptFlags flags)
{
int rc = RPLWRAP(somemopt)(request, buffer, size, flags);
return __wut_get_nsysnet_result(NULL, rc);
}
2 changes: 2 additions & 0 deletions tests/test_compile_headers_common/test_compile_headers_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
#include <nn/ccr/sys_caffeine.h>
#include <nn/cmpt/cmpt.h>
#include <nn/ffl/miidata.h>
#include <nn/nets2/somemopt.h>
#include <nn/nfp/nfp_cpp.h>
#include <nn/nfp/amiibo_settings_cpp.h>
#include <nn/pdm/pdm_c.h>
Expand All @@ -116,6 +117,7 @@
#include <nn/cmpt.h>
#include <nn/result.h>
#include <nn/sl.h>
#include <nn/nets2.h>
#include <nn/nfp.h>
#include <nn/pdm.h>
#include <nn/swkbd.h>
Expand Down

0 comments on commit af0ccf4

Please sign in to comment.