mirror of
https://github.com/holub/mame
synced 2025-10-07 01:16:22 +03:00
Do web serving in main thread (nw)
This commit is contained in:
parent
98942bb612
commit
d14d6a8099
@ -1931,6 +1931,8 @@ void device_debug::instruction_hook(offs_t curpc)
|
||||
// flush any pending updates before waiting again
|
||||
machine.debug_view().flush_osd_updates();
|
||||
|
||||
machine.manager().web()->serve();
|
||||
|
||||
// clear the memory modified flag and wait
|
||||
global->memory_modified = false;
|
||||
if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)
|
||||
|
@ -372,6 +372,8 @@ int running_machine::run(bool firstrun)
|
||||
js_set_main_loop(this);
|
||||
#endif
|
||||
|
||||
manager().web()->serve();
|
||||
|
||||
// execute CPUs if not paused
|
||||
if (!m_paused)
|
||||
m_scheduler.timeslice();
|
||||
|
@ -360,7 +360,10 @@ void ui_manager::display_startup_screens(bool first_time, bool show_disclaimer)
|
||||
|
||||
// loop while we have a handler
|
||||
while (m_handler_callback != handler_ingame && !machine().scheduled_event_pending() && !ui_menu::stack_has_special_main_menu())
|
||||
{
|
||||
machine().manager().web()->serve();
|
||||
machine().video().frame_update();
|
||||
}
|
||||
|
||||
// clear the handler and force an update
|
||||
set_handler(handler_ingame, 0);
|
||||
|
@ -287,27 +287,6 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||
}
|
||||
}
|
||||
|
||||
static int iterate_callback(struct mg_connection *c, enum mg_event ev) {
|
||||
if (ev == MG_POLL && c->is_websocket) {
|
||||
char buf[20];
|
||||
int len = snprintf(buf, sizeof(buf), "%lu",
|
||||
(unsigned long) * (time_t *) c->callback_param);
|
||||
mg_websocket_write(c, 1, buf, len);
|
||||
}
|
||||
return MG_TRUE;
|
||||
}
|
||||
|
||||
static void *serve(void *server) {
|
||||
time_t current_timer = 0, last_timer = time(NULL);
|
||||
for (;;) mg_poll_server((struct mg_server *) server, 1000);
|
||||
current_timer = time(NULL);
|
||||
if (current_timer - last_timer > 0) {
|
||||
last_timer = current_timer;
|
||||
mg_iterate_over_connections((struct mg_server *)server, iterate_callback, ¤t_timer);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// web_engine - constructor
|
||||
//-------------------------------------------------
|
||||
@ -325,8 +304,6 @@ web_engine::web_engine(emu_options &options)
|
||||
|
||||
mg_set_option(m_server, "listening_port", options.http_port());
|
||||
mg_set_option(m_server, "document_root", options.http_path());
|
||||
|
||||
mg_start_thread(serve, m_server);
|
||||
}
|
||||
|
||||
}
|
||||
@ -352,6 +329,11 @@ void web_engine::close()
|
||||
mg_destroy_server(&m_server);
|
||||
}
|
||||
|
||||
void web_engine::serve()
|
||||
{
|
||||
if (m_options.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;
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
web_engine(emu_options &options);
|
||||
~web_engine();
|
||||
|
||||
void serve();
|
||||
void push_message(const char *message);
|
||||
void close();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user