Skip to content
Snippets Groups Projects
Commit 9b2b6ad8 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Created printErrors function

parent 4cb1f2ba
Branches lento
No related tags found
1 merge request!1Lento
...@@ -14,6 +14,16 @@ double timestamp(void) { ...@@ -14,6 +14,16 @@ double timestamp(void) {
return ((double)(tp.tv_sec + tp.tv_usec/1000000.0)); return ((double)(tp.tv_sec + tp.tv_usec/1000000.0));
} }
void printErrors(char error){
if(error == DIR_ERR){
cout << "Arquivo ou diretório inexistente."<<endl;
}else if(error == PERM_ERR){
cout << "Você não tem permissão."<<endl;
}else if(error == SPACE_ERR){
cout << "Espaço insuficiente no disco."<<endl;
}
}
vector<Message> Protocol::getMessages(){ vector<Message> Protocol::getMessages(){
return messages; return messages;
} }
...@@ -221,7 +231,8 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){ ...@@ -221,7 +231,8 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){
nextSequence = (messages.back().sequence.to_ulong()+1)%(MAXSIZE+1); nextSequence = (messages.back().sequence.to_ulong()+1)%(MAXSIZE+1);
} }
} else if(status == ERROR) { } else if(status == ERROR) {
cout << "ERROR: " << messages.back().getDataAsString() << endl; cout << "ERROR: ";
printErrors(messages.back().data[0]);
return -1; return -1;
} }
}while(status != end); }while(status != end);
......
...@@ -45,7 +45,7 @@ int main(){ ...@@ -45,7 +45,7 @@ int main(){
args = line.substr(pos+1, line.size()); args = line.substr(pos+1, line.size());
if(fexists(args)) { if(fexists(args)) {
string size = to_string(filesize(args)); string size = to_string(filesize(args));
cout << "ARQUIVO: " << args << "|\tTAMANHO:" << size << endl; // cout << "ARQUIVO: " << args << "|\tTAMANHO:" << size << endl;
sendProtocol.setData(vector<BYTE>(args.begin(), args.end()), PUT); sendProtocol.setData(vector<BYTE>(args.begin(), args.end()), PUT);
sendProtocol.sendMessage(sockt, 0); sendProtocol.sendMessage(sockt, 0);
int error = receiveProtocol.receive(sockt, OK, WAIT_STOP, false); int error = receiveProtocol.receive(sockt, OK, WAIT_STOP, false);
......
...@@ -59,7 +59,7 @@ bool hasEnoughSpace(int size){ ...@@ -59,7 +59,7 @@ bool hasEnoughSpace(int size){
void writeFile(string path, vector<BYTE>data){ void writeFile(string path, vector<BYTE>data){
cout << "path: "<< path<<endl; // cout << "path: "<< path<<endl;
string strData(data.begin(), data.end()); string strData(data.begin(), data.end());
ofstream file(path); ofstream file(path);
if (file.is_open()){ if (file.is_open()){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment