tcpswindow

mac2022-06-30  106

tcpswindow

/*------------------------------------------------------------------------ * tcpswindow - handle send window updates from remote *------------------------------------------------------------------------ */ int tcpswindow(struct tcb *ptcb, struct ep *pep) { struct ip *pip = (struct ip *)pep->ep_data; struct tcp *ptcp = (struct tcp *)pip->ip_data; tcpseq wlast, owlast; if (SEQCMP(ptcp->tcp_seq, ptcb->tcb_lwseq) < 0) return OK; if (SEQCMP(ptcp->tcp_seq, ptcb->tcb_lwseq) == 0 && SEQCMP(ptcp->tcp_ack, ptcb->tcb_lwack) < 0) return OK; /* else, we have a send window update */ /* compute the last sequences of the new and old windows */ owlast = ptcb->tcb_lwack + ptcb->tcb_swindow; wlast = ptcp->tcp_ack + ptcp->tcp_window; ptcb->tcb_swindow = ptcp->tcp_window; ptcb->tcb_lwseq = ptcp->tcp_seq; ptcb->tcb_lwack = ptcp->tcp_ack; if (SEQCMP(wlast, owlast) <= 0) return OK; /* else, window increased */ if (ptcb->tcb_ostate == TCPO_PERSIST) { tmclear(tcps_oport, MKEVENT(PERSIST, ptcb-&tcbtab[0])); ptcb->tcb_ostate = TCPO_XMIT; } tcpkick(ptcb); /* do something with it */ return OK; }

tcpkick

/*------------------------------------------------------------------------ * tcpkick - make sure we send a packet soon *------------------------------------------------------------------------ */ int tcpkick(struct tcb *ptcb) { int tcbnum = ptcb - &tcbtab[0]; /* for MKEVENT() */ void *tv; tv = MKEVENT(SEND, tcbnum); if (ptcb->tcb_flags & TCBF_DELACK && !tmleft(tcps_oport, tv)) tmset(tcps_oport, TCPQLEN, tv, TCP_ACKDELAY); else if (pcount(tcps_oport) < TCPQLEN) psend(tcps_oport, (int)tv); /* send now */ return OK; }

MKEVENT

#define MKEVENT(timer, tcb) (void *)(((tcb)<<3) | ((timer) & TMASK))

tmclear

/*------------------------------------------------------------------------ * tmclear - clear the indicated timer *------------------------------------------------------------------------ */ int tmclear(int port, void *msg) { struct tqent *prev, *ptq; int timespent; wait(tqmutex); prev = 0; for (ptq = tqhead; ptq != NULL; ptq = ptq->tq_next) { if (ptq->tq_port == port && ptq->tq_msg == msg) { timespent = ctr100 - ptq->tq_time; if (prev) prev->tq_next = ptq->tq_next; else tqhead = ptq->tq_next; if (ptq->tq_next) ptq->tq_next->tq_timeleft += ptq->tq_timeleft; signal(tqmutex); freemem(ptq, sizeof(struct tqent)); return timespent; } prev = ptq; } signal(tqmutex); return SYSERR; }
最新回复(0)