blob: d1e4dc74b3d2d88e307d4a386556e686968e403f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include "bt.hpp"
#include <cstdint>
#include <ipmiblob/blob_errors.hpp>
#include <vector>
namespace host_tool
{
bool BtDataHandler::sendContents(const std::string& input,
std::uint16_t session)
{
int inputFd = sys->open(input.c_str(), 0);
if (inputFd < 0)
{
return false;
}
std::int64_t fileSize = sys->getSize(input.c_str());
if (fileSize == 0)
{
std::fprintf(stderr, "Zero-length file, or other file access error\n");
return false;
}
progress->start(fileSize);
try
{
static constexpr int btBufferLen = 50;
std::uint8_t readBuffer[btBufferLen];
int bytesRead;
std::uint32_t offset = 0;
do
{
bytesRead = sys->read(inputFd, readBuffer, sizeof(readBuffer));
if (bytesRead > 0)
{
/* minorly awkward repackaging. */
std::vector<std::uint8_t> buffer(&readBuffer[0],
&readBuffer[bytesRead]);
blob->writeBytes(session, offset, buffer);
offset += bytesRead;
progress->updateProgress(bytesRead);
}
} while (bytesRead > 0);
}
catch (const ipmiblob::BlobException& b)
{
sys->close(inputFd);
return false;
}
sys->close(inputFd);
return true;
}
} // namespace host_tool
|