int aln_pair_align(FILE *fp1, FILE *fp2, AlnParam *ap, int type, int misc_flag) { seq_t seq1, seq2; int len1, len2, n; char name1[MAX_NAME_LEN], name2[MAX_NAME_LEN]; path_t *pt, *pp; AlnAln *aa; INIT_SEQ(seq1); INIT_SEQ(seq2); for (n = 0; ; ++n) { len1 = read_fasta(fp1, &seq1, name1, 0); len2 = read_fasta(fp2, &seq2, name2, 0); if (len1 < 0 || len2 < 0) break; aa = aln_align((char*)seq1.s, (char*)seq2.s, ap, type); pp = aa->path; pt = aa->path + aa->path_len - 1; printf(">%s\t%d\t%d\t%d\t%s\t%d\t%d\t%d\t%d\n", name1, len1, pt->i, pp->i, name2, len2, pt->j, pp->j, aa->score); if (aa->out1) printf("%s\n", aa->out1); if (aa->outm) printf("%s\n", aa->outm); if (aa->out2) printf("%s\n", aa->out2); if (type != ALN_BOUND_ALIGN) printf("//\n"); fflush(stdout); if (misc_flag) aln_output_segment((char*)seq1.s, (char*)seq2.s, aa->path, aa->path_len, name1, name2); aln_free_AlnAln(aa); } MYFREE(seq1.s); MYFREE(seq2.s); return n; }
/* * Called from tcp_fsm.c / tcp_listen_state() (via _tcp_syn_hook) to * append a new connection to the listen-queue of socket 'sock'. * * TCB on input ('orig') has received a SYN. Replace TCB on output * with a cloned TCB that we append to the listen-queue and eventually * is used by accept() to create a new socket. * * TCB on input ('orig') must still be listening for further connections * on the same port as specified in call to _TCP_listen(). */ int _sock_append (tcp_Socket **tcp) { tcp_Socket *clone; tcp_Socket *orig = *tcp; Socket *sock = NULL; /* associated socket for '*tcp' */ int i; /* Lookup BSD-socket for Wattcp TCB */ if (!_tcp_find_hook || (sock = (*_tcp_find_hook)(orig)) == NULL) { SOCK_DEBUGF ((NULL, "\n sock_append: not found!?")); return (0); /* i.e. could be a native Wattcp socket */ } SOCK_DEBUGF ((sock, "\n sock_append:%d", sock->fd)); if (!(sock->so_options & SO_ACCEPTCONN)) { SOCK_DEBUGF ((sock, ", not SO_ACCEPTCONN")); return (-1); /* How could this happen? */ } /* Find the first vacant slot for this clone */ for (i = 0; i < sock->backlog; i++) if (!sock->listen_queue[i]) break; if (i >= sock->backlog || i >= SOMAXCONN) { /* !!to-do: drop the oldest (or a random) slot in the listen-queue. */ SOCK_DEBUGF ((sock, ", queue full (idx %d)", i)); return (-1); } SOCK_DEBUGF ((sock, ", idx %d", i)); clone = SOCK_CALLOC (sizeof(*clone)); if (!clone) { SOCK_DEBUGF ((sock, ", ENOMEM")); return (-1); } /* Link in the semi-connected socket (SYN received, ACK will be sent) */ sock->listen_queue[i] = clone; sock->syn_timestamp[i] = set_timeout (0); /* Copy the TCB (except Tx-buffer) to clone */ memcpy (clone, orig, sizeof(*clone) - sizeof(clone->data)); clone->safetytcp = SAFETYTCP; /* Increase the TCP window (to 16kB) */ sock_setbuf ((sock_type*)clone, calloc(DEFAULT_RCV_WIN,1), DEFAULT_RCV_WIN); /* Undo what tcp_handler() and tcp_listen_state() did to * this listening socket. */ orig->hisport = 0; orig->hisaddr = 0; orig->myaddr = 0; orig->seqnum = INIT_SEQ(); /* set new ISS */ orig->unhappy = FALSE; CLR_PEER_MAC_ADDR (orig); #if defined(USE_DEBUG) /* !!needs some work */ orig->last_acknum[0] = orig->last_acknum[1] = 0; orig->last_seqnum[0] = orig->last_seqnum[1] = 0; #endif clone->next = _tcp_allsocs; _tcp_allsocs = clone; /* prepend clone to TCB-list */ *tcp = clone; /* clone is now the new TCB */ return (0); }