libnx
bsd.h
Go to the documentation of this file.
1 /**
2  * @file bsd.h
3  * @brief BSD sockets (bsd:u/s) service IPC wrapper. Please use socket.c instead.
4  * @author plutoo
5  * @author TuxSH
6  * @copyright libnx Authors
7  */
8 #pragma once
9 #include <sys/socket.h> // for socklen_t
10 #include <sys/select.h> // for fd_set
11 #include <poll.h> // for struct pollfd, ndfs_t
12 
13 #include "../types.h"
14 #include "../kernel/tmem.h"
15 
16 /// Configuration structure for bsdInitalize
17 typedef struct {
18  u32 version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
19 
20  u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
21  u32 tcp_rx_buf_size; ///< Size of the TCP recieve buffer (initial or fixed).
22  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.
23  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.
24 
25  u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
26  u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes).
27 
28  u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8).
30 
31 extern __thread Result g_bsdResult; ///< Last Switch "result", per-thread
32 extern __thread int g_bsdErrno; ///< Last errno, per-thread
33 
34 /// Fetch the default configuration for bsdInitialize.
36 /// Initialize the BSD service.
37 Result bsdInitialize(const BsdInitConfig *config);
38 /// Deinitialize the BSD service.
39 void bsdExit(void);
40 
41 int bsdSocket(int domain, int type, int protocol);
42 /// Like @ref bsdSocket but the newly created socket is immediately shut down.
43 int bsdSocketExempt(int domain, int type, int protocol);
44 int bsdOpen(const char *pathname, int flags);
45 int bsdSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
46 int bsdPoll(struct pollfd *fds, nfds_t nfds, int timeout);
47 int bsdSysctl(const int *name, unsigned int namelen, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
48 ssize_t bsdRecv(int sockfd, void *buf, size_t len, int flags);
49 ssize_t bsdRecvFrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
50 ssize_t bsdSend(int sockfd, const void* buf, size_t len, int flags);
51 ssize_t bsdSendTo(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
52 int bsdAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
53 int bsdBind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
54 int bsdConnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
55 int bsdGetPeerName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
56 int bsdGetSockName(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
57 int bsdGetSockOpt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
58 int bsdListen(int sockfd, int backlog);
59 /// Made non-variadic for convenience.
60 int bsdIoctl(int fd, int request, void *data);
61 /// Made non-variadic for convenience.
62 int bsdFcntl(int fd, int cmd, int flags);
63 int bsdSetSockOpt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
64 int bsdShutdown(int sockfd, int how);
65 int bsdShutdownAllSockets(int how);
66 ssize_t bsdWrite(int fd, const void *buf, size_t count);
67 ssize_t bsdRead(int fd, void *buf, size_t count);
68 int bsdClose(int fd);
69 /// Duplicate a socket (bsd:s).
70 int bsdDuplicateSocket(int sockfd);
71 
72 // TODO: Reverse-engineer GetResourceStatistics. Implement sendmmsg/recvmmsg (custom (un)serialization)
73 
74 /// Initialize the BSD service using the default configuration.
75 static inline Result bsdInitializeDefault(void) {
77 }
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: bsd.h:22
int bsdIoctl(int fd, int request, void *data)
Made non-variadic for convenience.
Result bsdInitialize(const BsdInitConfig *config)
Initialize the BSD service.
u32 Result
Function error code result type.
Definition: types.h:46
__thread int g_bsdErrno
Last errno, per-thread.
u32 udp_rx_buf_size
Size of the UDP receive buffer (typically 0xA500 bytes).
Definition: bsd.h:26
static Result bsdInitializeDefault(void)
Initialize the BSD service using the default configuration.
Definition: bsd.h:75
uint32_t u32
32-bit unsigned integer.
Definition: types.h:23
const BsdInitConfig * bsdGetDefaultInitConfig(void)
Fetch the default configuration for bsdInitialize.
void bsdExit(void)
Deinitialize the BSD service.
u32 sb_efficiency
Number of buffers for each socket (standard values range from 1 to 8).
Definition: bsd.h:28
u32 udp_tx_buf_size
Size of the UDP transfer (send) buffer (typically 0x2400 bytes).
Definition: bsd.h:25
u32 tcp_tx_buf_size
Size of the TCP transfer (send) buffer (initial or fixed).
Definition: bsd.h:20
Configuration structure for bsdInitalize.
Definition: bsd.h:17
int bsdSocketExempt(int domain, int type, int protocol)
Like bsdSocket but the newly created socket is immediately shut down.
u32 tcp_rx_buf_size
Size of the TCP recieve buffer (initial or fixed).
Definition: bsd.h:21
int bsdFcntl(int fd, int cmd, int flags)
Made non-variadic for convenience.
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: bsd.h:23
int bsdDuplicateSocket(int sockfd)
Duplicate a socket (bsd:s).
u32 version
Observed 1 on 2.0 LibAppletWeb, 2 on 3.0.
Definition: bsd.h:18
__thread Result g_bsdResult
Last Switch "result", per-thread.