Ejemplo n.º 1
0
void recibirOrdenReduce(int socketQueEscribe){
	uint32_t longNombreEnDondeGuardarlo;
	recibir(socketQueEscribe,&longNombreEnDondeGuardarlo,sizeof(uint32_t));
	char* nombreEnDondeGuardarlo = malloc(longNombreEnDondeGuardarlo);
	recibir(socketQueEscribe,nombreEnDondeGuardarlo,longNombreEnDondeGuardarlo);


	//uint32_t tamanioPaquete;
	//recv(socketQueEscribe, &tamanioPaquete, sizeof(tamanioPaquete),0);
	//printf("recibi el tamanioPaquete: %d\n", tamanioPaquete);
	//char* mensajeSerializado = malloc(tamanioPaquete);
	//recibir(socketQueEscribe,mensajeSerializado, tamanioPaquete);
	//t_list* listaNodoNombres = deserializarOrdenDeReduce(mensajeSerializado);

	t_list* listaNodoNombres = recibirEstructurasDelNodo(socketQueEscribe);

	char* identificador = string_itoa(socketQueEscribe);
	char* nombre = "reducer.pl";
	//logearOrdenReduce(identificador,nombre);
	string_append(&identificador,nombre);

	char respuesta = ejecutarReduce(identificador,nombreEnDondeGuardarlo,listaNodoNombres);

	enviarRespuestaDelMapAlJob(respuesta,socketQueEscribe);

	free(nombreEnDondeGuardarlo);
	list_destroy_and_destroy_elements(listaNodoNombres, (void*) estructuraN_destroy);
}
Ejemplo n.º 2
0
t_list* solicitarArchivosAlFileSystem(t_list* listaDeUrls){  //lista de char*

	//enviar peticion
	int tamanioTotal = 0;
	char* mensajeSerializado = serializarPedidoDeArchivosAlFileSystem(listaDeUrls, &tamanioTotal);
	enviar(socketFS,mensajeSerializado, tamanioTotal);

	//recibir respuesta
	char idProceso, idOperacion;

	recibir(socketFS, &idProceso, sizeof(char));
//	printf("IDPROCESO: %c", idProceso);
	recibir(socketFS, &idOperacion, sizeof(char));
//	printf("IDOPERACION: %c", idOperacion);

	//OJO CON LA SINCRONIZACION,  PENSAR!.

	if(idOperacion!='M'){

	t_list* estructuraTrabajo = deserializarYarmarEstructura();
	return estructuraTrabajo;

	}

	t_list* listaVacia = list_create(); //por si falla el pedido
	return listaVacia;
}
Ejemplo n.º 3
0
void conseguirArchivoFinal(int socket_FS){
	uint32_t tamanioRuta;
	recibir(socket_FS,&tamanioRuta,sizeof(uint32_t));
	char* ruta = malloc(tamanioRuta);
	recibir(socket_FS,ruta,tamanioRuta);
	uint32_t tamanioNombre;
	recibir(socket_FS,&tamanioNombre,sizeof(uint32_t));
	char* nombre = malloc(tamanioNombre);
	recibir(socket_FS,nombre,tamanioNombre);

	int fd_archivo = open(nombre,O_RDONLY);
	char* mapeo;
	int tamanioArchivo = tamanio_archivo(fd_archivo);

	if( (mapeo = mmap(NULL, tamanioArchivo, PROT_READ, MAP_SHARED, fd_archivo, 0 )) == MAP_FAILED){
	//Si no se pudo ejecutar el MMAP, imprimir el error y aborta;
		printf("Error con MMAP");
		abort();
		}

	char idProceso = 'N';
	char idOperacion = 'T';
	int tamanioEnvio = tamanioArchivo + 1;

	enviar(socket_FS,&idProceso,sizeof(char));
	enviar(socket_FS,&idOperacion,sizeof(char));
	enviar(socket_FS,&tamanioRuta,sizeof(uint32_t));
	enviar(socket_FS,ruta,tamanioRuta);
	enviar(socket_FS,&tamanioEnvio,sizeof(uint32_t));
	enviar(socket_FS,mapeo,tamanioEnvio);
	close(fd_archivo);
	munmap(mapeo,tamanioEnvio);
}
Ejemplo n.º 4
0
void conseguirBloqueYEnviarAlFS(int socket_FS){
	int bloqueABuscar;
	recibir(socket_FS,&bloqueABuscar,sizeof(int));
	int tamanioRuta;
	recibir(socket_FS,&tamanioRuta,sizeof(int));
	char* rutaLinux = malloc(tamanioRuta);
	recibir(socket_FS,rutaLinux,tamanioRuta);

	char* bloqueLeido;
	bloqueLeido = conseguirUnBloquePedido(bloqueABuscar);
	int tamanio = strlen(bloqueLeido)+1;

	//loguearLecturaDeBloques(bloqueABuscar);
	char idProceso = 'N';
	char idOperacion = 'B';

	enviar(socket_FS,&idProceso,sizeof(char));
	enviar(socket_FS,&idOperacion,sizeof(char));
	enviar(socket_FS,&tamanioRuta,sizeof(int));
	enviar(socket_FS,rutaLinux,tamanioRuta);
	enviar(socket_FS,&tamanio,sizeof(int));
	enviar(socket_FS,bloqueLeido,tamanio);

	free(bloqueLeido);
	free(rutaLinux);


}
Ejemplo n.º 5
0
void conseguirYEnviarLoQuePideElFS(socket_FS){
	uint32_t tamanio;
	char* nombreArchivo;
	recibir(socket_FS,&tamanio,sizeof(uint32_t));
	recibir(socket_FS,nombreArchivo,tamanio);

	int fd_archivo = open(nombreArchivo,O_RDONLY); //agregar al archivo de config!!
	char* mapeo;
	uint32_t tamanioArchivo = tamanio_archivo(fd_archivo);

	if( (mapeo = mmap(NULL, tamanioArchivo, PROT_READ, MAP_SHARED, fd_archivo, 0 )) == MAP_FAILED){
		//Si no se pudo ejecutar el MMAP, imprimir el error y aborta;
		printf("Error con MMAP");
		abort();
	}

//	char idProceso = 'N';
//	char idOperacion = 'A';

//	enviar(socket_FS,&idProceso,sizeof(char));
//	enviar(socket_FS,&idOperacion,sizeof(char));
	enviar(socket_FS,&tamanioArchivo,sizeof(uint32_t));
	enviar(socket_FS,mapeo,tamanioArchivo);
	munmap(mapeo,tamanioArchivo);
}
void esperar_jugadores(int socket_fd){
    char buffer[1000];
    recibir(socket_fd, buffer);
    if(!strcmp(buffer, "wait")){
	printw("Esperando mas usuarios...\n");
	refresh();
    }
    while(!strcmp(buffer, "wait"))
	recibir(socket_fd, buffer);
}
Ejemplo n.º 7
0
void *muestrear(void *arg) {
	char select[16];
	int i;
	//printf("Soy el HILO\n");
	while(1) {
		//printf("Thread: Valor anterior %s\n", select);
		recibir(fd,select,15);
		select[1]='\0';
		
		//printf("Thread: Valor leido %u\n", (unsigned char)select[0]);
		sensoresPIC=(unsigned int) select[0];
		for(i=0;i<8;i++) {
			if( BIT_TEST(sensoresPIC,i) )
				printf("X");
			else
				printf("_");
		}
		if( borde == DCHO )
			printf("\tDCHO\t%lf",error);
		else
			printf("\tIZQDO\t%lf",error);
		printf("\n");
		//printf("KK %u\n", sensoresPIC);
		}

	return NULL;

}
Ejemplo n.º 8
0
void* atender(void *parametro)
{ 
	int fdcliente_local=*(int *)parametro;
	int nro_jugador=cont_clientes;
	int seguir=1,j;
	struct paketeSC packout;
	struct paketeCS packin;
	fdclientes[nro_jugador-1]=fdcliente_local;

while(seguir)
{	packin.cabecera='X';
	if(recibir (fdcliente_local,(void*)&packin,sizeof(packin)))
		perror("recibir");
	switch(packin.cabecera)
	{
	case 'N': //recibe nombre		
		strcpy(vnombres[nro_jugador-1],packin.nombre);
		printf("Se conecto: %s\n", packin.nombre);fflush(stdout);
		break;
	case 'S': //recibe movimiento
		if(direcc[nro_jugador-1]!=-1)		
		
			if( !(   (direcc[nro_jugador-1]==1 && packin.direcc==3)||
				(direcc[nro_jugador-1]==2 && packin.direcc==4)||
				(direcc[nro_jugador-1]==3 && packin.direcc==1)||
				(direcc[nro_jugador-1]==4 && packin.direcc==2) ) )
					direcc[nro_jugador-1]=packin.direcc;
	}
}

}//main
/*
 * @Parametros:
 * 				-socket_cliente: El descriptor que está activo
 * 				-*select_orquestador
 * 				-(*atender_peticion_X): Puntero a función, el orquestador y el planificador colocarán la que corresponda.
 */
