int mainloop() { unsigned cmd; nodep myLine; extern int phys_pcode; extern int row, scol, ecol; int curserr; for (;;) { here(1); checkfar(1); printt5("mainloop, cursor %x, ocursor %x, srch_row %d, srch_real %d, look.=%x\n", cursor, ocursor, srch_row, srch_real, lookaheadchar); hist_mark(); printt0("back from hist_mark()\n"); if (lookaheadchar == AL_NOP || lookaheadchar == ' ') lookaheadchar = 0; /* * Redisplay unconditionally, not just when there's no * typeahead, because often there is typeahead of the * terminating character, like comma or right paren. * Ideally the redisplay should be done only if dirty * from the keyboard driver when we are ready for real * input. */ newrange(FALSE); display(FALSE); /* * ocursor is set by arrow keys to indicate that that's * where the arrow keys left the cursor. Only if it * was set (possibly in them middle of a token) and * hasn't moved since do we want to leave it alone. */ here(2); checkfar(2); if (cursor != ocursor) { /* don't do if moves are in type-ahead */ find_phys_cursor( curr_window, cursor,anywflag); anywflag = FALSE; phys_pcode = kcget( -1, cursor ); flusht(); } here(3); ocursor = NIL; CheckAt = NIL; CodeChanged = FALSE; if( autsave && ascount++ > autsave ) { ascount = 0; if( work_fname( curr_workspace ) ) { save(0); statusLine(); } else warning( ER(220,"autosave`Automatic Save is engaged but there is no file name.") ); } here(4); cmd = topcmd( srch_row, srch_real, srch_real+srch_width, cursnode ); printt2("mainloop: topcmd returns %s (%d)\n", tokname(cmd), cmd); mark_line( cursor, SMALL_CHANGE ); do_command(cmd); here(5); checkfar(3); /* never leave the cursor on a list or below hide */ cursor = hidebound(realcp( cursor )); mark_line( cursor, SMALL_CHANGE ); curserr = node_flag(cursor) & NF_ERROR; if( curserr && !WhereDeclsChanged ) { NodeNum cltype = ntype( t_up_to_line(cursor)); if( ntype_info(cltype) & F_DECLARE||highType( cltype ) ) { WhereDeclsChanged = my_block(cursor); printt1("mainloop: WhereDeclsChanged=%x\n", WhereDeclsChanged); } } /* * Whenever a graft, etc takes place we check to see * if changes are being made to a declaration. If they * are then we set WhereDeclsChanged. If it has been * set when we get back here we recompile its declaration * block. */ if (CheckSpeed && WhereDeclsChanged && (CheckSpeed >= 4 || CodeChanged || WhereDeclsChanged != OldDeclsChanged) ) { if( CheckSpeed < 4 && WhereDeclsChanged != OldDeclsChanged ) { nodep decswap; decswap = OldDeclsChanged; OldDeclsChanged = WhereDeclsChanged; WhereDeclsChanged = decswap; printt1("mainloop: WhereDeclsChanged=%x (2)\n", WhereDeclsChanged); } if( WhereDeclsChanged ) { clr_node_flag(WhereDeclsChanged, NF_TCHECKED); here(4); checkfar(4); c_comp_decls(my_scope(WhereDeclsChanged), WhereDeclsChanged, CheckSpeed < 6 ? TC_NOSTUBS : (TC_DESCEND | TC_FULL) ); here(5); checkfar(5); WhereDeclsChanged = NIL; } } /* * Typecheck the current line. This was added late in the * game, and isn't really the best way of doing things. * Every time we return from a command, we typecheck * the current line (or if CheckAt has already been set * by a skip down routine, we typecheck there). We * don't typecheck declarations. */ printt2("CheckAt=%x, cursor=%x\n", CheckAt, cursor); if (!CheckAt && (curserr||is_undid(cursor))) CheckAt = cursor; if( CheckAt && CheckSpeed ) { myLine = t_up_to_line(CheckAt); if (!( highType(ntype(myLine)) || (ntype_info(ntype(myLine)) & F_DECLARE)) ) { printt2("mainloop: c_typecheck(%x, 0, %x)\n", (int)myLine, TC_NOSTUBS|TC_ONERROR); c_typecheck(myLine, 0, TC_NOSTUBS|TC_ONERROR ); here(6); checkfar(6); } } /* if code was changed, clear chance at resuming */ if( CodeChanged ) clear_resume(); #ifdef CHECKSUM cscheck(); #endif } }
int tipc_bind(int sd, uint32_t type, uint32_t lower, uint32_t upper, tipc_domain_t scope) { struct sockaddr_tipc addr = { .family = AF_TIPC, .addrtype = TIPC_ADDR_NAMESEQ, .addr.nameseq.type = type, .addr.nameseq.lower = lower, .addr.nameseq.upper = upper }; if (tipc_own_node() == scope) addr.scope = TIPC_NODE_SCOPE; if (tipc_own_cluster() == scope) addr.scope = TIPC_CLUSTER_SCOPE; if (tipc_own_zone() == scope) addr.scope = TIPC_ZONE_SCOPE; /* TODO: introduce support for global scope in module */ if (!scope) addr.scope = TIPC_ZONE_SCOPE; if (!my_scope(scope)) return -1; return bind(sd, (struct sockaddr *)&addr, sizeof(addr)); } int tipc_unbind(int sd, uint32_t type, uint32_t lower, uint32_t upper) { struct sockaddr_tipc addr = { .family = AF_TIPC, .addrtype = TIPC_ADDR_NAMESEQ, .addr.nameseq.type = type, .addr.nameseq.lower = lower, .addr.nameseq.upper = upper, .scope = -1 }; return bind(sd, (struct sockaddr *)&addr, sizeof(addr)); } int tipc_connect(int sd, const struct tipc_addr *dst) { struct sockaddr_tipc addr; if (!dst) return -1; addr.family = AF_TIPC; addr.addrtype = TIPC_ADDR_NAME; addr.addr.name.name.type = dst->type; addr.addr.name.name.instance = dst->instance; addr.addr.name.domain = dst->domain; return connect(sd, (struct sockaddr*)&addr, sizeof(addr)); } int tipc_listen(int sd, int backlog) { return listen(sd, backlog); } int tipc_accept(int sd, struct tipc_addr *src) { struct sockaddr_tipc addr; socklen_t addrlen = sizeof(addr); int rc; rc = accept(sd, (struct sockaddr *) &addr, &addrlen); if (src) { src->type = 0; src->instance = addr.addr.id.ref; src->domain = addr.addr.id.node; } return rc; } int tipc_send(int sd, const char *msg, size_t msg_len) { return send(sd, msg, msg_len, 0); } int tipc_sendmsg(int sd, const struct msghdr *msg) { return sendmsg(sd, msg, 0); } int tipc_sendto(int sd, const char *msg, size_t msg_len, const struct tipc_addr *dst) { struct sockaddr_tipc addr; if(!dst) return -1; addr.family = AF_TIPC; if (dst->type) { addr.addrtype = TIPC_ADDR_NAME; addr.addr.name.name.type = dst->type; addr.addr.name.name.instance = dst->instance; addr.addr.name.domain = dst->domain; } else { addr.addrtype = TIPC_ADDR_ID; addr.addr.id.ref = dst->instance; addr.addr.id.node = dst->domain; } return sendto(sd, msg, msg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); } int tipc_mcast(int sd, const char *msg, size_t msg_len, const struct tipc_addr *dst) { struct sockaddr_tipc addr = { .family = AF_TIPC, .addrtype = TIPC_ADDR_MCAST, .addr.name.domain = TIPC_CLUSTER_SCOPE }; if(!dst) return -1; addr.addr.nameseq.type = dst->type; addr.addr.nameseq.lower = dst->instance; addr.addr.nameseq.upper = dst->instance; if (dst->domain != tipc_own_cluster()) return -ENOTSUP; return sendto(sd, msg, msg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); } int tipc_recv(int sd, char* buf, size_t buf_len, bool waitall) { int flags = waitall ? MSG_WAITALL : 0; return recv(sd, buf, buf_len, flags); } int tipc_recvfrom(int sd, char *buf, size_t len, struct tipc_addr *src, struct tipc_addr *dst, int *err) { int rc, _err = 0; struct sockaddr_tipc addr; struct iovec iov = {buf, len}; struct msghdr msg = {0, }; char anc_space[CMSG_SPACE(8) + CMSG_SPACE(1024) + CMSG_SPACE(16)]; struct cmsghdr *anc; msg.msg_name = &addr; msg.msg_namelen = sizeof(addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = (struct cmsghdr *)anc_space; msg.msg_controllen = sizeof(anc_space); rc = recvmsg(sd ,&msg ,0); if (rc < 0) return rc; if (src) { src->type = 0; src->instance = addr.addr.id.ref; src->domain = addr.addr.id.node; } anc = CMSG_FIRSTHDR(&msg); if (anc && (anc->cmsg_type == TIPC_ERRINFO)) { _err = *(int*)(CMSG_DATA(anc)); rc = *(int*)(CMSG_DATA(anc) + 4); if (rc > len) rc = len; anc = CMSG_NXTHDR(&msg, anc); memcpy(buf, (char*)CMSG_DATA(anc), rc); anc = CMSG_NXTHDR(&msg, anc); } if (_err) tipc_sockid(sd, src); if (err) *err = _err; else if (_err) rc = 0; if (!dst) return rc; if (anc && (anc->cmsg_type == TIPC_DESTNAME)) { dst->type = *((uint32_t*)(CMSG_DATA(anc))); dst->instance = *((uint32_t*)(CMSG_DATA(anc) + 4)); dst->domain = 0; } else { tipc_sockid(sd, dst); } return rc; } int tipc_topsrv_conn(tipc_domain_t node) { int sd; struct tipc_addr srv = {TIPC_TOP_SRV, TIPC_TOP_SRV, node}; sd = tipc_socket(SOCK_SEQPACKET); if (sd <= 0) return sd; if (tipc_connect(sd, &srv) < 0) tipc_close(sd); return sd; }