void
GameSession::restart_level()
{
  game_pause   = false;
  exit_status  = NONE;
  end_sequence = NO_ENDSEQUENCE;

  fps_timer.init(true);
  frame_timer.init(true);

  float old_x_pos = -1;

  if (world)
    { // Tux has lost a life, so we try to respawn him at the nearest reset point
      old_x_pos = world->get_tux()->base.x;
    }
  
  delete world;

  if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
    {
      world = new World(subset);
    }
  else if (st_gl_mode == ST_GL_DEMO_GAME)
    {
      world = new World(subset);
    }
  else
    {
      world = new World(subset, levelnb);
    }

  // Set Tux to the nearest reset point
  if (old_x_pos != -1)
    {
      ResetPoint best_reset_point = { -1, -1 };
      for(std::vector<ResetPoint>::iterator i = get_level()->reset_points.begin();
          i != get_level()->reset_points.end(); ++i)
        {
          if (i->x < old_x_pos && best_reset_point.x < i->x)
            best_reset_point = *i;
        }
      
      if (best_reset_point.x != -1)
        {
          world->get_tux()->base.x = best_reset_point.x;
          world->get_tux()->base.y = best_reset_point.y;
        }
    }
    
  if (st_gl_mode != ST_GL_DEMO_GAME)
    {
      if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
        levelintro();
    }

  time_left.init(true);
  start_timers();
  world->play_music(LEVEL_MUSIC);
}
Exemple #2
0
static int bfin_lq035_fb_open(struct fb_info *info, int user)
{
	unsigned long flags;

	spin_lock_irqsave(&bfin_lq035_lock, flags);
	lq035_open_cnt++;
	spin_unlock_irqrestore(&bfin_lq035_lock, flags);

	if (lq035_open_cnt <= 1) {
		bfin_write_PPI_CONTROL(0);
		SSYNC();

		set_vcomm();
		config_dma();
		config_ppi();

		/* start dma */
		enable_dma(CH_PPI);
		SSYNC();
		bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN);
		SSYNC();

		if (!t_conf_done) {
			config_timers();
			start_timers();
		}
		/* gpio_set_value(MOD,1); */
	}

	return 0;
}
Exemple #3
0
    void
    on_idle() {
	scoped_lock with(lock);
	make_new_connections();
	close_connections();
	write_buffers();
	start_reads();
        start_timers();
	close_idle_if_stop();
    }
Exemple #4
0
int motor_pwm_init(void)
{
	const int ret = init_constants(config_get("mot_pwm_hz"));
	if (ret) {
		return ret;
	}

	init_timers();
	start_timers();

	motor_pwm_set_freewheeling();
	return 0;
}
Exemple #5
0
  void APIC_Timer::calibrate()
  {
    init();

    if (ticks_per_micro != 0) {
      // make sure timers are delay-initalized
      const auto irq = LAPIC_IRQ_TIMER;
      Events::get().subscribe(irq, start_timers);
      // soft-trigger IRQ immediately
      Events::get().trigger_event(irq);
      return;
    }

    // start timer (unmask)
    INFO("APIC", "Measuring APIC timer...");

    auto& lapic = APIC::get();
    // See: Vol3a 10.5.4.1 TSC-Deadline Mode
    // 0xFFFFFFFF --> ~68 seconds
    // 0xFFFFFF   --> ~46 milliseconds
    lapic.timer_begin(0xFFFFFFFF);
    // measure function call and tick read overhead
    uint32_t overhead;
    [&overhead] {
        overhead = APIC::get().timer_diff();
    }();
    // restart counter
    lapic.timer_begin(0xFFFFFFFF);

    /// use PIT to measure <time> in one-shot ///
    PIT::oneshot(milliseconds(CALIBRATION_MS),
    [overhead] {
      uint32_t diff = APIC::get().timer_diff() - overhead;
      assert(ticks_per_micro == 0);
      // measure difference
      ticks_per_micro = diff / CALIBRATION_MS / 1000;
      // stop APIC timer
      APIC::get().timer_interrupt(false);

      //printf("* APIC timer: ticks %ums: %u\t 1mi: %u\n",
      //       CALIBRATION_MS, diff, ticks_per_micro);
      start_timers();

      // with SMP, signal everyone else too (IRQ 1)
      if (SMP::cpu_count() > 1) {
        APIC::get().bcast_ipi(0x21);
      }
    });
  }
