standalone: revive spu_c64x build
[pcsx_rearmed.git] / deps / libretro-common / include / net / net_socket.h
1 /* Copyright  (C) 2010-2022 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (net_socket.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22
23 #ifndef _LIBRETRO_SDK_NET_SOCKET_H
24 #define _LIBRETRO_SDK_NET_SOCKET_H
25
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <boolean.h>
29
30 #include <net/net_compat.h>
31
32 #include <retro_common_api.h>
33
34 RETRO_BEGIN_DECLS
35
36 enum socket_domain
37 {
38    SOCKET_DOMAIN_INET = 0
39 };
40
41 enum socket_type
42 {
43    SOCKET_TYPE_DATAGRAM = 0,
44    SOCKET_TYPE_STREAM,
45    SOCKET_TYPE_SEQPACKET
46 };
47
48 enum socket_protocol
49 {
50    SOCKET_PROTOCOL_NONE = 0,
51    SOCKET_PROTOCOL_TCP,
52    SOCKET_PROTOCOL_UDP
53 };
54
55 typedef struct socket_target
56 {
57    unsigned port;
58    const char *server;
59    enum socket_domain domain;
60    enum socket_protocol prot;
61 } socket_target_t;
62
63 int socket_init(void **address, uint16_t port, const char *server,
64       enum socket_type type, int family);
65
66 int socket_next(void **address);
67
68 int socket_close(int fd);
69
70 bool socket_set_block(int fd, bool block);
71
72 /* TODO: all callers should be converted to socket_set_block() */
73 bool socket_nonblock(int fd);
74
75 int socket_select(int nfds, fd_set *readfds, fd_set *writefds,
76       fd_set *errorfds, struct timeval *timeout);
77
78 #ifdef NETWORK_HAVE_POLL
79 int socket_poll(struct pollfd *fds, unsigned nfds, int timeout);
80 #endif
81
82 bool socket_wait(int fd, bool *rd, bool *wr, int timeout);
83
84 bool socket_send_all_blocking(int fd, const void *data_, size_t size, bool no_signal);
85
86 bool socket_send_all_blocking_with_timeout(int fd,
87       const void *data_, size_t size,
88       int timeout, bool no_signal);
89
90 ssize_t socket_send_all_nonblocking(int fd, const void *data_, size_t size,
91       bool no_signal);
92
93 bool socket_receive_all_blocking(int fd, void *data_, size_t size);
94
95 bool socket_receive_all_blocking_with_timeout(int fd,
96       void *data_, size_t size,
97       int timeout);
98
99 ssize_t socket_receive_all_nonblocking(int fd, bool *error,
100       void *data_, size_t size);
101
102 bool socket_bind(int fd, void *data);
103
104 int socket_connect(int fd, void *data);
105
106 bool socket_connect_with_timeout(int fd, void *data, int timeout);
107
108 int socket_create(
109       const char *name,
110       enum socket_domain domain_type,
111       enum socket_type socket_type,
112       enum socket_protocol protocol_type);
113
114 void socket_set_target(void *data, socket_target_t *in_addr);
115
116 RETRO_END_DECLS
117
118 #endif