libnx  v4.8.0
htcs.h
Go to the documentation of this file.
1 /**
2  * @file htcs.h
3  * @brief HTC sockets (htcs) service IPC wrapper. Please use <<TODO>> instead.
4  * @author SciresM
5  * @copyright libnx Authors
6  */
7 #pragma once
8 
9 #include "../types.h"
10 #include "../sf/service.h"
11 
12 #define HTCS_PEER_NAME_MAX 32
13 #define HTCS_PORT_NAME_MAX 32
14 
15 #define HTCS_SESSION_COUNT_MAX 0x10
16 #define HTCS_SOCKET_COUNT_MAX 40
17 #define HTCS_FD_SET_SIZE HTCS_SOCKET_COUNT_MAX
18 
19 typedef uint16_t HtcsAddressFamilyType;
20 
21 typedef struct {
22  char name[HTCS_PEER_NAME_MAX];
23 } HtcsPeerName;
24 
25 typedef struct {
26  char name[HTCS_PORT_NAME_MAX];
27 } HtcsPortName;
28 
29 typedef struct {
30  HtcsAddressFamilyType family;
31  HtcsPeerName peer_name;
32  HtcsPortName port_name;
33 } HtcsSockAddr;
34 
35 typedef struct {
36  s64 tv_sec;
37  s64 tv_usec;
38 } HtcsTimeVal;
39 
40 typedef struct {
41  int fds[HTCS_FD_SET_SIZE];
42 } HtcsFdSet;
43 
44 typedef enum {
45  HTCS_ENONE = 0,
46  HTCS_EACCES = 2,
47  HTCS_EADDRINUSE = 3,
48  HTCS_EADDRNOTAVAIL = 4,
49  HTCS_EAGAIN = 6,
50  HTCS_EALREADY = 7,
51  HTCS_EBADF = 8,
52  HTCS_EBUSY = 10,
53  HTCS_ECONNABORTED = 13,
54  HTCS_ECONNREFUSED = 14,
55  HTCS_ECONNRESET = 15,
56  HTCS_EDESTADDRREQ = 17,
57  HTCS_EFAULT = 21,
58  HTCS_EINPROGRESS = 26,
59  HTCS_EINTR = 27,
60  HTCS_EINVAL = 28,
61  HTCS_EIO = 29,
62  HTCS_EISCONN = 30,
63  HTCS_EMFILE = 33,
64  HTCS_EMSGSIZE = 35,
65  HTCS_ENETDOWN = 38,
66  HTCS_ENETRESET = 39,
67  HTCS_ENOBUFS = 42,
68  HTCS_ENOMEM = 49,
69  HTCS_ENOTCONN = 56,
70  HTCS_ETIMEDOUT = 76,
71  HTCS_EUNKNOWN = 79,
72 
73  HTCS_EWOULDBLOCK = HTCS_EAGAIN,
74 } HtcsSocketError;
75 
76 typedef enum {
77  HTCS_MSG_PEEK = 1,
78  HTCS_MSG_WAITALL = 2,
79 } HtcsMessageFlag;
80 
81 typedef enum {
82  HTCS_SHUT_RD = 0,
83  HTCS_SHUT_WR = 1,
84  HTCS_SHUT_RDWR = 2,
85 } HtcsShutdownType;
86 
87 typedef enum {
88  HTCS_F_GETFL = 3,
89  HTCS_F_SETFL = 4,
90 } HtcsFcntlOperation;
91 
92 typedef enum {
93  HTCS_O_NONBLOCK = 4,
94 } HtcsFcntlFlag;
95 
96 typedef enum {
97  HTCS_AF_HTCS = 0,
98 } HtcsAddressFamily;
99 
100 typedef struct {
101  Service s;
102 } HtcsSocket;
103 
104 
105 /// Initialize the HTCS service.
106 Result htcsInitialize(u32 num_sessions);
107 
108 /// Exit the HTCS service.
109 void htcsExit(void);
110 
111 /// Gets the Service object for the actual HTCS manager service session.
113 
114 /// Gets the Service object for the actual HTCS monitor service session.
116 
117 /// Manager functionality.
119 Result htcsGetDefaultHostName(HtcsPeerName *out);
120 Result htcsCreateSocket(s32 *out_err, HtcsSocket *out, bool enable_disconnection_emulation);
121 Result htcsStartSelect(u32 *out_task_id, Handle *out_event_handle, const s32 *read, size_t num_read, const s32 *write, size_t num_write, const s32 *except, size_t num_except, s64 tv_sec, s64 tv_usec);
122 Result htcsEndSelect(s32 *out_err, s32 *out_count, s32 *read, size_t num_read, s32 *write, size_t num_write, s32 *except, size_t num_except, u32 task_id);
123 
124 /// Socket functionality.
125 Result htcsSocketClose(HtcsSocket *s, s32 *out_err, s32 *out_res);
126 Result htcsSocketConnect(HtcsSocket *s, s32 *out_err, s32 *out_res, const HtcsSockAddr *address);
127 Result htcsSocketBind(HtcsSocket *s, s32 *out_err, s32 *out_res, const HtcsSockAddr *address);
128 Result htcsSocketListen(HtcsSocket *s, s32 *out_err, s32 *out_res, s32 backlog_count);
129 Result htcsSocketShutdown(HtcsSocket *s, s32 *out_err, s32 *out_res, s32 how);
130 Result htcsSocketFcntl(HtcsSocket *s, s32 *out_err, s32 *out_res, s32 command, s32 value);
131 
132 Result htcsSocketAcceptStart(HtcsSocket *s, u32 *out_task_id, Handle *out_event_handle);
133 Result htcsSocketAcceptResults(HtcsSocket *s, s32 *out_err, HtcsSocket *out_socket, HtcsSockAddr *out_address, u32 task_id);
134 
135 Result htcsSocketRecvStart(HtcsSocket *s, u32 *out_task_id, Handle *out_event_handle, s32 mem_size, s32 flags);
136 Result htcsSocketRecvResults(HtcsSocket *s, s32 *out_err, s64 *out_size, void *buffer, size_t buffer_size, u32 task_id);
137 
138 Result htcsSocketSendStart(HtcsSocket *s, u32 *out_task_id, Handle *out_event_handle, const void *buffer, size_t buffer_size, s32 flags);
139 Result htcsSocketSendResults(HtcsSocket *s, s32 *out_err, s64 *out_size, u32 task_id);
140 
141 Result htcsSocketStartSend(HtcsSocket *s, u32 *out_task_id, Handle *out_event_handle, s64 *out_max_size, s64 size, s32 flags);
142 Result htcsSocketContinueSend(HtcsSocket *s, s64 *out_size, bool *out_wait, const void *buffer, size_t buffer_size, u32 task_id);
143 Result htcsSocketEndSend(HtcsSocket *s, s32 *out_err, s64 *out_size, u32 task_id);
144 
145 Result htcsSocketStartRecv(HtcsSocket *s, u32 *out_task_id, Handle *out_event_handle, s64 size, s32 flags);
146 Result htcsSocketEndRecv(HtcsSocket *s, s32 *out_err, s64 *out_size, void *buffer, size_t buffer_size, u32 task_id);
147 
148 Result htcsSocketGetPrimitive(HtcsSocket *s, s32 *out);
149 
150 void htcsCloseSocket(HtcsSocket *s);
Service * htcsGetMonitorServiceSession(void)
Gets the Service object for the actual HTCS monitor service session.
void htcsExit(void)
Exit the HTCS service.
Result htcsGetPeerNameAny(HtcsPeerName *out)
Manager functionality.
Result htcsInitialize(u32 num_sessions)
Initialize the HTCS service.
Service * htcsGetManagerServiceSession(void)
Gets the Service object for the actual HTCS manager service session.
Result htcsSocketClose(HtcsSocket *s, s32 *out_err, s32 *out_res)
Socket functionality.
Definition: htcs.h:40
Definition: htcs.h:21
Definition: htcs.h:25
Definition: htcs.h:29
Definition: htcs.h:100
Definition: htcs.h:35
Service object structure.
Definition: service.h:14
int64_t s64
64-bit signed integer.
Definition: types.h:28
u32 Handle
Kernel object handle.
Definition: types.h:43
u32 Result
Function error code result type.
Definition: types.h:44
int32_t s32
32-bit signed integer.
Definition: types.h:27
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21