void sub_dll_flush(void) { /// (1) Put System states into the right place and flush existing events. /// (2) Reset sessions. /// (3) Set scheduler ids and prepare idle time events ot_task task; if (radio.state != RADIO_Idle) { rm2_kill(); } rm2_mac_configure(); # ifndef __KERNEL_NONE__ task = &sys.task_HSS; do { task->cursor = 0; task->reserve = 1; task->latency = 255; task->nextevent= 0; task++; } while (task < &sys.task[SSS_INDEX+1]); # endif session_init(); dll.idle_state = sub_default_idle(); dll_idle(); }
int main(int argc, char *argv[]) { session *s; session_init(&argc, &argv, &s, "Pingpong_A.spr"); if (argc < 3) return EXIT_FAILURE; int M = atoi(argv[1]); int N = atoi(argv[2]); printf("M: %d, N: %d\n", M, N); role *B = s->r(s, "B"); int val[M]; size_t sz = M; long long start_time = sc_time(); int i; for (i=0; i<N; i++) { memset(val, i, M * sizeof(int)); send_int_array(val, (size_t)M, B); sz = M; recv_int_array(val, &sz, B); } long long end_time = sc_time(); printf("%s: Time elapsed: %f sec\n", s->name, sc_time_diff(start_time, end_time)); session_end(s); return EXIT_SUCCESS; }
int main () { char * request_uri; /* Load the controller .so from this sub directory */ route_import_controllers("controllers/"); /* Initialize session system */ session_init(); while (FCGI_Accept() >= 0) { /* Record start time */ gettimeofday(&start_time,NULL); request_uri = cleanrequest( getenv("REQUEST_URI")); /* Initialize session for this request */ fprintf(stderr, "Request for %s\n", request_uri ); /* Dispatch the request to the correct controller */ route_dispatch(request_uri); free(request_uri); /* Calculate total runtime of the operation */ gettimeofday(&end_time,NULL); timeval_diff( &difference_time, &end_time, &start_time ); printf("time: %ld.%06ld\n", difference_time.tv_sec, difference_time.tv_usec); FCGI_Finish(); } fprintf(stderr, "FF Exiting\n"); return 0; }
void ebnf_start_parsing__terminal() { FsmCursor cur; //Fake main nonterminal fsm_cursor_init(&cur, &fix.fsm); fsm_cursor_define(&cur, nzs("expression")); fsm_cursor_done(&cur, '\0'); Action *action; int E_EXPRESSION = fsm_get_symbol(&fix.fsm, nzs("expression")); Session session; session_init(&session, &fix.fsm); MATCH(session, L_TERMINAL_STRING); action = TEST(session, L_CONCATENATE_SYMBOL); t_assert(action->type == ACTION_REDUCE); t_assert(action->reduction == E_EXPRESSION); action = TEST(session, L_DEFINITION_SEPARATOR_SYMBOL); t_assert(action->type == ACTION_REDUCE); t_assert(action->reduction == E_EXPRESSION); action = TEST(session, L_TERMINATOR_SYMBOL); t_assert(action->type == ACTION_REDUCE); t_assert(action->reduction == E_EXPRESSION); MATCH(session, L_TERMINATOR_SYMBOL); t_assert(session.current->type == ACTION_ACCEPT); session_dispose(&session); fsm_cursor_dispose(&cur); }
static void client(int sock) { int err = 0; time_t started = time(0); const char* line = "foobar!"; char buffer[8192]; int len; session_init(sock, 0); killtimer_set(); do { err = process_error(gnutls_handshake(session)); if (err != 0) { int t = gnutls_dtls_get_timeout(session); await(sock, t ? t : 100); } } while (err != 0); process_error_or_timeout(err, time(0) - started); killtimer_set(); die_on_error(gnutls_record_send(session, line, strlen(line))); do { await(sock, -1); len = process_error(gnutls_record_recv(session, buffer, sizeof(buffer))); } while (len < 0); if (len > 0 && strncmp(line, buffer, len) == 0) { exit(0); } else { exit(1); } }
bool init_full(void) { int error; error = pool6_init(NULL, 0); if (error) goto fail; error = pool4_init(NULL, 0); if (error) goto fail; error = bib_init(); if (error) goto fail; error = session_init(session_expired_callback); if (error) goto fail; error = filtering_init(); if (error) goto fail; return true; fail: return false; }
int sessiondb_init(fate_cb tcpest_fn, fate_cb tcptrans_fn) { int error; error = session_init(); if (error) return error; error = pktqueue_init(); if (error) { session_destroy(); return error; } sessiontable_init(&session_table_udp, config_get_ttl_udp, just_die, NULL, NULL); sessiontable_init(&session_table_tcp, config_get_ttl_tcpest, tcpest_fn, config_get_ttl_tcptrans, tcptrans_fn); sessiontable_init(&session_table_icmp, config_get_ttl_icmp, just_die, NULL, NULL); return 0; }
static void server(int sock) { int err; time_t started = time(0); char buffer[8192]; int len; session_init(sock, 1); await(sock, -1); killtimer_set(); do { err = process_error(gnutls_handshake(session)); if (err != 0) { int t = gnutls_dtls_get_timeout(session); await(sock, t ? t : 100); } } while (err != 0); process_error_or_timeout(err, time(0) - started); killtimer_set(); do { await(sock, -1); len = process_error(gnutls_record_recv(session, buffer, sizeof(buffer))); } while (len < 0); die_on_error(gnutls_record_send(session, buffer, len)); exit(0); }
PRIVATE void signal_handler(int sig) { switch (sig) { case SIGINT: case SIGTERM: { dbg_printf(P_INFO2, "SIGTERM/SIGINT caught"); closing = true; break; } case SIGHUP: { if(isRunning || !mySession) { seenHUP = true; } else { auto_handle * s = NULL; dbg_printf(P_MSG, "Caught SIGHUP. Reloading config file."); s = session_init(); if((parse_config_file(s, AutoConfigFile) != 0) || !setupSession(s)) { dbg_printf(P_ERROR, "Error parsing config file. Keeping the old settings."); session_free(s); } seenHUP = false; } break; } } }
Session *pop3_session_new(PrefsAccount *account) { Pop3Session *session; cm_return_val_if_fail(account != NULL, NULL); account->receive_in_progress = TRUE; session = g_new0(Pop3Session, 1); session_init(SESSION(session), account, FALSE); SESSION(session)->type = SESSION_POP3; SESSION(session)->recv_msg = pop3_session_recv_msg; SESSION(session)->recv_data_finished = pop3_session_recv_data_finished; SESSION(session)->send_data_finished = NULL; SESSION(session)->ssl_cert_auto_accept = account->ssl_certs_auto_accept; SESSION(session)->destroy = pop3_session_destroy; session->state = POP3_READY; session->ac_prefs = account; session->pop_before_smtp = FALSE; pop3_get_uidl_table(account, session); session->current_time = time(NULL); session->error_val = PS_SUCCESS; session->error_msg = NULL; return SESSION(session); }
bool init(void) { int error; int i; for (i = 0; i < ARRAY_SIZE(IPV4_ADDRS); i++) { error = str_to_addr4(IPV4_ADDRS[i], &addr4[i].address); if (error) return false; addr4[i].l4_id = IPV4_PORTS[i]; } for (i = 0; i < ARRAY_SIZE(IPV4_ADDRS); i++) { error = str_to_addr6(IPV6_ADDRS[i], &addr6[i].address); if (error) return false; addr6[i].l4_id = IPV6_PORTS[i]; } error = bib_init(); if (error) return false; error = session_init(session_always_dies); if (error) { bib_destroy(); return false; } return true; }
void session_start(struct session *s){ debug("session_start"); http_parser_init(s->client_parser, HTTP_REQUEST); http_parser_init(s->server_parser, HTTP_RESPONSE); s->client_parser->data = s; s->server_parser->data = s; session_init(s); }
static void _init(char *log_level) { setlocale(LC_ALL, ""); // ignore SIGPIPE signal(SIGPIPE, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGWINCH, ui_sigwinch_handler); if (pthread_mutex_init(&lock, NULL) != 0) { log_error("Mutex init failed"); exit(1); } pthread_mutex_lock(&lock); files_create_directories(); log_level_t prof_log_level = log_level_from_string(log_level); prefs_load(); log_init(prof_log_level); log_stderr_init(PROF_LEVEL_ERROR); if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION log_info("Starting Profanity (%sdev.%s.%s)...", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); #else log_info("Starting Profanity (%sdev)...", PACKAGE_VERSION); #endif } else { log_info("Starting Profanity (%s)...", PACKAGE_VERSION); } chat_log_init(); groupchat_log_init(); accounts_load(); char *theme = prefs_get_string(PREF_THEME); theme_init(theme); prefs_free_string(theme); ui_init(); session_init(); cmd_init(); log_info("Initialising contact list"); muc_init(); tlscerts_init(); scripts_init(); #ifdef HAVE_LIBOTR otr_init(); #endif #ifdef HAVE_LIBGPGME p_gpg_init(); #endif #ifdef HAVE_OMEMO omemo_init(); #endif atexit(_shutdown); plugins_init(); #ifdef HAVE_GTK tray_init(); #endif inp_nonblocking(TRUE); ui_resize(); }
PyMODINIT_FUNC init_spotify(void) { PyObject *m; if (PyType_Ready(&SessionType) < 0) return; if (PyType_Ready(&ArtistType) < 0) return; if (PyType_Ready(&ArtistBrowserType) < 0) return; if (PyType_Ready(&LinkType) < 0) return; if (PyType_Ready(&PlaylistType) < 0) return; if (PyType_Ready(&PlaylistContainerType) < 0) return; if (PyType_Ready(&ResultsType) < 0) return; if (PyType_Ready(&ToplistBrowserType) < 0) return; if (PyType_Ready(&TrackType) < 0) return; if (PyType_Ready(&ImageType) < 0) return; if (PyType_Ready(&UserType) < 0) return; m = Py_InitModule("_spotify", module_methods); if (m == NULL) return; PyObject *spotify = PyImport_ImportModule("spotify"); PyObject *d = PyModule_GetDict(spotify); PyObject *s = PyUnicode_FromString("SpotifyError"); SpotifyError = PyDict_GetItem(d, s); Py_INCREF(SpotifyError); SpotifyApiVersion = Py_BuildValue("i", SPOTIFY_API_VERSION); Py_INCREF(SpotifyApiVersion); PyModule_AddObject(m, "api_version", SpotifyApiVersion); album_init(m); albumbrowser_init(m); artist_init(m); artistbrowser_init(m); link_init(m); playlist_init(m); playlistcontainer_init(m); session_init(m); search_init(m); toplistbrowser_init(m); track_init(m); image_init(m); user_init(m); }
void core_init(void) { dialog_type_queue = NULL; dialog_text_queue = NULL; client_start_time = time(NULL); modules_init(); pidwait_init(); net_disconnect_init(); signals_init(); signal_add_first("gui dialog", (SIGNAL_FUNC) sig_gui_dialog); signal_add_first("irssi init finished", (SIGNAL_FUNC) sig_init_finished); settings_init(); commands_init(); nickmatch_cache_init(); session_init(); #ifdef HAVE_CAPSICUM capsicum_init(); #endif chat_protocols_init(); chatnets_init(); expandos_init(); ignore_init(); servers_init(); write_buffer_init(); log_init(); log_away_init(); rawlog_init(); recode_init(); channels_init(); queries_init(); nicklist_init(); chat_commands_init(); wcwidth_wrapper_init(); settings_add_str("misc", "ignore_signals", ""); settings_add_bool("misc", "override_coredump_limit", FALSE); #ifdef HAVE_SYS_RESOURCE_H getrlimit(RLIMIT_CORE, &orig_core_rlimit); #endif read_settings(); signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished); settings_check(); module_register("core", "core"); }
int main(int argc, char const *argv[]) { check_permission(); setup_signal_chld(); parseconf_load_file("ftpserver.conf"); print_conf(); init_hash(); //创建一个监听fd int listenfd = tcp_server(tunable_listen_address, tunable_listen_port); pid_t pid; session_t sess; session_init(&sess); p_sess = &sess; //配置全局变量 while(1) { struct sockaddr_in addr; int peerfd = accept_timeout(listenfd, &addr, tunable_accept_timeout); if(peerfd == -1 && errno == ETIMEDOUT) continue; else if(peerfd == -1) ERR_EXIT("accept_timeout"); //获取ip地址,并在hash中添加一条记录 uint32_t ip = addr.sin_addr.s_addr; sess.ip = ip; add_clients_to_hash(&sess, ip); if((pid = fork()) == -1) ERR_EXIT("fork"); else if(pid == 0) { close(listenfd); sess.peerfd = peerfd; limit_num_clients(&sess); session_begin(&sess); exit(EXIT_SUCCESS); } else { //pid_to_ip add_pid_ip_to_hash(pid, ip); close(peerfd); } } return 0; }
/* * Allocate memory for a new session and add it to the sessions linked list. */ session * session_new(void) { session *s = (session *)xmalloc(sizeof(session)); session_init(s); sessions = list_append(sessions, s); return s; }
int main(int argc, char *argv[]) { if (getuid()) { fprintf(stderr, "the ftpserver must started by root\n"); exit(EXIT_FAILURE); } if (signal(SIGCHLD, handle_sigchld) == SIG_ERR) ERR_EXIT("signal"); parse_load_file("ftpserver.conf"); printf("parse_load_file success\n"); // printconfig(); ip_to_clients = hash_alloc(256, hash_func); pid_to_ip = hash_alloc(256, hash_func); int listenfd; listenfd = tcp_server(listen_address, listen_port); printf("tcp_server success, listenfd = %d\n", listenfd); int connfd; pid_t pid; session_t sess; while (1) { struct sockaddr_in addr; connfd = accept_time_out(listenfd, &addr, accept_timeout); if (connfd == -1) { // printf("don't has connection in %d seconds\n", accept_timeout); continue; } uint32_t ip = addr.sin_addr.s_addr; printf("connect success\n"); session_init(&sess); num_of_clients++; sess.curr_clients = num_of_clients; sess.curr_ip_clients = add_ip_to_hash(ip_to_clients, ip); sess.ip = ip; p_sess = &sess; pid = fork(); if (pid == -1) { ERR_EXIT("fork error"); } else if (pid == 0) { //子进程 close(listenfd); sess.peerfd = connfd; session_begin(&sess); //建立一个会话 exit(EXIT_SUCCESS); } else { //父进程 close(connfd); hash_add_entry(pid_to_ip, &pid, sizeof(pid), &ip, sizeof(ip)); } } return 0; }
int main(int argc, char *argv[]) { enum { SC = 3 }; int opt, n; int sigs[] = { SIGINT, SIGHUP, SIGTERM }; void (*sighandlers[])() = { sigint_handler, sighup_handler, sigterm_handler }; struct sigaction s[SC]; for (n = 0; n < SC; ++n) { s[n].sa_handler = SIG_IGN; sigfillset(&s[n].sa_mask); s[n].sa_flags = 0; sigaction(sigs[n], &s[n], NULL); } for (opt = 1; opt < argc; ++opt) { if (strcmp(argv[opt], "-h") == 0 || strcmp(argv[opt], "--help") == 0) { show_usage(); return 0; } } mod_src_create(); gtk_init(&argc, &argv); settings_init(); driver_init(); lfo_tables_init(); mixer_init(); patch_control_init(); dish_file_state_init(); session_init(argc, argv); gui_init(); for (n = 0; n < SC; ++n) { s[n].sa_handler = sighandlers[n]; sigfillset(&s[n].sa_mask); s[n].sa_flags = 0; sigaction(sigs[n], &s[n], NULL); } gtk_main(); cleanup(); return 0; }
static bool init(void) { if (config_init(false)) return false; if (session_init()) { config_destroy(); return false; } sessiontable_init(&table, config_get_ttl_udp, just_die, NULL, NULL); return true; }
void core_init(int argc, char *argv[]) { dialog_type_queue = NULL; dialog_text_queue = NULL; modules_init(); #ifndef WIN32 pidwait_init(); #endif net_disconnect_init(); net_sendbuffer_init(); signals_init(); signal_add_first("gui dialog", (SIGNAL_FUNC) sig_gui_dialog); signal_add_first("irssi init finished", (SIGNAL_FUNC) sig_init_finished); settings_init(); commands_init(); nickmatch_cache_init(); session_init(); chat_protocols_init(); chatnets_init(); expandos_init(); ignore_init(); servers_init(); write_buffer_init(); log_init(); log_away_init(); rawlog_init(); recode_init(); channels_init(); queries_init(); nicklist_init(); chat_commands_init(); settings_add_str("misc", "ignore_signals", ""); settings_add_bool("misc", "override_coredump_limit", TRUE); #ifdef HAVE_SYS_RESOURCE_H getrlimit(RLIMIT_CORE, &orig_core_rlimit); #endif read_settings(); signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished); settings_check(); module_register("core", "core"); }
bool init_full(void) { bool success = true; success &= pool6_init(); success &= pool4_init(true); success &= bib_init(); success &= session_init(); success &= filtering_init(); return success; }
static SieveSession *sieve_session_new(PrefsAccount *account) { SieveSession *session; session = g_new0(SieveSession, 1); session_init(SESSION(session), account, FALSE); session->account = account; SESSION(session)->recv_msg = sieve_session_recv_msg; SESSION(session)->destroy = sieve_session_destroy; SESSION(session)->connect_finished = sieve_connect_finished; session_set_recv_message_notify(SESSION(session), sieve_recv_message, NULL); sieve_session_reset(session); return session; }
Session *smtp_session_new(void) { SMTPSession *session; session = g_new0(SMTPSession, 1); session_init(SESSION(session)); SESSION(session)->type = SESSION_SMTP; SESSION(session)->recv_msg = smtp_session_recv_msg; SESSION(session)->recv_data_finished = NULL; SESSION(session)->send_data_finished = smtp_session_send_data_finished; SESSION(session)->destroy = smtp_session_destroy; session->state = SMTP_READY; #if USE_OPENSSL session->tls_init_done = FALSE; #endif session->hostname = NULL; session->user = NULL; session->pass = NULL; session->from = NULL; session->to_list = NULL; session->cur_to = NULL; session->send_data = NULL; session->send_data_len = 0; session->max_message_size = -1; session->avail_auth_type = 0; session->forced_auth_type = 0; session->auth_type = 0; session->esmtp_flags = 0; session->error_val = SM_OK; session->error_msg = NULL; return SESSION(session); }
static void init (void) { Any_Type arg; session_init (); sess_private_data_offset = object_expand (OBJ_SESS, sizeof (Sess_Private_Data)); rg_sess.rate = ¶m.rate; rg_sess.tick = sess_create; rg_sess.arg.l = 0; arg.l = 0; event_register_handler (EV_SESS_DESTROYED, sess_destroyed, arg); event_register_handler (EV_CALL_DESTROYED, call_destroyed, arg); }
int main(int argc, char *argv[]) { session *s; session_init(&argc, &argv, &s, "Protocol_R2.spr"); session_dump(s); long long barrier_start = sc_time(); barrier(s->r(s, "_Others"), "R0"); long long barrier_end = sc_time(); sc_print_version(); printf("%s: Barrier time: %f sec\n", s->name, sc_time_diff(barrier_start, barrier_end)); session_end(s); return EXIT_SUCCESS; }
int p_session_init( /* - */ value v_session, type t_session ) { session_t * session; pword p_session; session_init( &session); if (session == NULL) { Bip_Error(dbi_errno); } session->refs = 1; p_session = ec_handle(&session_handle_tid, session); Return_Unify_Pw(v_session, t_session, p_session.val, p_session.tag ); }
int main(int argc, char const *argv[]) { if(getuid()) { fprintf(stderr, "FtpServer must be started by root\n"); exit(EXIT_FAILURE); } //创建一个监听fd int listenfd = tcp_server(NULL, 9981); pid_t pid; session_t sess; session_init(&sess); while(1) { int peerfd = accept_timeout(listenfd, NULL, 10); if(peerfd == -1 && errno == ETIMEDOUT) continue; else if(peerfd == -1) ERR_EXIT("accept_timeout"); if((pid = fork()) == -1) ERR_EXIT("fork"); else if(pid == 0) { close(listenfd); // sess.peerfd = peerfd; session_begin(&sess); } else { close(peerfd); } } return 0; }
static void init (void) { const char *slash; Any_Type arg; #ifdef UW_CALL_STATS if (param.call_stats >= 0) { fprintf(stderr, "Can not use --call-stats with --wsesspage\n"); exit(1); } #endif /* UW_CALL_STATS */ slash = strrchr (param.uri, '/'); if (slash) prefix_len = (slash + 1) - param.uri; else panic ("%s: URI specified with --uri must be absolute", prog_name); prefix = strdup (param.uri); prefix[prefix_len] = '\0'; session_init (); call_private_data_offset = object_expand (OBJ_CALL, sizeof (Call_Private_Data)); sess_private_data_offset = object_expand (OBJ_SESS, sizeof (Sess_Private_Data)); rg_sess.rate = ¶m.rate; rg_sess.tick = sess_create; rg_sess.arg.l = 0; arg.l = 0; event_register_handler (EV_CALL_RECV_HDR, call_recv_hdr, arg); event_register_handler (EV_CALL_RECV_DATA, call_recv_data, arg); event_register_handler (EV_SESS_DESTROYED, sess_destroyed, arg); event_register_handler (EV_CALL_DESTROYED, call_destroyed, arg); }
static Session *news_session_new(Folder *folder, const gchar *server, gushort port, const gchar *userid, const gchar *passwd) #endif { NewsSession *session; int r = 0; cm_return_val_if_fail(server != NULL, NULL); log_message(LOG_PROTOCOL, _("Account '%s': Connecting to NNTP server: %s:%d...\n"), folder->account->account_name, server, port); session = g_new0(NewsSession, 1); session_init(SESSION(session), folder->account, FALSE); SESSION(session)->type = SESSION_NEWS; SESSION(session)->server = g_strdup(server); SESSION(session)->port = port; SESSION(session)->sock = NULL; SESSION(session)->destroy = news_session_destroy; nntp_init(folder); #ifdef USE_GNUTLS if (ssl_type != SSL_NONE) r = nntp_threaded_connect_ssl(folder, server, port); else #endif r = nntp_threaded_connect(folder, server, port); if (r != NEWSNNTP_NO_ERROR) { log_error(LOG_PROTOCOL, _("Error logging in to %s:%d...\n"), server, port); session_destroy(SESSION(session)); return NULL; } session->folder = folder; return SESSION(session); }