diff --git a/inc/Utils.h b/inc/Utils.h index a7947a99632bd5a4b52263a00669d25801cb0162..6c552a1c4365e79dc0e09c18780fcb8911384899 100644 --- a/inc/Utils.h +++ b/inc/Utils.h @@ -10,6 +10,7 @@ #include <stdio.h> #include <stdio.h> #include <string.h> +#include <unistd.h> #include <sys/socket.h> #include <sys/wait.h> #include <arpa/inet.h> diff --git a/src/Node.cpp b/src/Node.cpp index 0b770bf289a2a8485ecad10c66dd9a55b4600f65..e0237f1d4a11a5bb69c10b738704500d1bf9cf8b 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -882,7 +882,7 @@ void Node::handleTcpMessage() case CHUNKACK: { cout << "[CHUNKACK] receiving the put worked!" << endl; - //IP, exec, start, temp, actual file, prefix + //IP, exec, start, temp, actual file if (!isLeader) { //forward to know that the file was put okay this->tcpServent->sendMessage(leaderIP, TCPPORT, msg.toString()); @@ -896,22 +896,25 @@ void Node::handleTcpMessage() fprintf (stderr, "Fork failed.\n"); break; } else { //child process close(dataPipe[0]); + cout << "[CHUNKACK] processing " << inMsg[3] << endl; dup2(dataPipe[1], 1); //stdout -> write end of pipe string execName = "./" + inMsg[4]; int status = execl(execName.c_str(),execName.c_str(),inMsg[3].c_str(),NULL); if (status < 0) exit(status); } + int status; + waitpid(pid, &status, 0); close(dataPipe[0]);close(dataPipe[1]); //go thorugh and process things from datapipe //if processing success, send out TCP MAPLEACK - string match = "tmp-" + inMsg[5]; + string match = "tmp-" + sdfsPre; int matchLen = match.size(); struct dirent *entry = nullptr; DIR *dp = nullptr; - if ((dp = opendir(".")) == nullptr) { cout << "tmp directory error " << match << endl; break; } + if ((dp = opendir(".")) == nullptr) { cout << "tmp directory error " << sdfsPre << endl; break; } while ((entry = readdir(dp))){ - cout << "[FILES] found " << entry->d_name << " looking to match " << to_string(matchLen) << " chars from " << match << endl; - if (strncmp(entry->d_name, match.c_str(), matchLen) == 0){ + //cout << "[FILES] found " << entry->d_name << " looking to match " << to_string(matchLen) << " chars from " << sdfsPre << endl; + if (strncmp(entry->d_name, sdfsPre.c_str(), matchLen) == 0){ string searcher(entry->d_name); string target = searcher.substr(4); cout << "[CHUNKACK] found " << entry->d_name << endl; diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index 1a454828d2fdc1204efdcbe3d4d3f43742121fd8..82fd73a8004cc1b77ade03147ee874903922d941 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -136,7 +136,8 @@ void TcpSocket::sendLines(string ip, string port, string execfile, string readfi int sockfd = 0, lineCounter = -1; if ((sockfd = createConnection(ip, port)) == -1) return; //exec, read, start, tmp, prefix - string toSend = execfile + "," + readfile + "," + to_string(start) + "," + readfile + to_string(start) + "temp" + "," + prefix; + vector<string> unDirectory = splitString(readfile, "-"); + string toSend = execfile + "," + readfile + "," + to_string(start) + "," + prefix+"-tmp"+to_string(start)+"-"+unDirectory[1]; Messages msg(PUT, toSend); string payload = msg.toString(); if (send(sockfd, payload.c_str(), strlen(payload.c_str()), 0) == -1) { @@ -240,7 +241,6 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP sdfsfilename = fields[0]; //exec file name start = stoi(fields[2]); //start line (used just for signalling what work finished to master) remoteLocalname = fields[1]; //actual file (used for signalling) - prefix = fields[4]; } fp = fopen(localfilename.c_str(), mode.c_str()); if (fp == NULL) { @@ -267,8 +267,8 @@ int TcpSocket::messageHandler(int sockfd, string payloadMessage, string returnIP // TODO: Handel file corruption here } else { if (start != -1){ - //IP, exec, start, temp, actual file, prefix - Messages putack(CHUNKACK, returnIP + "::" + sdfsfilename + "::" + to_string(start) + "::" + localfilename + "::" + remoteLocalname + "::" + prefix); + //IP, exec, start, temp, actual file + Messages putack(CHUNKACK, returnIP + "::" + sdfsfilename + "::" + to_string(start) + "::" + localfilename + "::" + remoteLocalname); regMessages.push(putack.toString()); } else { Messages putack(PUTACK, returnIP + "::" + sdfsfilename + "::" + localfilename+"::"+remoteLocalname); diff --git a/src/Utils.cpp b/src/Utils.cpp index 82c072bea07646d3877c23d99a14fc0b4f07119a..702d3b99a69c61c83d85d2bb8a407f02e441ef89 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -51,6 +51,8 @@ bool isInVector(vector<int> v, int i){ void handlePipe(int file, string prefix) { size_t bufSize = 1024; + cout << "[PIPE] sleeping for data " << endl; + sleep(5); FILE *stream = fdopen(file, "r"); FILE *tmp; char str[bufSize]; const char * delim = ",";