static void RunEventsIfNeeded() { unique_ptr<WStatus> pStatus(session()->status_manager()->GetStatus()); if (!IsEquals(date(), pStatus->GetLastDate())) { if ((session()->GetBeginDayNodeNumber() == 0) || (session()->instance_number() == session()->GetBeginDayNodeNumber())) { cleanup_events(); beginday(true); } } if (!do_event) { check_event(); } while (do_event) { run_event(do_event - 1); check_event(); } session()->SetCurrentSpeed("KB"); static time_t last_time_c = 0; time_t lCurrentTime = time(nullptr); if ((((rand() % 8000) == 0) || (lCurrentTime - last_time_c > 1200)) && net_sysnum) { lCurrentTime = last_time_c; attempt_callout(); } }
//----------------------------------------------------------------------------- // Main... process command line parameters, and then setup our listening // sockets and event loop. int main(int argc, char **argv) { system_data_t sysdata; ///============================================================================ /// Initialization. ///============================================================================ init_sysdata(&sysdata); init_settings(&sysdata); get_options(sysdata.settings, argc, argv); init_maxconns(&sysdata); init_daemon(&sysdata); init_events(&sysdata); init_logging(&sysdata); logger(sysdata.logging, 1, "System starting up"); init_signals(&sysdata); init_buffers(&sysdata); init_servers(&sysdata); init_stats(&sysdata); init_risp(&sysdata); init_nodes(&sysdata); init_msglist(&sysdata); init_queues(&sysdata); init_controllers(&sysdata); ///============================================================================ /// Main Event Loop. ///============================================================================ // enter the event loop. logger(sysdata.logging, 1, "Starting Event Loop"); assert(sysdata.evbase); event_base_loop(sysdata.evbase, 0); logger(sysdata.logging, 1, "Shutdown preparations complete. Shutting down now."); ///============================================================================ /// Shutdown ///============================================================================ cleanup_events(&sysdata); cleanup_controllers(&sysdata); cleanup_queues(&sysdata); cleanup_msglist(&sysdata); cleanup_nodes(&sysdata); cleanup_risp(&sysdata); cleanup_stats(&sysdata); cleanup_servers(&sysdata); cleanup_buffers(&sysdata); cleanup_signals(&sysdata); logger(sysdata.logging, 1, "Shutdown complete.\n"); cleanup_logging(&sysdata); cleanup_daemon(&sysdata); cleanup_maxconns(&sysdata); cleanup_settings(&sysdata); cleanup_sysdata(&sysdata); // good-bye. return 0; }
int main(void) { buffer_t buf = buf_new(1); screen_t fake, real; int rows, cols; read_dimensions(&rows, &cols); fake_screen_init(&fake, rows, cols); real_screen_init(&buf, &real, rows, cols); prepare_events(); int x = 0, y = 0; char text[cols*rows]; bool marks[cols*rows]; memset(text, ' ', sizeof text); memset(marks, 0, sizeof marks); await: { event_t e = await_event(); switch (e.type) { case E_SIG: goto quit; break; case E_KEY: switch (e.key) { case '\b': if (x > 0) x -= 1; break; case '\n': x = 0; y += 1; break; case '~': marks[x + y*cols] = !marks[x + y*cols]; x++; break; default: text[x + y*cols] = e.key; x++; break; } break; case E_UP: y -= 1; break; case E_DOWN: y += 1; break; case E_LEFT: x -= 1; break; case E_RIGHT: x += 1; break; default: break; } int cx, cy; for (cx = 0; cx < cols; cx++) { for (cy = 0; cy < rows; cy++) { fake.cells[cx + cy*cols].codes[0] = text[cx + cy*cols]; } } int j; for (j = 0; j < cols*rows; j++) { if (marks[j]) { fake.cells[j].style.back.rgb = 0xff0000; } } fake.cursor.x = x; fake.cursor.y = y; fake.cursor.visible = true; screen_flush(&buf, &fake, &real); write(STDOUT_FILENO, buf.data, buf.used); buf.used = 0; fake_screen_reset(&fake, 25, 80); goto await; } quit: cleanup_events(); real_screen_cleanup(&buf, &real); write(STDOUT_FILENO, buf.data, buf.used); screen_free(&fake); screen_free(&real); buf_free(&buf); return 0; }