1 #include "private-libwebsockets.h"
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.
10 unsigned long long time_in_microseconds(void)
15 LWS_VISIBLE int libwebsockets_get_random(struct libwebsocket_context *context,
20 unsigned char *b = (unsigned char *)buf;
27 * MBED3 does not have a 'kernel' which takes copies of what userland wants
28 * to send. The user application must hold the tx buffer until it is informed
29 * that send of the user buffer was complete.
31 * So as soon as you send something the pipe is globally choked.
33 * There is no concept of additional sent things being maybe acceptable.
34 * You can send one thing up to 64KB at a time and may not try to send
35 * anything else until that is completed.
37 * You can send things on other sockets, but they cannot complete until they
38 * get their turn at the network device.
41 LWS_VISIBLE int lws_send_pipe_choked(struct libwebsocket *wsi)
44 struct libwebsocket_pollfd fds;
46 /* treat the fact we got a truncated send pending as if we're choked */
47 if (wsi->truncated_send_len)
54 if (poll(&fds, 1, 0) != 1)
57 if ((fds.revents & POLLOUT) == 0)
60 /* okay to send another packet without blocking */
67 lws_poll_listen_fd(struct libwebsocket_pollfd *fd)
74 * libwebsocket_cancel_service() - Cancel servicing of pending websocket activity
75 * @context: Websocket context
77 * This function let a call to libwebsocket_service() waiting for a timeout
80 * There is no poll() in MBED3, he will fire callbacks when he feels like
84 libwebsocket_cancel_service(struct libwebsocket_context *context)
89 LWS_VISIBLE void lwsl_emit_syslog(int level, const char *line)
91 printf("%d: %s", level, line);
95 lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
103 #ifdef LWS_OPENSSL_SUPPORT
104 struct libwebsocket *wsi, *wsi_next;
107 /* stay dead once we are dead */
112 lws_libev_run(context);
114 context->service_tid = context->protocols[0].callback(context, NULL,
115 LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
117 #ifdef LWS_OPENSSL_SUPPORT
118 /* if we know we have non-network pending data, do not wait in poll */
119 if (lws_ssl_anybody_has_buffered_read(context))
122 n = poll(context->fds, context->fds_count, timeout_ms);
123 context->service_tid = 0;
125 #ifdef LWS_OPENSSL_SUPPORT
126 if (!lws_ssl_anybody_has_buffered_read(context) && n == 0) {
128 if (n == 0) /* poll timeout */ {
130 libwebsocket_service_fd(context, NULL);
135 if (LWS_ERRNO != LWS_EINTR)
140 /* any socket with events to service? */
142 for (n = 0; n < context->fds_count; n++) {
144 if (!context->fds[n].revents)
147 if (context->fds[n].fd == context->dummy_pipe_fds[0]) {
148 if (read(context->fds[n].fd, &buf, 1) != 1)
149 lwsl_err("Cannot read from dummy pipe.");
153 m = libwebsocket_service_fd(context, &context->fds[n]);
156 /* if something closed, retry this slot */
165 lws_plat_set_socket_options(struct libwebsocket_context *context, lws_sockfd_type fd)
173 lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
179 lws_plat_init_lookup(struct libwebsocket_context *context)
186 lws_plat_init_fd_tables(struct libwebsocket_context *context)
194 lws_plat_context_early_init(void)
200 lws_plat_context_early_destroy(struct libwebsocket_context *context)
206 lws_plat_context_late_destroy(struct libwebsocket_context *context)
213 lws_plat_service_periodic(struct libwebsocket_context *context)
219 lws_plat_change_pollfd(struct libwebsocket_context *context,
220 struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
230 lws_plat_open_file(const char* filename, unsigned long* filelen)
234 return LWS_INVALID_FILE;
237 LWS_VISIBLE const char *
238 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt)
244 return "unsupported";
248 insert_wsi(struct libwebsocket_context *context, struct libwebsocket *wsi)
257 delete_from_fd(struct libwebsocket_context *context, lws_sockfd_type fd)