/** * @brief igtCommunicationStack::igtCommunicationStack */ igtCommunicationStack::igtCommunicationStack(pissBaseDeDonnee* database){ this->igtClientCount = 0; int mode = 192; this->database = database; this->inputQueueManager = new igtInputQueueManager(); this->outputQueueManager = new igtOutputQueueManager(); this->datagramAnalyser = new igtDatagramAnalyser(database); this->serv = new igtServer(inputQueueManager); this->serv->setMode(mode); this->connect(this->serv, SIGNAL(localIPDetect(QString)), this, SLOT(getSelfIp(QString))); this->encodingTask = new igtEncodingTask(this->database, this->outputQueueManager, this->datagramAnalyser); this->decodingTask = new igtDecodingTask(this->database, inputQueueManager, this->datagramAnalyser); this->connect(this->datagramAnalyser, SIGNAL(newConnection(QString)), this, SLOT(receptConnection(QString))); this->connect(this->datagramAnalyser, SIGNAL(connectionConfirm()), this, SLOT(connectionEstablish())); }
int chunkserver_init(int argc, char *argv[]) { /* Set path of chunkserver */ chunk_path = (char*)malloc(sizeof(char)*(strlen(argv[1])+1)); if(chunk_path == NULL){ printf("%s: Failed to allocate memory\n",__func__); return -1; } strcpy(chunk_path,argv[1]); #ifdef DEBUG printf("path is %s\n", chunk_path); #endif char command[50]; sprintf(command, "rm -fr %s", chunk_path); system(command); mkdir(chunk_path, 0777); /* Set ip addr and port of master */ strcpy(master.ip_addr, argv[2]); master.port = MASTER_LISTEN; #ifdef DEBUG printf("Master ip address = %s port = %d\n", master.ip_addr, master.port); #endif /* Set heartbeat port of chunkserver */ heartbeat_port = atoi(argv[3]); #ifdef DEBUG printf("Chunkserver heartbeat port is %d\n", heartbeat_port); #endif /* Set ip addr of chunkserver */ // strcpy(chunkserver.ip_addr, argv[4]); getSelfIp(&chunkserver); #ifdef DEBUG printf("Chunkserver ip address = %s\n", chunkserver.ip_addr); #endif /* Set client port of chunkserver */ chunkserver.port = atoi(argv[4]); #ifdef DEBUG printf("Chunkserver client port is %d\n", chunkserver.port); #endif if((client_listen_socket = createSocket())==-1){ printf("%s: Failed to create socket\n",__func__); return -1; } if((bindSocket(client_listen_socket, chunkserver.port, chunkserver.ip_addr))==-1){ printf("%s: Failed bind to the port\n",__func__); return -1; } if((listenSocket(client_listen_socket))==-1){ printf("%s: Could not start the listener\n",__func__); return -1; } if((master_socket = createSocket())==-1){ printf("%s: Failed to create socket\n",__func__); return -1; } if((bindSocket(master_socket, heartbeat_port, chunkserver.ip_addr))==-1){ printf("%s: Failed bind to the port\n",__func__); return -1; } if(createConnection(master,master_socket)==-1){ printf("%s: Could not connect to the master\n",__func__); return -1; } pthread_mutex_init(&seq_mutex, NULL); //recv an ack //send IP and Port details return 0; }