void Server::EnviarDatos(vector<string> &vector) { stringstream ss; string str_tamanyo; /*Convertimos el numero de posiciones que tiene el vector que pasamos como parametro de entrada a string para poder enviarlo al cliente.*/ ss << vector.size(); str_tamanyo = ss.str(); //Enviamos el tamanyo y si podemos enviar el tamanyo enviamos el vector. if (write(client_sock, str_tamanyo.c_str(), strlen(str_tamanyo.c_str())) > 0) { for (unsigned int i = 0; i < vector.size(); i++) { if (GetReady()) { if (write(client_sock, vector[i].c_str(), strlen(vector[i].c_str())) < 0) cout << "Error en la transferencia" << endl; } } //El servidor espera un ok todavia del ultimo elemento. GetReady(); } else cout << "Error en la transferencia" << endl; }
int main(int argc, char *argv[]) { pid_t pid; /* do some ready work before start the distributed system */ GetReady(); if ((pid = fork()) < 0) { printf("fork error\n"); } else if(pid == 0) { int i; /* storage process */ InitStorage(); ExitSys(); printf("storage process finished.\n"); } else { /* transaction process */ InitTransaction(); dataLoading(); /* wait other slave nodes until all of them have loaded data. */ WaitDataReady(); /* begin run the benchmark. */ RunTerminals(THREADNUM); printf("transaction process finished.\n"); } return 0; }
void Server::EnviarDatos(string mensaje) { if (write(client_sock, mensaje.c_str(), strlen(mensaje.c_str())) < 0) cout << "Error en la transferencia"; else GetReady(); }
void Server::SerializarObjeto(vector<Archivo> &vector) { char data[1000]; string str_num_elementos; int inum_elementos = vector.size(); str_num_elementos = UtilidadesTipos::IntToString(inum_elementos); for (unsigned int i = 0; i < str_num_elementos.length(); i++) data[i] = str_num_elementos[i]; write(client_sock, data, strlen(data)); GetReady(); for (unsigned int i = 0; i < vector.size(); i++) { //Enviamos el nombre UtilidadesTipos::StringToArray(vector[i].get_nombre(), data); write(client_sock, data, strlen(data)); GetReady(); //Vaciamos el array bzero(data, 1000); //Enviamos la ruta UtilidadesTipos::StringToArray(vector[i].get_ruta(), data); write(client_sock, data, strlen(data)); GetReady(); //Vaciamos el array bzero(data, 1000); UtilidadesTipos::StringToArray(vector[i].get_tipo(), data); write(client_sock, data, strlen(data)); GetReady(); //Vaciamos el array bzero(data, 1000); UtilidadesTipos::LongToArray(vector[i].get_tamanyo(), data); write(client_sock, data, strlen(data)); bzero(data, 1000); GetReady(); } }
//================================================================================================== bool Solver::MakeEntireSolutionSequence( const RubiksCube* rubiksCube, RubiksCube::RotationSequence& rotationSequence ) { if( !GetReady() ) return false; // I don't plan to support solving a bandaged cube...not sure how to do it. rubiksCube->EnforceBandaging( false ); wxScopedPtr< RubiksCube > rubiksCubeCopy; rubiksCubeCopy.reset( new RubiksCube( rubiksCube->SubCubeMatrixSize() ) ); if( !rubiksCubeCopy->Copy( *rubiksCube, RubiksCube::CopyMap ) ) return false; RubiksCube::RotationSequence subRotationSequence; int maxSequenceLength = 99999999; //70 * rubiksCube->SubCubeMatrixSize(); rotationSequence.clear(); while( signed( rotationSequence.size() ) <= maxSequenceLength ) { subRotationSequence.clear(); if( !MakeRotationSequence( rubiksCubeCopy.get(), subRotationSequence ) ) return false; if( subRotationSequence.size() == 0 ) break; else { RubiksCube::CompressRotationSequence( subRotationSequence ); rubiksCubeCopy->ApplySequence( subRotationSequence ); rotationSequence.insert( rotationSequence.end(), subRotationSequence.begin(), subRotationSequence.end() ); } } if( signed( rotationSequence.size() ) > maxSequenceLength ) { rotationSequence.clear(); return false; } // Now compress across the entire solution sequence. RubiksCube::CompressRotationSequence( rotationSequence ); bool solved = rubiksCubeCopy->IsInSolvedState(); //wxASSERT( solved ); return true; }
void Server::EnviarArchivo(string path) { char *data = new char[1024]; ifstream file; struct stat filestatus; unsigned long long tamanyo_fichero, tamanyo_restante; string nombre_fichero; //tamanyo del fichero stat(path.c_str() , &filestatus ); tamanyo_fichero = filestatus.st_size; tamanyo_restante = tamanyo_fichero; //Abrimos el fichero file.open(path.c_str(), ios::binary); //Si hemos podido abrir el fichero, empezamos a leerlo y mandarlo if (file) { //Enviamos el nombre del fichero. nombre_fichero = ObtenerNombreFichero(path); write(client_sock, nombre_fichero.c_str(), sizeof(nombre_fichero.c_str())); GetReady(); //Leemos el archivo y lo enviamos. while (file.read(data, 1024)) { write(client_sock, data, 1024); tamanyo_restante -= 1024; //GetReady(); } cout << tamanyo_restante << endl; write(client_sock, data, tamanyo_restante); //GetReady(); cout << "enviado" << endl; file.close(); } }
int main(int argc, char *argv[]) { pid_t pid; GetReady(); if ((pid = fork()) < 0) { printf("fork error\n"); } else if(pid == 0) { /* shmget the shared memory address*/ BindShmem(); InitStorage(); printf("storage process finished.\n"); } else { InitTransaction(); /* load the benchmark data */ dataLoading(); /* wait other nodes in the distributed system prepare the data */ WaitDataReady(); /* run the benchmark */ RunTerminals(THREADNUM); printf("transaction process finished.\n"); } return 0; }