Exemple #6
0
int 
main(int argc, char *argv[])
{
    // thread stuff
    pthread_t tid_recv;
    struct sched_param sp_recv;
    struct rlimit rl;
    cpu_set_t mask;

    void *thd_ret;

    if (argc != 3) {
        printf("Usage: %s <msg size> <sleep_var>\n", argv[0]);
        return -1;
    }

    // For signal handlers
    ratectl = 1;
    start_timers();

    // Set up rlimits to allow more CPU usage
    rl.rlim_cur = RLIM_INFINITY;
    rl.rlim_max = RLIM_INFINITY;
    if(setrlimit(RLIMIT_CPU, &rl)) {
        perror("set rlimit: ");
        return -1;
    }
    printf("CPU limit removed\n");

    // Set up the receiver and create a thread for it
    sp_recv.sched_priority = sched_get_priority_max(SCHED_RR);
    if(pthread_create(&tid_recv, NULL, recv_pkt, (void *) argv) != 0) {
        perror("pthread create receiver: ");
        return -1;
    }
    CPU_ZERO(&mask);
    CPU_SET(1, &mask);
    if(pthread_setaffinity_np(tid_recv, sizeof(mask), &mask ) == -1 ) {
        perror("setaffinity recv error: ");
        return -1;
    }
    printf("Set affinity for recv thread\n");

    // We're done here; we'll wait for the threads to do their thing
    pthread_join(tid_recv, &thd_ret);
 
    return 0;
}
Exemple #7
0
int main( void )
{
    init_arduino( );

    init_globals( );

    init_devices( );

    init_communication_interfaces( );

    start_timers( );

    DEBUG_PRINTLN( "init complete" );

    while( true )
    {
        check_for_incoming_message( );

        check_for_faults( );
    }
}
int main(int argc, char const *argv[])
{
	int rv;
	int server_fd;

	read_config(CONFIG_PATH);

	server_fd = create_unix_server(unix_server_name);
	if (server_fd < 0)
		return 1;

	rv = start_child_processes();
	if (rv < 0)
		return 1;

	start_timers();
	wait_heart_beat(server_fd);
	
	delete_timers();
	close(server_fd);

	return 0;
}
Exemple #9
0
static int tx09_fb_open(struct fb_info *info, int user)
{
	unsigned long flags;

	pr_debug("%s\n", __func__);

	spin_lock_irqsave(&tx09_lock, flags);
	tx09_open_cnt++;	/* increase counter */
	spin_unlock_irqrestore(&tx09_lock, flags);

	if (tx09_open_cnt <= 1) {	/* opened the first time */

		/* stop PPI */
		WRITE_PPI_CONTROL(0);
		SSYNC();

		/* configure dma stuff */
		config_dma();

		config_ppi();

		/* start dma */
		enable_dma(CH_PPI);
		SSYNC();

		/* start PPI */
		WRITE_PPI_CONTROL(READ_PPI_CONTROL() | PORT_EN);
		SSYNC();

		if (!t_conf_done)
			config_timers();

		start_timers();
	}

	return 0;
}
Exemple #10
0
//Aplicamos todos los algoritmos a todos los archivos
void TodosArchivos(){
    int n, costo=0;
    int nficheros=20;
    char *nombres[nficheros];
    double tiempo;
    DarNombres(nombres);

    int finales[nficheros][5];
    float tiempos[nficheros][5];
		int tamanio[nficheros];
		int resultadosoptimos[nficheros];
		resultadosoptimos[0]=2192;
		resultadosoptimos[1]=14142;
		resultadosoptimos[2]=6194;
		resultadosoptimos[3]=3796;
		resultadosoptimos[4]=130;
		resultadosoptimos[5]=116;
		resultadosoptimos[6]=64;
		resultadosoptimos[7]=88700;
		resultadosoptimos[8]=360630;
		resultadosoptimos[9]=15812;
		resultadosoptimos[10]=23386;
		resultadosoptimos[11]=90998;
		resultadosoptimos[12]=115534;
		resultadosoptimos[13]=140691;
		resultadosoptimos[14]=1855928;
		resultadosoptimos[15]=13499184;
		resultadosoptimos[16]=15844731;
		resultadosoptimos[17]=441786736;
		resultadosoptimos[18]=43849646;
		resultadosoptimos[19]=7620628;
    double desviacion_total[5];
		double desviaciones[nficheros][5];

    for (int i=0; i<nficheros; i++){
        n = leerNumeroDatos(nombres[i]);
        reservarEspacio(n);
        obtenerMatrices(nombres[i], mat1, mat2);
        tamanio[i]=n;

			  //Aplico Greedy
        start_timers();
        alg_Greedy(n, mat1, mat2, sol, &costo);
        tiempo = elapsed_time();
        finales[i][0]=costo;
        tiempos[i][0]=tiempo;
        desviaciones[i][0]=(finales[i][0] - resultadosoptimos[i])*10;
        desviaciones[i][0] = desviaciones[i][0]/resultadosoptimos[i];
        desviaciones[i][0] = desviaciones[i][0]*10;

			  //Aplico AGG posicional
        start_timers();
        alg_Memetico(n, mat1, mat2, sol, &costo,0,0);
        tiempo = elapsed_time();
        finales[i][1]=costo;
        tiempos[i][1]=tiempo;
        desviaciones[i][1]=(finales[i][1] - resultadosoptimos[i])*10;
        desviaciones[i][1] = desviaciones[i][1]/resultadosoptimos[i];
        desviaciones[i][1] = desviaciones[i][1]*10;

		    alg_Greedy(n, mat1, mat2, sol, &costo);
				//Aplico AGG posicional
				start_timers();
				alg_Memetico(n, mat1, mat2, sol, &costo,0,1);
				tiempo = elapsed_time();
				finales[i][2]=costo;
				tiempos[i][2]=tiempo;
				desviaciones[i][2]=(finales[i][2] - resultadosoptimos[i])*10;
				desviaciones[i][2] = desviaciones[i][2]/resultadosoptimos[i];
				desviaciones[i][2] = desviaciones[i][2]*10;

	    	alg_Greedy(n, mat1, mat2, sol, &costo);
				//Aplico AGG posicional
				start_timers();
				alg_Memetico(n, mat1, mat2, sol, &costo,0,2);
				tiempo = elapsed_time();
				finales[i][3]=costo;
				tiempos[i][3]=tiempo;
				desviaciones[i][3]=(finales[i][3] - resultadosoptimos[i])*10;
				desviaciones[i][3] = desviaciones[i][3]/resultadosoptimos[i];
				desviaciones[i][3] = desviaciones[i][3]*10;

  }

   int cont1=0,cont2=0,cont3=0,cont4=0, cont5=0;
    for (int i=0; i<nficheros; i++){
        int mejor=0;
        if (finales[i][mejor]>=finales[i][1])
            mejor=1;
		    if (finales[i][mejor]>=finales[i][2])
		        mejor=2;
		    if (finales[i][mejor]>=finales[i][3])
		        mejor=3;
        if (mejor == 0) cont1++;
        if (mejor == 1) cont2++;
        if (mejor == 2) cont3++;
        if (mejor == 3) cont4++;

        printf("Problema: %s con n: %d\n",nombres[i],tamanio[i]);
        printf("\tGreeedy: %d en %f\n", finales[i][0],tiempos[i][0]);
        printf("\tAM0: %d en %f\n", finales[i][1],tiempos[i][1]);
        printf("\tAM1: %d en %f\n", finales[i][2],tiempos[i][2]);
        printf("\tAM2: %d en %f\n", finales[i][3],tiempos[i][3]);
    }
    printf("\nNuevo de veces que es mejor:\n Greedy: %d\n AM0: %d\n AM1: %d\n AM2: %d\n",
		       cont1, cont2, cont3, cont4);
    for(int j=0; j< nficheros; j++){
	desviacion_total[0] += desviaciones[j][0];
	desviacion_total[1] += desviaciones[j][1];
	desviacion_total[2] += desviaciones[j][2];
	desviacion_total[3] += desviaciones[j][3];
   }
   desviacion_total[0] = desviacion_total[0]/nficheros;
   desviacion_total[1] = desviacion_total[1]/nficheros;
   desviacion_total[2] = desviacion_total[2]/nficheros;
   desviacion_total[3] = desviacion_total[3]/nficheros;

   printf("\nDesviaciones: \n Greedy: %f\n AM0: %f\n AM1: %f\n AM2: %f\n",
		desviacion_total[0], desviacion_total[1], desviacion_total[2], desviacion_total[3]);
}
Exemple #11
0
int main(int argc, char * argv[])
{
    int todos = 1;
    if (todos == 1){
        TodosArchivos();
        return 0;
    }

	int n = leerNumeroDatos(argv[1]);
	if (n > 0) {
		reservarEspacio(n);
		obtenerMatrices(argv[1], mat1, mat2);
    double tiempo;
    int costo;
		//Aplico Greedy
    start_timers();
		alg_Greedy(n, mat1, mat2, sol, &costo);
		tiempo = elapsed_time();
		printf("Greedy de %d datos: Coste-> %d. Tiempo-> %fs.\n", n, costo, tiempo);

		printf("Solucion encontrada: ");
		for (int i=0; i<n; i++){
			printf("%d ", sol[i]);
		}
		printf("\n\n");

		//Aplico AM0
    start_timers();
		alg_Memetico(n, mat1, mat2, sol, &costo, 0,0); 
    tiempo = elapsed_time();
		printf("Algoritmos Memeticos 0 de %d datos: Coste-> %d. Tiempo-> %fs.\n", n, costo, tiempo);
		printf("Solucion encontrada: ");
		for (int i=0; i<n; i++){
			printf("%d ", sol[i]);
		}
		printf("\n\n");

		alg_Greedy(n, mat1, mat2, sol, &costo);
		//Aplico AM1
		start_timers();
		alg_Memetico(n, mat1, mat2, sol, &costo, 0,1); 
		tiempo = elapsed_time();
		printf("Algoritmos Memeticos 1 de %d datos: Coste-> %d. Tiempo-> %fs.\n", n, costo, tiempo);
		printf("Solucion encontrada: ");
		for (int i=0; i<n; i++){
			printf("%d ", sol[i]);
		}
		printf("\n\n");


		alg_Greedy(n, mat1, mat2, sol, &costo);
		//Aplico AM2
		start_timers();
		alg_Memetico(n, mat1, mat2, sol, &costo, 0,2); 
		tiempo = elapsed_time();
		printf("Algoritmos Memeticos 2 de %d datos: Coste-> %d. Tiempo-> %fs.\n", n, costo, tiempo);
		printf("Solucion encontrada: ");
		for (int i=0; i<n; i++){
			printf("%d ", sol[i]);
		}
		printf("\n\n");


	}

  return 0;
}
Exemple #12
0
main(int argc , char *argv[])
{
inpfname = argv[1];
int runno, itno, antno;
double time_used;


read_data(inpfname);
print_data();

init_out(inpfname);


time_used = elapsed_time( VIRTUAL );
printf("Initialization took %.10f seconds\n",time_used);

for(runno=0;runno<runs;runno++)
{
seed = (long int ) time(NULL);
 start_timers();

 initialize_ants_variables(runno);


 initialize_trail();

 for(itno=0;  bestant.ofn != 436.00 &&  itno<ncmax ;itno++)
 {
	 
 iteration_init(itno);
  
 find_values();
  
 analysis( itno);
 

update_stats(itno,runno);

#if (usels == 1)

if(lswithitbest ==1)
{
ls(&itbestval,itno);
lsstats(itno,runno);
}

if(lswithbest ==1)
{
ls(&bestval,itno);
lsstats(itno,runno);
}

#endif

 trail();

if(!(itno%statsafterit))
{ print_itstats(itno ,runno);}

}//end of nc max iterations

update_stats(itno,runno);
report_run(runno);

}//end of runs

final_stats();

freememory();


}//end of main
int main(int argc, char *argv[])
{
	int fd, fdr;
	struct sockaddr_in sa;
	int msg_size;
	char *msg;
	int sleep_val;

	if (argc != 5 && argc != 6) {
		printf("Usage: %s <ip> <port> <msg size> <sleep_val> <opt:rcv_port>\n", argv[0]);
		return -1;
	}
	sleep_val = atoi(argv[4]);
	sleep_val = sleep_val == 0 ? 1 : sleep_val;

	msg_size = atoi(argv[3]);
	msg_size = msg_size < (sizeof(unsigned long long)*2) ? (sizeof(unsigned long long)*2) : msg_size;
	msg     = malloc(msg_size);
	rcv_msg = malloc(msg_size);

	sa.sin_family      = AF_INET;
	sa.sin_port        = htons(atoi(argv[2]));
	sa.sin_addr.s_addr = inet_addr(argv[1]);
	if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
		perror("Establishing socket");
		return -1;
	}

	if (argc == 6) {
		struct sockaddr_in si;

		if ((fdr = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
			perror("Establishing receive socket");
			return -1;
		}
		/*if (socket_nonblock(fdr)) {
			return -1;
		}*/
		memset(&si, 0, sizeof(si));
		si.sin_family      = AF_INET;
		si.sin_port        = htons(atoi(argv[5]));
		si.sin_addr.s_addr = htonl(INADDR_ANY);
		printf("Binding the receive socket to port %d\n", atoi(argv[5]));
		if (bind(fdr, (struct sockaddr *)&si, sizeof(si))) {
			perror("binding receive socket");
			return -1;
		}
		rcv = 1;
	}

	start_timers();

	while (1) {
		int i;
		
		construct_header(msg);
		
		if (sendto(fd, msg, msg_size, 0, (struct sockaddr*)&sa, sizeof(sa)) < 0 &&
		    errno != EINTR) {
			perror("sendto");
			return -1;
		}
		msg_sent++;
		
		for (i=0 ; i < sleep_val ; i++) {
			if (argc == 6) {
				do_recv_proc(fdr, msg_size);
			}
			foo++;
		}
		//nanosleep(&ts, NULL);
	}

	return 0;
}
Exemple #14
0
void pim_interface::address_added_or_removed(bool added, const inet6_addr &addr) {
	if (added) {
		if (addr.is_linklocal()) {
			if (intf_state != NOT_READY)
				return;

			if (!pim->pim_sock.join_mc(owner(), pim_all_routers)) {
				if (should_log(WARNING)) {
					log().perror("Failed to join All-PIM-"
						     "Routers multicast group");
				}
			}

			if (!start_timers()) {
				if (should_log(WARNING)) {
					log().writeline("Failed to start required timers");
				}
			}

			state was = intf_state;
			intf_state = owner()->globals().empty() ? LOCAL_READY : READY;

			if (should_log(DEBUG)) {
				if (was != intf_state) {
					if (intf_state == LOCAL_READY) {
						log().writeline("Has link-local address, changed to LOCAL_READY.");
					} else {
						log().writeline("Has global address, changed to READY.");
					}
				}
			}

			pim->interface_state_changed(this, NOT_READY);
		} else {
			if (intf_state == LOCAL_READY) {
				intf_state = READY;

				if (should_log(DEBUG))
					log().writeline("Has global address, changed to READY");

				pim->interface_state_changed(this, LOCAL_READY);
			}
		}
	} else {
		if (addr.is_linklocal()) {
			if (owner()->linklocals().empty()) {
				intf_state = NOT_READY;

				pim->pim_sock.leave_mc(owner(), pim_all_routers);

				if (should_log(DEBUG))
					log().writeline("Lost link-local, changed to NOT_READY");

				// stop hello timer

				pim->interface_state_changed(this, LOCAL_READY);
			}
		} else {
			if (owner()->globals().empty() && intf_state == READY) {
				intf_state = LOCAL_READY;
				if (should_log(DEBUG))
					log().writeline("Lost global address, changed to LOCAL_READY");
				pim->interface_state_changed(this, READY);
			}

			if (pim->my_address() == addr) {
				pim->check_my_address(true);
			}
		}
	}
}
Exemple #15
0
void main (void)
{
    io_init();
    servo_init();
    timers_init();
    i2c_init();
    wdt_enable(WDTO_15MS);
    sei();
    start_timers();

    flags.new_buf_ready = 0;
    flags.i2c_first_byte = 0;
    flags.servo_pd_changed = 0;
    flags.servo_minmaxpd_cnahged = 0;

#ifdef MEGADEBUG
    struct {
        uint8_t sw1 : 1;
        uint8_t sw2 : 1;
    } ss;

    UTILS_DDR_CLR(I2CSCL_PORT, I2CSCL_PIN);
    UTILS_DDR_CLR(I2CSDA_PORT, I2CSDA_PIN);
    UTILS_PORT_SET(I2CSCL_PORT, I2CSCL_PIN);
    UTILS_PORT_SET(I2CSDA_PORT, I2CSDA_PIN);
#endif

    for (;;)
    {
#ifdef MEGADEBUG
        if (!UTILS_PIN_VALUE(I2CSCL_PORT, I2CSCL_PIN))
        {
            if (!ss.sw1)
            {
                servo[0].target += 16;
            }
            ss.sw1 = 1;
        }
        else
        {
            ss.sw1 = 0;
        }

        if (!UTILS_PIN_VALUE(I2CSDA_PORT, I2CSDA_PIN))
        {
            if (!ss.sw2)
            {
                servo[0].target -= 16;
            }
            ss.sw2 = 1;
        }
        else
        {
            ss.sw2 = 0;
        }
#endif

#ifndef MEGADEBUG
        // i2c
        if (TWCR & _BV(TWINT))
        {
            // i2c 
            switch (TWSR)
            {
                case TW_SR_SLA_ACK: // i2c start
                    flags.i2c_first_byte = 1;
                    break;
                case TW_SR_DATA_ACK: // i2c byte received
                    if (flags.i2c_first_byte)
                    {
                        i2cMemAddr = TWDR;
                        flags.i2c_first_byte = 0;
                    }
                    else
                    {
                        i2c_read();
                        i2cMemAddr ++;
                    }
                    break;
                case TW_ST_DATA_ACK:
                    i2c_write();
                    i2cMemAddr ++;
                    break;
            }

            TWCR |= _BV(TWINT);
        }
#endif

        // servo.position 
        if (UTILS_AGGL(TIFR, ITIMER) & _BV(UTILS_AGGL2(OCF, ITIMER, A)))
        {
            // Timer ITIMER compare match A
            UTILS_AGGL(TIFR, ITIMER) |= _BV(UTILS_AGGL2(OCF, ITIMER, A)); 

            for (uint8_t i = 0; i < SERVO_NUM; i ++)
            {
                if (servo[i].position != servo[i].target)
                {
                    UTILS_PORT_SET(LED_PORT, LED_PIN);
                    if (servo[i].speed == 0)
                    {
                        // Change position immediately
                        servo[i].position = servo[i].target;
                        servo_find_pd(i);
                        flags.servo_pd_changed = 1;
                    }
                    else
                    {
                        if (servo[i].speed_counter == servo[i].speed)
                        {
                            // Change position
                            if (servo[i].position < servo[i].target)
                                servo[i].position ++;
                            else
                                servo[i].position --;
                            servo_find_pd(i);
                            flags.servo_pd_changed = 1;
                            servo[i].speed_counter = 0;
                        }
                        else
                            servo[i].speed_counter ++;
                    }
                }
                else
                {
                    UTILS_PORT_CLR(LED_PORT, LED_PIN);
                }
            }

            if (flags.servo_minmaxpd_cnahged)
            {
                for (uint8_t i = 0; i < SERVO_NUM; i ++)
                {
                    servo_find_pd(i);
                }
                flags.servo_pd_changed = 1;
                flags.servo_minmaxpd_cnahged = 0;
            }

            if (flags.servo_pd_changed)
            {
                servo_sort();
                outstate_gen();
                flags.servo_pd_changed = 0;
            }
        }

        wdt_reset();
    }
}
Exemple #16
0
void channel::talk()
{
    proxy::talk();
    start_timers();
}
int main(int argc, char *argv[])
{
	struct sockaddr_in sa;
	char *msg;
	int sleep_val, i, msg_size;

	if (argc != 6) {
		printf("Usage: %s <ip> <port> <msg size> <sleep_val> <conns>\n", argv[0]);
		return -1;
	}
	sleep_val = atoi(argv[4]);
	sleep_val = sleep_val == 0 ? 1 : sleep_val;

	msg_size = atoi(argv[3]);
	msg_size = msg_size < (sizeof(unsigned long long)*2) ? (sizeof(unsigned long long)*2) : msg_size;
	msg      = malloc(msg_size);
	rcv_msg  = malloc(msg_size);

	conns    = atoi(argv[5]);
	conn_fds = malloc(conns * sizeof(int));

	if (!conn_fds || !msg || !rcv_msg) return -1;
	
	sa.sin_family      = AF_INET;
	sa.sin_port        = htons(atoi(argv[2]));
	sa.sin_addr.s_addr = inet_addr(argv[1]);
	for (i = 0 ; i < conns ; i++) {
		if ((conn_fds[i] = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
			perror("Establishing socket");
			fflush(stdout);
			return -1;
		}
		if (socket_nonblock(conn_fds[i])) return -1;
		if (connect(conn_fds[i], (struct sockaddr*)&sa, sizeof(sa)) &&
		    errno != EINPROGRESS) {
			perror("connecting");
			return -1;
		}
	}
	printf("Start communication\n");
	fflush(stdout);
	start_timers();
	while (1) {
		int i, j;

		construct_header(msg);
		
		for (i = 0 ; i < conns ; i++) {
			if (write(conn_fds[i], msg, msg_size) < 0 &&
			    errno != EINTR && errno != EAGAIN) {
				perror("sendto");
				fflush(stdout);
				return -1;
			}
			if (errno != EINTR || errno != EAGAIN) {
				msg_sent++;
			}
			for (j = 0 ; j < sleep_val ; j++) {
				do_recv_proc(conn_fds[i], msg_size);
			}
		}
		//nanosleep(&ts, NULL);
	}

	return 0;
}