win32 more build fixes
[platform/upstream/libwebsockets.git] / lib / lws-plat-mbed3.c
1 #include "private-libwebsockets.h"
2
3 /*
4  * included from libwebsockets.c for MBED3 builds
5  * MBED3 is an "OS" for very small embedded systems.
6  * He doesn't have Posix semantics or apis.
7  * But he has things like TCP sockets.
8  */
9
10 unsigned long long time_in_microseconds(void)
11 {
12         return 0;
13 }
14
15 LWS_VISIBLE int lws_get_random(struct lws_context *context, void *buf, int len)
16 {
17         int n = len;
18         unsigned char *b = (unsigned char *)buf;
19
20         (void)context;
21
22         while (n--)
23                 b[n]= rand();
24         return len;
25 }
26
27 /*
28  * MBED3 does not have a 'kernel' which takes copies of what userland wants
29  * to send.  The user application must hold the tx buffer until it is informed
30  * that send of the user buffer was complete.
31  *
32  * So as soon as you send something the pipe is globally choked.
33  *
34  * There is no concept of additional sent things being maybe acceptable.
35  * You can send one thing up to 64KB at a time and may not try to send
36  * anything else until that is completed.
37  *
38  * You can send things on other sockets, but they cannot complete until they
39  * get their turn at the network device.
40  */
41
42 LWS_VISIBLE int lws_send_pipe_choked(struct lws *wsi)
43 {
44 #if 0
45         struct lws_pollfd fds;
46
47         /* treat the fact we got a truncated send pending as if we're choked */
48         if (wsi->trunc_len)
49                 return 1;
50
51         fds.fd = wsi->sock;
52         fds.events = POLLOUT;
53         fds.revents = 0;
54
55         if (poll(&fds, 1, 0) != 1)
56                 return 1;
57
58         if ((fds.revents & POLLOUT) == 0)
59                 return 1;
60
61         /* okay to send another packet without blocking */
62 #endif
63         (void)wsi;
64         return 0;
65 }
66
67 LWS_VISIBLE int
68 lws_poll_listen_fd(struct lws_pollfd *fd)
69 {
70         (void)fd;
71         return -1;
72 }
73
74 /**
75  * lws_cancel_service() - Cancel servicing of pending websocket activity
76  * @context:    Websocket context
77  *
78  *      This function let a call to lws_service() waiting for a timeout
79  *      immediately return.
80  *
81  *      There is no poll() in MBED3, he will fire callbacks when he feels like
82  *      it.
83  */
84 LWS_VISIBLE void
85 lws_cancel_service(struct lws_context *context)
86 {
87         (void)context;
88 }
89
90 LWS_VISIBLE void
91 lws_cancel_service_pt(struct lws *wsi)
92 {
93         (void)wsi;
94 }
95
96 LWS_VISIBLE void lwsl_emit_syslog(int level, const char *line)
97 {
98         printf("%d: %s", level, line);
99 }
100
101 LWS_VISIBLE int
102 lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd)
103 {
104         (void)context;
105         (void)fd;
106         return 0;
107 }
108
109 LWS_VISIBLE void
110 lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
111 {
112         (void)info;
113 }
114
115 LWS_VISIBLE int
116 lws_plat_context_early_init(void)
117 {
118         return 0;
119 }
120
121 LWS_VISIBLE void
122 lws_plat_context_early_destroy(struct lws_context *context)
123 {
124         (void)context;
125 }
126
127 LWS_VISIBLE void
128 lws_plat_context_late_destroy(struct lws_context *context)
129 {
130         (void)context;
131 }
132
133
134 LWS_VISIBLE void
135 lws_plat_service_periodic(struct lws_context *context)
136 {
137         (void)context;
138 }
139
140 LWS_VISIBLE const char *
141 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt)
142 {
143         (void)af;
144         (void)src;
145         (void)dst;
146         (void)cnt;
147         return "unsupported";
148 }
149
150 LWS_VISIBLE int
151 insert_wsi(struct lws_context *context, struct lws *wsi)
152 {
153         (void)context;
154         (void)wsi;
155
156         return 0;
157 }
158
159 LWS_VISIBLE int
160 delete_from_fd(struct lws_context *context, lws_sockfd_type fd)
161 {
162         (void)context;
163         (void)fd;
164
165         return 1;
166 }
167
168 static lws_filefd_type
169 _lws_plat_file_open(struct lws *wsi, const char *filename,
170                     unsigned long *filelen, int flags)
171 {
172         (void)wsi;
173         (void)filename;
174         (void)filelen;
175         (void)flags;
176         return NULL;
177 }
178
179 static int
180 _lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
181 {
182         (void)wsi;
183         (void)fd;
184         return -1;
185 }
186
187 unsigned long
188 _lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
189 {
190         (void)wsi;
191         (void)fd;
192         (void)offset;
193
194         return -1;
195 }
196
197 static int
198 _lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
199                     unsigned char *buf, unsigned long len)
200 {
201         (void)wsi;
202         (void)amount;
203         (void)fd;
204         (void)buf;
205         (void)len;
206
207         return -1;
208 }
209
210 static int
211 _lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
212                      unsigned char *buf, unsigned long len)
213 {
214         (void)wsi;
215         (void)amount;
216         (void)fd;
217         (void)buf;
218         (void)len;
219
220         return -1;
221 }
222
223 LWS_VISIBLE int
224 lws_plat_init(struct lws_context *context,
225               struct lws_context_creation_info *info)
226 {
227         (void)info;
228
229         context->fops.open      = _lws_plat_file_open;
230         context->fops.close     = _lws_plat_file_close;
231         context->fops.seek_cur  = _lws_plat_file_seek_cur;
232         context->fops.read      = _lws_plat_file_read;
233         context->fops.write     = _lws_plat_file_write;
234
235         return 0;
236 }