status handling update

This commit is contained in:
Uwe Seimet 2021-07-16 15:13:34 +02:00
parent 915c5b7924
commit 6dfdb1f077

View File

@ -38,7 +38,7 @@ BOOL SendCommand(char *buf)
if (connect(fd, (struct sockaddr *)&server, if (connect(fd, (struct sockaddr *)&server,
sizeof(struct sockaddr_in)) < 0) { sizeof(struct sockaddr_in)) < 0) {
fprintf(stderr, "Error : Can't connect to rascsi process\n"); fprintf(stderr, "Error : Can't connect to rascsi process\n");
return FALSE; return false;
} }
// Send the command // Send the command
@ -46,8 +46,10 @@ BOOL SendCommand(char *buf)
setvbuf(fp, NULL, _IONBF, 0); setvbuf(fp, NULL, _IONBF, 0);
fputs(buf, fp); fputs(buf, fp);
bool status = true;
// Receive the message // Receive the message
while (true) { while (status) {
int len; int len;
size_t res = fread(&len, sizeof(int), 1, fp); size_t res = fread(&len, sizeof(int), 1, fp);
if (res != 1) { if (res != 1) {
@ -62,14 +64,10 @@ BOOL SendCommand(char *buf)
rasctl_interface::CommandResult command_result; rasctl_interface::CommandResult command_result;
command_result.ParseFromString(msg); command_result.ParseFromString(msg);
cout << "Command terminated with status " << (command_result.status() ? "true" : "false") << ":" << endl; if (!command_result.status()) {
cout << command_result.msg(); cout << command_result.msg();
if (command_result.status()) { status = false;
fclose(fp);
close(fd);
return false;
} }
} }
@ -77,7 +75,7 @@ BOOL SendCommand(char *buf)
fclose(fp); fclose(fp);
close(fd); close(fd);
return TRUE; return status;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------