Exemplo n.º 1
0
void answer_error_to_client(int err_code, int client_id){
	
	ipc_params_t client_params;
	status client_program;
	
	client_params = get_params_from_pid(client_id, PROGRAM_STATUS, sizeof(struct status), server_params->semid);			
	client_params->socklistener = TRUE;
	client_program.flag = err_code;
	printf("Answering to client: %d\n", client_id);
	ipc_open(client_params, O_WRONLY);
	ipc_send(client_params, &client_program, sizeof(struct status));
	ipc_close(client_params);
	free(client_params->file);
	free(client_params);
	
}
Exemplo n.º 2
0
int main(int argc, char ** argv){
	
	char * program_name;
	struct status cl_program;
	int i;
	ipc_params_t client_params;

	init_processes();

	if(argc > 1){
		program_name = argv[1];
	}else{
		printf("Entrada incorrecta\n");
		return 0;
	}

	client_params = get_params_from_pid(getpid(), PROGRAM_STATUS, sizeof(struct status));

	client_header_t header = calloc(1, sizeof(struct client_header));
	header->program_size = strlen(program_name);
	header->client_id = getpid();

	ipc_open(server_params, O_WRONLY);
	
	server_params->msg_type = PRE_HEADER;
	ipc_send(server_params, header, sizeof(struct client_header));
	
	server_params->msg_type = PROGRAM_STRING;
	ipc_send(server_params, program_name, header->program_size);
	
	ipc_close(server_params);
	
	ipc_create(client_params);
	ipc_open(client_params, O_RDONLY);
	while (!ipc_receive(client_params, &cl_program, sizeof(struct status)));
	ipc_close(client_params);
	ipc_destroy(client_params);
	
	for (i = 0; i < MEM_SIZE; i++){
		printf("%d ", cl_program.mem[i]);
	}
	printf("\n");

	return 0;
}
Exemplo n.º 3
0
void * run_program(void * program_stat)
{
    ipc_params_t client_params;

    stack_t c_stack;
    graph_t c_graph;
    int memkey, i;
    status client_program;
    process_t process_type;

    thread_status_t thread_info = (thread_status_t)program_stat;

    c_stack = parse_file((char*)thread_info->file);

    c_graph = build_graph(c_stack);

    if (c_graph != NULL)
    {
        create_sh_graph(c_graph, get_graph_size(c_graph),
                        &memkey, &client_program.g_header);
        client_program.cursor = 0;
        client_program.flag = FALSE;
        for(i = 0; i < MEM_SIZE; i++) {
            client_program.mem[i] = 0;
        }
        process_type = c_graph->first->instruction_process->instruction_type;
        client_program.mtype = process_type->params->unique_mq_id;
        ipc_send(process_type->params, &client_program, sizeof(struct status));
    } else {
        printf("Entrada incorrecta\n");
    }
    while(!ipc_receive(server_receive_params, &client_program,
                       sizeof(struct status)))
        sleep(1);

    client_params = get_params_from_pid(thread_info->client_id, PROGRAM_STATUS, sizeof(struct status));

    ipc_open(client_params, O_WRONLY);
    ipc_send(client_params, &client_program, sizeof(struct status));
    ipc_close(client_params);
}
Exemplo n.º 4
0
void * run_server_receive(void * params){
	
	ipc_params_t client_params;
	status client_final;
	
	ipc_create(server_receive_params);
	ipc_open(server_receive_params, O_RDONLY|O_NONBLOCK);
	
	while(1){
		if(ipc_receive(server_receive_params, &client_final, sizeof(struct status))){
			client_params = get_params_from_pid(client_final.client_id, PROGRAM_STATUS, sizeof(struct status), server_params->semid);			
			client_params->socklistener = TRUE;
			printf("Answering to client: %d\n", client_final.client_id);
			ipc_open(client_params, O_WRONLY);
			ipc_send(client_params, &client_final, sizeof(struct status));
			ipc_close(client_params);
			free(client_params->file);
			free(client_params);
		}
		sleep(1);
	}
}