Esempio n. 1
0
File: sender.c Progetto: s4byun/SWP
void handle_timedout_frames(Sender * sender,
        LLnode ** outgoing_frames_head_ptr)
{
    //Iterate through the send queue
    int i;
    for(i=0; i < glb_receivers_array_length; i++)
    {
        send_Q ** curr_node = sender->send_q_head[i];
        int lar = sender->LAR[i];
        int lfs = sender->LFS[i];
        while(lar != lfs)
        {
            lar = (lar + 1) % (MAX_SEQ_NUM + 1);
            send_Q * curr = curr_node[lar%WS];
            Frame * sent_frame = curr->frame;
            struct timeval * tv = curr->frame_timeout;
            struct timeval now;
            gettimeofday(&now, NULL);

            //A frame with set timeout is found
            if(tv != NULL)
            {
                //Update timeout field for old, timed out frames
                if(timeval_usecdiff(tv, &now) > 0)
                {
                    fprintf(stderr, "TIMEDOUT DATA %s being resent\n", sent_frame->data);
                    char * outframe_char_buf = convert_frame_to_char(sent_frame);
                    ll_append_node(outgoing_frames_head_ptr, outframe_char_buf);
                    calculate_timeout(curr->frame_timeout);
                }
            }

            //Update timeout field for fresh outgoing frames
            if(tv == NULL && sent_frame != NULL)
            {
                fprintf(stderr, "FRESH DATA %s being sent\n", sent_frame->data);
                curr->frame_timeout = (struct timeval *) malloc(sizeof(struct timeval));
                calculate_timeout(curr->frame_timeout);
            }
        }
    }
}
Esempio n. 2
0
void wait_for_start(nstate *state)
{
	draw_pause_continue_button(state);
	while(state->state == STATE_STOPPED) {
		GrGetNextEvent(&state->event);
		handle_event(state);
	}
	if(state->state == STATE_NEWGAME) state->state = STATE_RUNNING;
	draw_pause_continue_button(state);
	calculate_timeout(state);
}
Esempio n. 3
0
void do_update(nstate *state)
{
	struct timeval t;

	gettimeofday(&t, NULL);

	if((t.tv_sec > state->timeout.tv_sec) ||
			((t.tv_sec == state->timeout.tv_sec) &&
			(t.tv_usec >= state->timeout.tv_usec))) {
		drop_block_1(state);
		calculate_timeout(state);
	} 
}