void accept_connection(long channel) { struct message msg; memset(&msg, 0, sizeof(struct message)); msg.channel = channel; msg.type = CONNECTION_ACCEPTED; check_interrupted(); if(-1 == msgsnd(read_queue_id, &msg, MSG_SIZE, 0)) serv_msg_error("Unable to send to %ld", channel); }
/** \brief Parse a sequence of commands. This method also perform error management. */ bool parser_imp::parse_commands() { bool done = false; while (!done) { protected_call([&]() { check_interrupted(); switch (curr()) { case scanner::token::CommandId: if (!parse_command()) done = true; break; case scanner::token::ScriptBlock: parse_script(); break; case scanner::token::Period: show_prompt(); next(); break; case scanner::token::Eof: done = true; break; default: throw parser_error("Command expected", pos()); } }, [&]() { sync_command(); }); } return !m_found_errors; }
expr apply(expr const & e, unsigned offset) { bool shared = false; if (m_use_cache && is_shared(e)) { if (auto r = m_cache->find(e, offset)) return *r; shared = true; } check_interrupted(); check_memory("replace"); if (optional<expr> r = m_f(e, offset)) { return save_result(e, offset, *r, shared); } else { switch (e.kind()) { case expr_kind::Constant: case expr_kind::Sort: case expr_kind::Var: return save_result(e, offset, e, shared); case expr_kind::Meta: case expr_kind::Local: { expr new_t = apply(mlocal_type(e), offset); return save_result(e, offset, update_mlocal(e, new_t), shared); } case expr_kind::App: { expr new_f = apply(app_fn(e), offset); expr new_a = apply(app_arg(e), offset); return save_result(e, offset, update_app(e, new_f, new_a), shared); } case expr_kind::Pi: case expr_kind::Lambda: { expr new_d = apply(binding_domain(e), offset); expr new_b = apply(binding_body(e), offset+1); return save_result(e, offset, update_binding(e, new_d, new_b), shared); } case expr_kind::Macro: { buffer<expr> new_args; unsigned nargs = macro_num_args(e); for (unsigned i = 0; i < nargs; i++) new_args.push_back(apply(macro_arg(e, i), offset)); return save_result(e, offset, update_macro(e, new_args.size(), new_args.data()), shared); }} lean_unreachable(); } }
_Noreturn void* thread_start(void *ptr) { struct message msg = ((struct thread_param*) ptr)->msg; bool allowed = ((struct thread_param*) ptr)->allowed; long channel = msg.channel_request.pid; free(ptr); check_interrupted(); if(msg.channel_request.id > 0) { if(!allowed) refuse_connection(channel); else { accept_connection(channel); process_results(channel); } } else process_report(channel); exit_thread(); }