libnx  v4.2.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 bsdsockets_version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
14 
15  u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
16  u32 tcp_rx_buf_size; ///< Size of the TCP receive buffer (initial or fixed).
17  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.
18  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.
19 
20  u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
21  u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes).
22 
23  u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8).
24 
25  u32 num_bsd_sessions; ///< Number of BSD service sessions (typically 3).
26  BsdServiceType bsd_service_type; ///< BSD service type (typically \ref BsdServiceType_User).
28 
29 /// Fetch the default configuration for the socket driver.
30 const SocketInitConfig *socketGetDefaultInitConfig(void);
31 /// Initalize the socket driver.
32 Result socketInitialize(const SocketInitConfig *config);
33 /// Fetch the last bsd:u/s Switch result code (thread-local).
34 Result socketGetLastResult(void);
35 /// Deinitialize the socket driver.
36 void socketExit(void);
37 
38 /// Initalize the socket driver using the default configuration.
39 NX_INLINE Result socketInitializeDefault(void) {
40  return socketInitialize(NULL);
41 }
42 
43 /// 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.
44 int socketSslConnectionSetSocketDescriptor(SslConnection *c, int sockfd);
45 
46 /// Wrapper for \ref sslConnectionGetSocketDescriptor. Returns the output sockfd on success and -1 on error.
47 int socketSslConnectionGetSocketDescriptor(SslConnection *c);
48 
SocketInitConfig::bsdsockets_version
u32 bsdsockets_version
Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
Definition: socket.h:13
SocketInitConfig::tcp_tx_buf_size
u32 tcp_tx_buf_size
Size of the TCP transfer (send) buffer (initial or fixed).
Definition: socket.h:15
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
SocketInitConfig::num_bsd_sessions
u32 num_bsd_sessions
Number of BSD service sessions (typically 3).
Definition: socket.h:25
SocketInitConfig::tcp_tx_buf_max_size
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:17
SocketInitConfig::udp_tx_buf_size
u32 udp_tx_buf_size
Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
Definition: socket.h:20
SocketInitConfig::udp_rx_buf_size
u32 udp_rx_buf_size
Size of the UDP receive buffer (typically 0xA500 bytes).
Definition: socket.h:21
SocketInitConfig::sb_efficiency
u32 sb_efficiency
Number of buffers for each socket (standard values range from 1 to 8).
Definition: socket.h:23
SocketInitConfig
Configuration structure for socketInitalize.
Definition: socket.h:12
Result
u32 Result
Function error code result type.
Definition: types.h:44
SocketInitConfig::bsd_service_type
BsdServiceType bsd_service_type
BSD service type (typically BsdServiceType_User).
Definition: socket.h:26
SslConnection
SslConnection.
Definition: ssl.h:162
SocketInitConfig::tcp_rx_buf_size
u32 tcp_rx_buf_size
Size of the TCP receive buffer (initial or fixed).
Definition: socket.h:16
BIT
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:54
SocketInitConfig::tcp_rx_buf_max_size
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:18
NX_INLINE
#define NX_INLINE
Flags a function as (always) inline.
Definition: types.h:82