From 950a428641808b5d083dcfddebbed06367f15a15 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 10 Jan 2015 13:47:51 +0100 Subject: [PATCH] Made compilation with latest mongoose possible (nw) --- 3rdparty/mongoose/mongoose.c | 2 +- src/emu/luaengine.c | 2 +- src/emu/webengine.c | 23 +++++++++++------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/3rdparty/mongoose/mongoose.c b/3rdparty/mongoose/mongoose.c index 0cacdfed470..0be5cfd1ca1 100644 --- a/3rdparty/mongoose/mongoose.c +++ b/3rdparty/mongoose/mongoose.c @@ -370,7 +370,7 @@ void iobuf_remove(struct iobuf *io, size_t n) { static size_t ns_out(struct ns_connection *nc, const void *buf, size_t len) { if (nc->flags & NSF_UDP) { - long n = sendto(nc->sock, buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin)); + long n = sendto(nc->sock, (const char*)buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin)); DBG(("%p %d send %ld (%d %s)", nc, nc->sock, n, errno, strerror(errno))); return n < 0 ? 0 : n; } else { diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c index 984a47195a4..ddd6a8b5997 100644 --- a/src/emu/luaengine.c +++ b/src/emu/luaengine.c @@ -18,7 +18,7 @@ #include "osdepend.h" #include "drivenum.h" #include "ui/ui.h" -#include "web/mongoose.h" +#include "mongoose/mongoose.h" //************************************************************************** // LUA ENGINE diff --git a/src/emu/webengine.c b/src/emu/webengine.c index c7fc8952f8a..ac81afe09a7 100644 --- a/src/emu/webengine.c +++ b/src/emu/webengine.c @@ -8,7 +8,7 @@ ***************************************************************************/ -#include "web/mongoose.h" +#include "mongoose/mongoose.h" #include "web/json/json.h" #include "emu.h" #include "emuopts.h" @@ -455,7 +455,7 @@ int web_engine::begin_request_handler(struct mg_connection *conn) mg_send_header(conn, "Cache-Control", "no-cache, no-store, must-revalidate"); mg_send_header(conn, "Pragma", "no-cache"); mg_send_header(conn, "Expires", "0"); - mg_send_file(conn, fullpath.cstr()); + mg_send_file(conn, fullpath.cstr(), NULL); return MG_MORE; // It is important to return MG_MORE after mg_send_file! } return 0; @@ -531,16 +531,15 @@ void web_engine::serve() if (m_http) mg_poll_server(m_server, 0); } -static int websocket_callback(struct mg_connection *c, enum mg_event ev) { - if (c->is_websocket) { - const char *message = (const char *)c->callback_param; - mg_websocket_write(c, 1, message, strlen(message)); - } - return MG_TRUE; -} - void web_engine::push_message(const char *message) { - if (m_server!=NULL) - mg_iterate_over_connections(m_server, websocket_callback, (void*)message); + struct mg_connection *c; + if (m_server!=NULL) { + // Iterate over all connections, and push current time message to websocket ones. + for (c = mg_next(m_server, NULL); c != NULL; c = mg_next(m_server, c)) { + if (c->is_websocket) { + mg_websocket_write(c, 1, message, strlen(message)); + } + } + } }