mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-10 02:29:33 +00:00
Update error handling
This commit is contained in:
parent
b14ab0f084
commit
7fe4e1c9f5
|
@ -23,12 +23,16 @@ using namespace spdlog;
|
|||
using namespace scsi_defs;
|
||||
using namespace piscsi_interface;
|
||||
|
||||
void ScsiExecutor::Execute(const string& filename, bool binary)
|
||||
string ScsiExecutor::Execute(const string& filename, bool binary)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if (!binary) {
|
||||
ifstream in(filename);
|
||||
assert(!in.fail());
|
||||
if (in.fail()) {
|
||||
return "Error opening JSON input file '" + filename + "'";
|
||||
}
|
||||
|
||||
stringstream buf;
|
||||
buf << in.rdbuf();
|
||||
const string json = buf.str();
|
||||
|
@ -37,7 +41,10 @@ void ScsiExecutor::Execute(const string& filename, bool binary)
|
|||
}
|
||||
else {
|
||||
ifstream in(filename, ios::binary);
|
||||
assert(!in.fail());
|
||||
if (in.fail()) {
|
||||
return "Error opening binary input file '" + filename + "'";
|
||||
}
|
||||
|
||||
vector<char> b(file_size(filename));
|
||||
in.read(b.data(), b.size());
|
||||
memcpy(buffer.data(), b.data(), b.size());
|
||||
|
@ -48,15 +55,15 @@ void ScsiExecutor::Execute(const string& filename, bool binary)
|
|||
cdb[1] = binary ? 0x0a : 0x05;
|
||||
cdb[5] = static_cast<uint8_t>(size >> 8);
|
||||
cdb[6] = static_cast<uint8_t>(size);
|
||||
cdb[7] = static_cast<uint8_t>(65535 >> 8);
|
||||
cdb[8] = static_cast<uint8_t>(65535);
|
||||
phase_executor->Execute(scsi_command::eCmdExecute, cdb, buffer, 65535);
|
||||
cdb[7] = static_cast<uint8_t>(buffer.size() >> 8);
|
||||
cdb[8] = static_cast<uint8_t>(buffer.size());
|
||||
phase_executor->Execute(scsi_command::eCmdExecute, cdb, buffer, buffer.size());
|
||||
|
||||
const int length = phase_executor->GetSize();
|
||||
|
||||
if (!binary) {
|
||||
const string json((const char *)buffer.data(), length);
|
||||
spdlog::info("json received:\n" + json);
|
||||
const string json((const char*) buffer.data(), length);
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
PbResult result;
|
||||
|
@ -65,6 +72,6 @@ void ScsiExecutor::Execute(const string& filename, bool binary)
|
|||
}
|
||||
string json;
|
||||
google::protobuf::util::MessageToJsonString(result, &json);
|
||||
spdlog::info("json (converted from binary) received:\n" + json);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
}
|
||||
~ScsiExecutor() = default;
|
||||
|
||||
void Execute(const string&, bool);
|
||||
string Execute(const string&, bool);
|
||||
|
||||
void SetTarget(int id, int lun)
|
||||
{
|
||||
|
|
|
@ -156,7 +156,7 @@ int ScsiExec::run(span<char*> args, bool in_process)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
scsi_executor->Execute(filename, binary);
|
||||
cout << scsi_executor->Execute(filename, binary) << "\n" << flush;
|
||||
|
||||
CleanUp();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user