}
LWS_VISIBLE int
-lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
-{
- (void)context;
- (void)timeout_ms;
-#if 0
- int n;
- int m;
- char buf;
-#ifdef LWS_OPENSSL_SUPPORT
- struct libwebsocket *wsi, *wsi_next;
-#endif
-
- /* stay dead once we are dead */
-
- if (!context)
- return 1;
-
- lws_libev_run(context);
-
- context->service_tid = context->protocols[0].callback(context, NULL,
- LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
-
-#ifdef LWS_OPENSSL_SUPPORT
- /* if we know we have non-network pending data, do not wait in poll */
- if (lws_ssl_anybody_has_buffered_read(context))
- timeout_ms = 0;
-#endif
- n = poll(context->fds, context->fds_count, timeout_ms);
- context->service_tid = 0;
-
-#ifdef LWS_OPENSSL_SUPPORT
- if (!lws_ssl_anybody_has_buffered_read(context) && n == 0) {
-#else
- if (n == 0) /* poll timeout */ {
-#endif
- libwebsocket_service_fd(context, NULL);
- return 0;
- }
-
- if (n < 0) {
- if (LWS_ERRNO != LWS_EINTR)
- return -1;
- return 0;
- }
-
- /* any socket with events to service? */
-
- for (n = 0; n < context->fds_count; n++) {
-
- if (!context->fds[n].revents)
- continue;
-
- if (context->fds[n].fd == context->dummy_pipe_fds[0]) {
- if (read(context->fds[n].fd, &buf, 1) != 1)
- lwsl_err("Cannot read from dummy pipe.");
- continue;
- }
-
- m = libwebsocket_service_fd(context, &context->fds[n]);
- if (m < 0)
- return -1;
- /* if something closed, retry this slot */
- if (m)
- n--;
- }
-#endif
- return 0;
-}
-
-LWS_VISIBLE int
lws_plat_set_socket_options(struct libwebsocket_context *context, lws_sockfd_type fd)
{
(void)context;
}
LWS_VISIBLE int
-lws_plat_change_pollfd(struct libwebsocket_context *context,
- struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
-{
- (void)context;
- (void)wsi;
- (void)pfd;
-
- return 0;
-}
-
-LWS_VISIBLE int
lws_plat_open_file(const char* filename, unsigned long* filelen)
{
(void)filename;
delete conn;
}
+void lws_conn::serialized_writeable(struct libwebsocket *_wsi)
+{
+ struct libwebsocket *wsi = (struct libwebsocket *)_wsi;
+ struct libwebsocket_pollfd pollfd;
+ lws_conn *conn = (lws_conn *)wsi->sock;
+
+ conn->awaiting_on_writeable = 0;
+
+ pollfd.fd = wsi->sock;
+ pollfd.events = POLLOUT;
+ pollfd.revents = POLLOUT;
+
+ lwsl_debug("%s: wsi %p\r\n", __func__, (void *)wsi);
+
+ libwebsocket_service_fd(wsi->protocol->owning_server, &pollfd);
+}
+
extern "C" void mbed3_tcp_stream_bind(void *sock, int port, struct libwebsocket *wsi)
{
lws_conn_listener *srv = (lws_conn_listener *)sock;
- lwsl_info("%s\r\n", __func__);
+ lwsl_debug("%s\r\n", __func__);
/* associate us with the listening wsi */
((lws_conn *)srv)->set_wsi(wsi);
{
lws_conn *conn = (lws_conn *)sock;
- lwsl_info("%s\r\n", __func__);
+ lwsl_debug("%s\r\n", __func__);
conn->set_wsi(wsi);
}
extern "C" LWS_VISIBLE int
+lws_plat_change_pollfd(struct libwebsocket_context *context,
+ struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd)
+{
+ lws_conn *conn = (lws_conn *)wsi->sock;
+
+ (void)context;
+ if (pfd->events & POLLOUT) {
+ conn->awaiting_on_writeable = 1;
+ if (conn->writeable) {
+ mbed::util::FunctionPointer1<void, struct libwebsocket *> book(conn, &lws_conn::serialized_writeable);
+ minar::Scheduler::postCallback(book.bind(wsi));
+ lwsl_debug("%s: wsi %p (booked callback)\r\n", __func__, (void *)wsi);
+ } else {
+
+ lwsl_debug("%s: wsi %p (set awaiting_on_writeable)\r\n", __func__, (void *)wsi);
+ }
+ } else
+ conn->awaiting_on_writeable = 0;
+
+ return 0;
+}
+
+extern "C" LWS_VISIBLE int
lws_ssl_capable_read_no_ssl(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned char *buf, int len)
{
socket_error_t err;
size_t _len = len;
-
+
lwsl_debug("%s\r\n", __func__);
(void)context;
- /* s/s_HACK/ts/g when mbed3 listen payload bug fixed */
- err = ((lws_conn *)wsi->sock)->s_HACK->recv((char *)buf, &_len);
+ err = ((lws_conn *)wsi->sock)->ts->recv((char *)buf, &_len);
if (err == SOCKET_ERROR_NONE) {
lwsl_info("%s: got %d bytes\n", __func__, _len);
return _len;
#endif
return LWS_SSL_CAPABLE_MORE_SERVICE;
- // !!! while listen payload mbed3 bug, don't error out if nothing */
-// if (((lws_conn *)wsi->sock)->s_HACK != ((Socket *)((lws_conn *)wsi->sock)->ts))
-// return 0;
-
lwsl_warn("error on reading from skt: %d\n", err);
return LWS_SSL_CAPABLE_ERROR;
}
lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int len)
{
socket_error_t err;
+ lws_conn *conn = (lws_conn *)wsi->sock;
lwsl_debug("%s: wsi %p: write %d (from %p)\n", __func__, (void *)wsi, len, (void *)buf);
- err = ((lws_conn *)wsi->sock)->ts->send((char *)buf, len);
+ lwsl_debug("%s: wsi %p: clear writeable\n", __func__, (void *)wsi);
+ conn->writeable = 0;
+
+ err = conn->ts->send((char *)buf, len);
if (err == SOCKET_ERROR_NONE)
return len;
int lws_conn::actual_onRX(Socket *s)
{
struct libwebsocket_pollfd pollfd;
+
+ (void)s;
pollfd.fd = this;
pollfd.events = POLLIN;
lwsl_debug("%s: lws %p\n", __func__, wsi);
- s_HACK = s;
-
return libwebsocket_service_fd(wsi->protocol->owning_server, &pollfd);
}
//if (s)
//delete this;
}
+
+extern "C" LWS_VISIBLE int
+lws_plat_service(struct libwebsocket_context *context, int timeout_ms)
+{
+ (void)context;
+ (void)timeout_ms;
+
+ return 0;
+}
+
void lws_conn::onSent(Socket *s, uint16_t len)
{
struct libwebsocket_pollfd pollfd;
(void)s;
(void)len;
+
+ if (!awaiting_on_writeable) {
+ lwsl_debug("%s: wsi %p (setting writable=1)\r\n", __func__, (void *)wsi);
+ writeable = 1;
+ return;
+ }
+
+ writeable = 1;
- pollfd.fd = this;
+ pollfd.fd = wsi->sock;
pollfd.events = POLLOUT;
pollfd.revents = POLLOUT;
-
- s_HACK = s;
- lwsl_debug("%s: wsi %p\r\n", __func__, (void *)wsi);
+ lwsl_debug("%s: wsi %p (servicing now)\r\n", __func__, (void *)wsi);
libwebsocket_service_fd(wsi->protocol->owning_server, &pollfd);
}