Modularised /udpclient_m.cpp
// updating window based on 4 states
updating window based on 4 states
updating window based on 4 states
void update_window(window* z,int nochunks)
{
        if(z->state==0)
        {
           z->windsize=(z->rwnd<z->cwnd)? z->rwnd : z->cwnd;
        }
        else if(z->state==1)
        {
            z->windsize=z->base-z->curr;
            if(z->windsize>=z->ssthresh)
            {
                z->ssthresh=z->ssthresh/2;
                z->cwnd=z->ssthresh;
            }
            else
            {
                z->windsize=1;
            }
        }
        else if(z->state==2)
        {
            z->windsize=z->base-z->curr;
            if(z->prev==-1)
            {
                z->prev=z->ack;
                z->count=0;
            }
            else if(z->prev!=z->ack)
            {
                z->prev=z->ack;
                z->count=0;
            }
            else
            {
                z->count++;
            }
            if(z->count==3)
            {
                z->count=0;
                z->ssthresh=z->ssthresh/2;
                if(z->ssthresh==0) z->ssthresh=1;
                z->cwnd=z->ssthresh;
                 z->flag=1;
             }
        }
        else if(z->state==3)
        {
            if(z->windsize<=z->ssthresh) z->cwnd=z->windsize+(z->ack-z->curr);
            else    z->cwnd=z->windsize+1;
        }
        z->state=-1;
    return;
}
void update_window ( window * z , int nochunks ) { if ( z -> state == 0 ) { z -> windsize = ( z -> rwnd < z -> cwnd ) ? z -> rwnd : z -> cwnd ; } else if ( z -> state == 1 ) { z -> windsize = z -> base - z -> curr ; if ( z -> windsize >= z -> ssthresh ) { z -> ssthresh = z -> ssthresh / 2 ; z -> cwnd = z -> ssthresh ; } else { z -> windsize = 1 ; } } else if ( z -> state == 2 ) { z -> windsize = z -> base - z -> curr ; if ( z -> prev == -1 ) { z -> prev = z -> ack ; z -> count = 0 ; } else if ( z -> prev != z -> ack ) { z -> prev = z -> ack ; z -> count = 0 ; } else { z -> count ++ ; } if ( z -> count == 3 ) { z -> count = 0 ; z -> ssthresh = z -> ssthresh / 2 ; if ( z -> ssthresh == 0 ) z -> ssthresh = 1 ; z -> cwnd = z -> ssthresh ; z -> flag = 1 ; } } else if ( z -> state == 3 ) { if ( z -> windsize <= z -> ssthresh ) z -> cwnd = z -> windsize + ( z -> ack - z -> curr ) ; else z -> cwnd = z -> windsize + 1 ; } z -> state = -1 ; return ; }
updating window based on 4 states
updating window based on 4 states