libnx  v4.6.0
socket.h
1 #pragma once
2 #include "../../types.h"
3 
4 /// BSD service type used by the socket driver.
5 typedef enum {
6  BsdServiceType_User = BIT(0), ///< Uses bsd:u (default).
7  BsdServiceType_System = BIT(1), ///< Uses bsd:s.
8  BsdServiceType_Auto = BsdServiceType_User | BsdServiceType_System, ///< Tries to use bsd:s first, and if that fails uses bsd:u (official software behavior).
9 } BsdServiceType;
10 
11 /// Configuration structure for socketInitalize
12 typedef struct {
13  u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
14  u32 tcp_rx_buf_size; ///< Size of the TCP receive buffer (initial or fixed).
15  u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value.
16  u32 tcp_rx_buf_max_size; ///< Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial value.
17 
18  u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
19  u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes).
20 
21  u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8).
22 
23  u32 num_bsd_sessions; ///< Number of BSD service sessions (typically 3).
24  BsdServiceType bsd_service_type; ///< BSD service type (typically \ref BsdServiceType_User).
26 
27 /// Fetch the default configuration for the socket driver.
28 const SocketInitConfig *socketGetDefaultInitConfig(void);
29 /// Initalize the socket driver.
30 Result socketInitialize(const SocketInitConfig *config);
31 /// Fetch the last bsd:u/s Switch result code (thread-local).
32 Result socketGetLastResult(void);
33 /// Deinitialize the socket driver.
34 void socketExit(void);
35 
36 /// Initalize the socket driver using the default configuration.
37 NX_INLINE Result socketInitializeDefault(void) {
38  return socketInitialize(NULL);
39 }
40 
41 /// Wrapper for \ref sslConnectionSetSocketDescriptor. Returns the output sockfd on success and -1 on error. errno==ENOENT indicates that no sockfd was returned, this error must be ignored.
42 int socketSslConnectionSetSocketDescriptor(SslConnection *c, int sockfd);
43 
44 /// Wrapper for \ref sslConnectionGetSocketDescriptor. Returns the output sockfd on success and -1 on error.
45 int socketSslConnectionGetSocketDescriptor(SslConnection *c);
46 
47 #ifdef _SOCKLEN_T_DECLARED
48 struct sockaddr;
49 /// Wrapper for \ref sslConnectionSetDtlsSocketDescriptor. Returns the output sockfd on success and -1 on error. errno==ENOENT indicates that no sockfd was returned, this error must be ignored.
50 int socketSslConnectionSetDtlsSocketDescriptor(SslConnection *c, int sockfd, const struct sockaddr *addr, socklen_t addrlen);
51 #endif
52 
53 /// Wrapper for \ref nifmRequestRegisterSocketDescriptor. Returns 0 on success and -1 on error.
54 int socketNifmRequestRegisterSocketDescriptor(NifmRequest* r, int sockfd);
55 
56 /// Wrapper for \ref nifmRequestUnregisterSocketDescriptor. Returns 0 on success and -1 on error.
57 int socketNifmRequestUnregisterSocketDescriptor(NifmRequest* r, int sockfd);
58 
Request.
Definition: nifm.h:42
Configuration structure for socketInitalize.
Definition: socket.h:12
u32 tcp_rx_buf_max_size
Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial va...
Definition: socket.h:16
u32 tcp_rx_buf_size
Size of the TCP receive buffer (initial or fixed).
Definition: socket.h:14
u32 tcp_tx_buf_max_size
Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its in...
Definition: socket.h:15
u32 udp_tx_buf_size
Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
Definition: socket.h:18
u32 num_bsd_sessions
Number of BSD service sessions (typically 3).
Definition: socket.h:23
u32 udp_rx_buf_size
Size of the UDP receive buffer (typically 0xA500 bytes).
Definition: socket.h:19
u32 sb_efficiency
Number of buffers for each socket (standard values range from 1 to 8).
Definition: socket.h:21
u32 tcp_tx_buf_size
Size of the TCP transfer (send) buffer (initial or fixed).
Definition: socket.h:13
BsdServiceType bsd_service_type
BSD service type (typically BsdServiceType_User).
Definition: socket.h:24
SslConnection.
Definition: ssl.h:201
#define NX_INLINE
Flags a function as (always) inline.
Definition: types.h:86
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:54
u32 Result
Function error code result type.
Definition: types.h:44
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21