int realizar_accion_plataforma(int socket_cliente, t_socket_select *socket_select, uint32_t (*atender_peticion_X)(uint32_t cliente, t_stream *pedido, t_queue_rr *cola_rr), t_queue_rr *cola_rr){

	t_stream *buffer;
	int cant_bytes = recibir(socket_cliente, (void*)&buffer);
	if(cant_bytes > 0){
		atender_peticion_X(socket_cliente, buffer, cola_rr);
	}

	else{

		//Aviso de la desconexión para que el proceso tomé las medidas que sean necesarias.
		if(cant_bytes == 0){
			int *socket_cierre = malloc(sizeof(int));
			t_header *header_cierre = malloc(sizeof(t_header));
			header_cierre->type = HUBO_UNA_DESCONEXION;
			*socket_cierre = socket_cliente;
			buffer = (t_stream*) header_cierre;
			atender_peticion_X(*socket_cierre, buffer, cola_rr);
			free(socket_cierre);
			close(socket_cliente);
			FD_CLR(socket_cliente, &(socket_select->conj_sockets));

		}
		if (cant_bytes < 0)
			perror("receiv");

		//ToDo: Quitar, usado para testear.

		close(socket_cliente);
		FD_CLR(socket_cliente, &(socket_select->conj_sockets));

	}

	return EXIT_SUCCESS;
}
int recibir_t_mensaje(int sock, t_mensaje* request)
{
	int ret;
	char *buffer = NULL;

	buffer = calloc(1, sizeof(t_mensaje));

	ret = recibir(sock, buffer, sizeof(t_mensaje));

	if (ret == WARNING) {
		close(sock);
		free(buffer);
		return WARNING;
	}

	if (ret == ERROR) {
		free(buffer);
		return ERROR;
	}

	memcpy(request, buffer, sizeof(t_mensaje));

	free(buffer);

	return EXITO;
}
Ejemplo n.º 11
0
void ClientSocket :: registrarNickname() {
    std::string mensaje;
    std::string nicknamePropuesto = nickname;
    nickname = "_client";

    Logger::log("CLIENT", "Chequeando caracteres de nickname" , DEBUG);
    for(int i = 0; i < nicknamePropuesto.size(); ++i) {
        if(!isalnum(nicknamePropuesto[i])){
            std::cout << "Client: Error al ingresar: el nickname debe ser alfanumerico" << std::endl;
            Logger::log("CLIENT", "Error: el nickname tenia caracteres no alfanumericos" , DEBUG);
            raise(SIGINT);
        }
    }

    Logger::log("CLIENT", "Intentando registrar nickname: " + nickname , DEBUG);
    char bufferRta[BUFFSIZE];
    std::string rta;

    mensaje = nickname + ": " + nicknamePropuesto;
    enviar ( static_cast<const void*>(mensaje.c_str()),mensaje.size() );
    int longRta = recibir ( static_cast<void*>(bufferRta),BUFFSIZE );
    rta = bufferRta;
    rta.resize(longRta);
    if (rta == "OK") {
        Logger::log("CLIENT", "Se ingreso con nickname: " +  nickname, DEBUG);
        nickname = nicknamePropuesto;
    } else {
        std::cout << "Client: Error al ingresar: " << rta << std::endl;
        Logger::log("CLIENT", "Error al registrar nickname: " + rta , DEBUG);
        raise(SIGINT);
    }
}
Ejemplo n.º 12
0
int reciveRSAsign(int sockfd, EVP_PKEY* pubKey, 
	unsigned char** msg){
	
	char* buff;
	unsigned char* sig = NULL,* auxMsg;
	int msglen = 0;
	if(sockfd <1 || pubKey == NULL || msg == NULL)
		return 0;
	msglen = recibir(sockfd, &buff);
	if(msglen == -1)
		return 0;	
	sig = malloc(sizeof(char) * SHA256_SIGLEN);
	auxMsg =  malloc(sizeof(char) * (msglen - SHA256_SIGLEN));

	if(auxMsg == NULL || sig == NULL){
		return 0;
	}
	
	memcpy(sig, buff, sizeof(char) * SHA256_SIGLEN);
	memcpy(auxMsg, &buff[SHA256_SIGLEN], msglen - SHA256_SIGLEN);
	
	*msg = auxMsg;
	if( !verifySignRSA(pubKey, (const unsigned char*)sig, 
	(const unsigned char*) auxMsg,  SHA256_SIGLEN, msglen - SHA256_SIGLEN))
		
		return 0;
	return msglen - SHA256_SIGLEN;
}
int recibir_map_request(int sock, t_map_request* map_request)
{
	int ret;
	char *buffer = NULL;

	buffer = calloc(1, sizeof(t_map_request));

	//printf("Espero recibir t_nivel (%u)", sizeof(t_nivel));
	ret = recibir(sock, buffer, sizeof(t_map_request));

	if (ret == WARNING) {
		close(sock);
		free(buffer);
		return WARNING;
	}

	if (ret == ERROR) {
		free(buffer);
		return ERROR;
	}

	memcpy(map_request, buffer, sizeof(t_map_request));

	free(buffer);

	return EXITO;
}
Ejemplo n.º 14
0
bool esperar_handshake(un_socket socket_del_cliente) {

	t_paquete * inicio_del_handhsake = recibir(socket_del_cliente);

	bool resultado = string_equals_ignore_case(
			(char *) inicio_del_handhsake->data, "Inicio autenticacion");

	liberar_paquete(inicio_del_handhsake);

	if (resultado) {

		char * respuesta = malloc(12);
		respuesta = "Autenticado";
		enviar(socket_del_cliente, 1, 12, respuesta);

	} else {

		char * respuesta = malloc(6);
		respuesta = "Error";
		enviar(socket_del_cliente, 1, 6, respuesta);

	}

	return resultado;
}
int recibir_struct(int sock, void* myStruct, size_t structSizeOf)
{
	int ret;
	void *buffer = NULL;
	//char strAux[50];

	buffer = calloc(1, structSizeOf);

	ret = recibir(sock, buffer, structSizeOf);

	if (ret == ERROR) {
		free(buffer);
		//return trazarError(errorTrace, "Error al recibir datos :S", ERROR,"comunicacion.h", "recibirHeader()");
		return ERROR;
	}

//	memset(myStruct, '\0', structSizeOf);
	memcpy(myStruct, buffer, structSizeOf); /*ojo que el memcopy si lo haces afuera el primer parametro tiene que tener &*/
	/* Por ejemplo si la estructua no fuera por referencia y fuera local, debes hacer asi:
	memcpy(&header, buffer, sizeof(header_t));*/

	//	printf("sock: %d --- largo: %d ---- ", sock, header->largo_mensaje);
	//	printf("tipo: %d\n", header->tipo);
	free(buffer);

	return EXITO;

}
int recibir_map_request_nodo(int sock, t_map_request_nodo* request, bool* seDesconecto)
{
	int ret;
	char *buffer = NULL;

	buffer = calloc(1, sizeof(t_map_request_nodo));
	*seDesconecto = false; /*False =0 define*/

	ret = recibir(sock, buffer, sizeof(t_map_request_nodo));

	if (ret == WARNING) {
		close(sock);
		*seDesconecto = true;
		free(buffer);
		return WARNING;
	}

	if (ret == ERROR) {
		free(buffer);
		return ERROR;
	}

	memcpy(request, buffer, sizeof(t_map_request_nodo));

	free(buffer);

	return EXITO;
}
Ejemplo n.º 17
0
main(int argc, char *argv[])
{
    char *optstring="RrTtV:v:";
    int c;

    opterr=0;
    while((c=getopt(argc, argv, optstring)) != EOF)
        switch(c) {
            case 'v':
            case 'V':
                debug=atoi(optarg);
                printf("Nivel de debugging: %d\n",debug);
                break;
            case ':': 
                printf("Falta valor numerico\n");
                exit(1);
                break;
            case 'R':
            case 'r':
                printf("Recibiendo\n");
                recibir(argv[optind]);
                break;
            case 'T':
            case 't':
                printf("Transmitiendo\n");
                transmitir(argv[optind]);
                break;
            case '?':
                printf("Mal argumento\n");
                break;
        }

}
bool IRsensor::recibido()
{
  if(recibir() < 8000)
  {
    return true;
  }
  return false;
}
Ejemplo n.º 19
0
void deletearBloque(int socket_FS,FILE* archivoAbierto){
	//fclose(ArchivoAbierto);
	int bloqueABorrar;
	recibir(socket_FS,&bloqueABorrar,sizeof(int));
	int offset = 20971520*bloqueABorrar;
	fseek(archivoAbierto,offset,SEEK_SET);

}
void recibir_datos(int fd, int pos_jugadores[][COORDENADAS], Direccion apunta[], bool jugador_caido[], TArma bala[][MAXAMO], int puntuacion[NJUGADORES]){
    char buffer[5];


    //Actualiza a los jugadores
    for(int jugador=0; jugador<NJUGADORES; jugador++){
	for(int pos=0; pos<COORDENADAS; pos++){
	    recibir(fd, buffer);
	    pos_jugadores[jugador][pos] = atoi(buffer);
	}
	recibir(fd, buffer);
	apunta[jugador] = (Direccion) atoi(buffer);
	recibir(fd, buffer);
	jugador_caido[jugador] = (bool) atoi(buffer);
	recibir(fd, buffer);
	puntuacion[jugador] = atoi(buffer);
    }

    //Actualiza las balas
    for(int jugador=0; jugador<NJUGADORES; jugador++)
	for(int n_bala=0; n_bala<MAXAMO; n_bala++){
	    recibir(fd, buffer);
	    bala[jugador][n_bala].se_mueve = atoi(buffer);
	    if(bala[jugador][n_bala].se_mueve){
		recibir(fd, buffer);
		bala[jugador][n_bala].col  = atoi(buffer);
		recibir(fd, buffer);
		bala[jugador][n_bala].fila = atoi(buffer);
	    }
	}

}
Ejemplo n.º 21
0
void leerEntradas()
{
	while (1)
	{
		fd_set nodosSelect;
		pthread_mutex_lock(&mNodos);
		nodosSelect = nodos;
		pthread_mutex_unlock(&mNodos);
		select(FD_SETSIZE, &nodosSelect, NULL, NULL, NULL);

		//Chequeo si salio del select por una nueva conexion
		if (FD_ISSET(desbloquearSelect[0], &nodosSelect))
		{
			char* dummy = malloc(1);
			int count = 1;
			while (count != 0)
			{
				read(desbloquearSelect[0], dummy, 1);
				ioctl(desbloquearSelect[0], FIONREAD, &count);
			}
			free(dummy);
		}

		//Chequeo los fd de las conexiones
		for (int i=0; i<conexiones->elements_count ;i++)
		{
			pthread_mutex_lock(&mConexiones);
			Conexion_t* conexion = list_get(conexiones,i);
			pthread_mutex_unlock(&mConexiones);
			if (conexion->sockfd < 0) continue;
			if (true != FD_ISSET(conexion->sockfd,&nodosSelect))
			{
				continue;
			}

			int estado;
			mensaje_t* mensaje = malloc(sizeof(mensaje_t));
			estado = recibir(conexion->sockfd, mensaje);
			if (estado == CONECTADO)
			{
				pthread_t tProcesar;
				argumentos_t* args = malloc(sizeof(argumentos_t));
				args->conexion = conexion;
				args->mensaje = mensaje;

				pthread_create(&tProcesar, NULL, procesarComandoRemoto, args);
				//ioctl(conexion->sockfd, FIONREAD, &count);
			} else
			{
				cerrarConexion(conexion);
				continue;
			}
		}
	}
}
Ejemplo n.º 22
0
int recibir_direccion(int socketfd, t_direccion *direccion)
{
	char buf[MENSAJE_MAXIMO+1];

	if (recibir(socketfd, buf) != 0)
		return -1;

	*direccion = t_direccion_crear_de_string(buf);

	return 0;
}
Ejemplo n.º 23
0
int esperar_respuesta(int socketfd, t_comando *respuesta)
{
	char buf[MENSAJE_MAXIMO+1];

	if (recibir(socketfd, buf) != 0)
		return -1;
	
	*respuesta = t_comando_crear_de_string(buf);
				
	return 0;
}
Ejemplo n.º 24
0
void recibirScript(int socketQueEscribe){
	char tipoScript;
	recibir(socketQueEscribe,&tipoScript,sizeof(char));

	char* identificador = malloc(15);
	identificador = string_itoa(socketQueEscribe);
	char* nombre = malloc(20);
	if(tipoScript=='m'){
		strcpy(nombre,"mapper.sh");
	}else{
		strcpy(nombre,"reducer.pl");
	}



	string_append(&identificador,nombre);


	/*FILE* archivo = fopen(identificador,"w");

	if(fchmod(fileno(archivo), 0755)==-1){
			printf("No se genero el permiso\n");
	}*/

	int fd_Archivo = creat(identificador,S_IRWXU);
	FILE* archivo = fdopen(fd_Archivo,"w");

	uint32_t longScript;
	recibir(socketQueEscribe,&longScript,sizeof(uint32_t));

	char* script = malloc(longScript);
	recibir(socketQueEscribe,script,longScript);

	fprintf(archivo,script);

	fclose(archivo);
	free(identificador);
	free(nombre);
	free(script);

}
void* _atiendo_hilo_conexion(void* conexion){

	loggear_trace("Nueva conexion establecida");

	while(1){

		char* msg;
		uint32_t len;
		// Recibimos la identificacion de la conexion
		recibir(conexion, &msg, &len);
		flag_t codop = codigo_operacion(msg);



		switch(codop){

		case CREA_UN_SEGMENTO:
			lock_mutex_pedido_msp();
			_atiendo_crear_segmento(conexion,msg);
			unlock_mutex_pedido_msp();
			break;

		case DESTRUI_SEGMENTO:
			lock_mutex_pedido_msp();
			_atiendo_destruir_segmento(conexion, msg);
			unlock_mutex_pedido_msp();
			break;

		case LEE_DE_MEMORIA:
			lock_mutex_pedido_msp();
			_atiendo_leer_memoria(conexion, msg);
			unlock_mutex_pedido_msp();
			break;

		case ESCRIBI_EN_MEMORIA:
			lock_mutex_pedido_msp();
			_atiendo_escribir_memoria(conexion, msg);
			unlock_mutex_pedido_msp();
			break;

		case DESCONEXION_CPU:
			loggear_trace("Finalizo una conexion");
			pthread_exit(NULL);
			break;

		default:
			break;
		}

	}
}
Ejemplo n.º 26
0
int reciveRSAkey(int sockfd, EVP_PKEY** pubKey){
	char* buffKey;
	int keylen = 0;

	if(sockfd <= 0 || pubKey== NULL || *pubKey == NULL)
		return 0;

	keylen = recibir(sockfd, &buffKey);
	if (keylen == -1)
		return 0;
	
	msgToRSApubKey(pubKey, buffKey, keylen);
	return 1;
}
Ejemplo n.º 27
0
void recibirOrdenMap(int socketQueEscribe){
	uint32_t nroBloqueDelNodo, longNombreEnDondeGuardarlo;
	recibir(socketQueEscribe,&nroBloqueDelNodo,sizeof(uint32_t));
	recibir(socketQueEscribe,&longNombreEnDondeGuardarlo,sizeof(uint32_t));
	char* nombreEnDondeGuardarlo = malloc(longNombreEnDondeGuardarlo);
	recibir(socketQueEscribe,nombreEnDondeGuardarlo,longNombreEnDondeGuardarlo);

	char* identificador = malloc(15);
	identificador = string_itoa(socketQueEscribe);
	char* nombre = "mapper.sh";
	char respuesta;
	//logearOrdenMap(nombre);
	string_append(&identificador,nombre);

	char* rutaEntrada = generarNombreRandom();

	respuesta = ejecutarMap(identificador,nombreEnDondeGuardarlo,nroBloqueDelNodo, rutaEntrada);

	enviarRespuestaDelMapAlJob(respuesta,socketQueEscribe);
	free(identificador);
	free(nombreEnDondeGuardarlo);
	remove(rutaEntrada);
}
Ejemplo n.º 28
0
void recibirBloque(int socket,char* nombre){
	FILE* archivo = fopen(nombre,"a");
	uint32_t longitud;
	recibir(socket, &longitud, sizeof(uint32_t));
	char* bloque = malloc(longitud);
	//memset(bloque,'\0',longitud);
	recibir(socket, bloque,longitud);

	/*char* a = "\n";
	char *contenido1 = malloc(longitud+5);
	contenido1 =strcat(bloque,a);
	free(bloque);
	fwrite(contenido1,longitud,1,archivo);


	free(contenido1);*/
	bloque[longitud] ='\n';
	fwrite(bloque,sizeof(char),longitud,archivo);
	free(bloque);

	//loguearEscrituraDeEspacioTemporal();
	fclose(archivo);

}
Ejemplo n.º 29
0
void Servidor::ejecutar(unsigned int repeticiones) {
    char filename[42], palabra[42], buffer[TAM_DGRAMA+1];
    for (int i = 0; i < repeticiones; ++i) {
        otro_descriptor = aceptar();
        recibir_n();
        for(int i = 0; i < n; ++i) {
            sprintf(filename, "%d.txt", i);
            archivos.push_back(Archivo(filename, O_RDONLY));
            recibir(TAM_DGRAMA, buffer);
            palabra_aleatoria(buffer, palabra);
            archivos.back().escribe(palabra, strlen(palabra));
            archivos.back().cerrar();
            close(otro_descriptor);
        }
    }
}
Ejemplo n.º 30
0
bool realizar_handshake(un_socket socket_del_servidor) {

	char * mensaje = malloc(18);
	mensaje = "Inicio autenticacion";

	enviar(socket_del_servidor, 1, 21, mensaje);

	t_paquete * resultado_del_handhsake = recibir(socket_del_servidor);

	bool resultado = string_equals_ignore_case(
			(char *) resultado_del_handhsake->data, "Autenticado");

	liberar_paquete(resultado_del_handhsake);

	return resultado;

}