trunk/3rdparty/mongoose/mongoose.c
| r242829 | r242830 | |
| 370 | 370 | |
| 371 | 371 | static size_t ns_out(struct ns_connection *nc, const void *buf, size_t len) { |
| 372 | 372 | if (nc->flags & NSF_UDP) { |
| 373 | | long n = sendto(nc->sock, buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin)); |
| 373 | long n = sendto(nc->sock, (const char*)buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin)); |
| 374 | 374 | DBG(("%p %d send %ld (%d %s)", nc, nc->sock, n, errno, strerror(errno))); |
| 375 | 375 | return n < 0 ? 0 : n; |
| 376 | 376 | } else { |
trunk/src/emu/webengine.c
| r242829 | r242830 | |
| 8 | 8 | |
| 9 | 9 | ***************************************************************************/ |
| 10 | 10 | |
| 11 | | #include "web/mongoose.h" |
| 11 | #include "mongoose/mongoose.h" |
| 12 | 12 | #include "web/json/json.h" |
| 13 | 13 | #include "emu.h" |
| 14 | 14 | #include "emuopts.h" |
| r242829 | r242830 | |
| 455 | 455 | mg_send_header(conn, "Cache-Control", "no-cache, no-store, must-revalidate"); |
| 456 | 456 | mg_send_header(conn, "Pragma", "no-cache"); |
| 457 | 457 | mg_send_header(conn, "Expires", "0"); |
| 458 | | mg_send_file(conn, fullpath.cstr()); |
| 458 | mg_send_file(conn, fullpath.cstr(), NULL); |
| 459 | 459 | return MG_MORE; // It is important to return MG_MORE after mg_send_file! |
| 460 | 460 | } |
| 461 | 461 | return 0; |
| r242829 | r242830 | |
| 531 | 531 | if (m_http) mg_poll_server(m_server, 0); |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | | static int websocket_callback(struct mg_connection *c, enum mg_event ev) { |
| 535 | | if (c->is_websocket) { |
| 536 | | const char *message = (const char *)c->callback_param; |
| 537 | | mg_websocket_write(c, 1, message, strlen(message)); |
| 538 | | } |
| 539 | | return MG_TRUE; |
| 540 | | } |
| 541 | | |
| 542 | 534 | void web_engine::push_message(const char *message) |
| 543 | 535 | { |
| 544 | | if (m_server!=NULL) |
| 545 | | mg_iterate_over_connections(m_server, websocket_callback, (void*)message); |
| 536 | struct mg_connection *c; |
| 537 | if (m_server!=NULL) { |
| 538 | // Iterate over all connections, and push current time message to websocket ones. |
| 539 | for (c = mg_next(m_server, NULL); c != NULL; c = mg_next(m_server, c)) { |
| 540 | if (c->is_websocket) { |
| 541 | mg_websocket_write(c, 1, message, strlen(message)); |
| 542 | } |
| 543 | } |
| 544 | } |
| 546 | 545 | } |