Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void * time_wizard( void * _worker ){
- int ret;
- worker *wrkr = ( worker *) _worker;
- block *myblock = wrkr -> my_block;
- sw_slot *window = wrkr -> sliding_window_slot_;
- sigset_t set;
- beginning:
- sigemptyset( &set );
- sigaddset( &set, SIGUSR1 );
- signal( SIGUSR1, wake_up );
- sigprocmask( SIG_BLOCK, &set, NULL );
- struct timespec now = { 0, 0 };
- if ( wrkr -> is_working == '0') {
- sigpending( &set );
- if( sigismember( &set, SIGUSR1 ) ) {
- sigprocmask( SIG_UNBLOCK, &set, NULL );
- if ( ( myblock -> eraser ) == '1') pthread_exit( NULL );
- signal( SIGUSR1, wake_up );
- }
- sigprocmask( SIG_UNBLOCK, &set, NULL );
- pause();
- if ( ( myblock -> eraser ) == '1') pthread_exit( NULL );
- sigprocmask( SIG_BLOCK, &set, NULL );
- } else {
- printf("\n TIME WIZARD %d RUNNING.\n ", ( wrkr -> identifier ) ); fflush(stdout);
- }
- do {
- printf("\n Time Wizard in the cycle\n"); fflush(stdout);
- ret = nanosleep( &beat, NULL );
- if (ret == -1) Error_( "Error in function : nanosleep() (time_wizard).", 1);
- current_timestamp( &now );
- for ( int i = 0; i < WINDOW_SIZE; i ++ ) {
- if (
- ( window != NULL )
- && ( window -> status == SENT ) ) {
- if ( nanodifftime( &now, &( window -> sent_timestamp ) ) >= ( window -> timeout_interval ) ) {
- if ( retransmission( window, ( wrkr -> sockfd ), (wrkr -> client_addr), ( wrkr -> len ) ) == -1 ) Error_("Error in function: retransmission (time_wizard).", 1);
- }
- }
- if ( window == NULL ) break;
- window = ( window -> next );
- }
- } while( ( wrkr -> is_working ) == '1' );
- printf("\n TIME WIZARD HAS COMPLETED A CYCLE ANG GOES TO SLEEP."); fflush(stdout);
- goto beginning;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement