void
call_arrival_event(Simulation_Run_Ptr simulation_run, void * ptr)
{
  Call_Ptr new_call;
  Channel_Ptr free_channel;
  Simulation_Run_Data_Ptr sim_data;
  double now;

  now = simulation_run_get_time(simulation_run);

  sim_data = simulation_run_data(simulation_run);
  sim_data->call_arrival_count++;

  if((free_channel = get_free_channel(simulation_run)) != NULL) {

    /* Start the call. */
    new_call = (Call_Ptr) xmalloc(sizeof(Call));
    new_call->arrive_time = now;
    new_call->call_duration = get_call_duration();

    server_put(free_channel, (void*) new_call);
    new_call->channel = free_channel;

    schedule_end_call_on_channel_event(simulation_run,
				       now + new_call->call_duration,
				       (void *) free_channel);
  } else {
    /* The call was blocked. */
    sim_data->blocked_call_count++;
  }

  /* Schedule the next call arrival. */
  schedule_call_arrival_event(simulation_run,
	      now + exponential_generator((double) 1/Call_ARRIVALRATE));
}
Esempio n. 2
0
int		server_do(int cs, char *cmd)
{
	if (ft_strcmp(cmd, "quit") == 0)
	{
		printf("Client %d disconnected\n", cs);
		close(cs);
		exit(0);
	}
	else if (ft_strequ(cmd, "ls"))
		server_ls(cs);
	else if (ft_strcmp(cmd, "pwd") == 0)
		server_pwd(cs);
	else if (ft_strncmp(cmd, "mkdir ", 6) == 0)
		server_mkdir(cs, cmd + 6);
	else if (ft_strncmp(cmd, "put ", 4) == 0)
		server_put(cs, cmd + 4);
	else if (ft_strncmp(cmd, "get ", 4) == 0)
		server_get(cs, cmd + 4);
	else if (ft_strncmp(cmd, "cd ", 3) == 0)
		server_cd(cs, cmd + 3);
	else if (ft_strequ(cmd, "cd"))
		server_cd(cs, "/");
	else
		server_sendbuf(cs, "ERROR: Incorrect command");
	return (0);
}
Esempio n. 3
0
void* thr_servidora()   
{
	while (TRUE)
	{
		sem_wait(&semaforo_servidora);
		buffer*aux;
		pthread_mutex_lock(&servidor);
		char *k,*v, *a;
		k=(char*)malloc(KV_SIZE*sizeof(char));
		v=(char*)malloc(KV_SIZE*sizeof(char));
		int ir;
		int d;
		aux=bf[podeServidor].buf;
		a=aux->nomeFuncao;
		ir=aux->shardId;
		k=aux->key;
		v=aux->value;
		d=aux->dim;
		podeServidor=(podeServidor+1)%tamanho_buf;
		pthread_mutex_unlock(&servidor);
		sem_post(&semaforo_cliente);
		pthread_mutex_lock(&acesso);
		if(strcmp(a,"g")==0)
		{
 			server_get(aux, ir, k);
 		}
 		if(strcmp(a,"p")==0)
 		{
 			server_put(aux, ir, k,v);
 			insereEmFicheiro(ir,k,v);
 			
 		}
		if(strcmp(a,"r")==0){
 			server_remove(aux, ir, k);
 			removeFicheiro(ir,k);
 		}
 		if(strcmp(a,"k")==0)
 			server_getAllKeys(aux, ir, d);
 		pthread_mutex_unlock(&acesso);
		sem_post(&aux->semaforo_resposta);
 	}
 	return NULL;
}