Make stream_descriptor not a pointer
There's no reason to avoid initing a stream descriptor, when internally
it has an is_open() state.
Change-Id: If9c4f41fc8293eb2c5cc7ef0daea3fdbc727c1b7
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/ssifbridged.cpp b/ssifbridged.cpp
index 2752102..d35f744 100644
--- a/ssifbridged.cpp
+++ b/ssifbridged.cpp
@@ -73,13 +73,13 @@
int numberOfReqNotRsp);
bool initOK() const
{
- return !!dev;
+ return dev.is_open();
}
void channelAbort(const char* msg, const boost::system::error_code& ec);
void async_read();
void processMessage(const boost::system::error_code& ecRd, size_t rlen);
int showNumOfReqNotRsp();
- std::unique_ptr<boost::asio::posix::stream_descriptor> dev = nullptr;
+ boost::asio::posix::stream_descriptor dev;
protected:
std::array<uint8_t, ssifMessageSize> xferBuffer;
@@ -102,8 +102,8 @@
std::shared_ptr<sdbusplus::asio::connection>& bus,
const std::string& device, bool verbose,
int numberOfReqNotRsp) :
- io(io),
- bus(bus), verbose(verbose), numberOfReqNotRsp(numberOfReqNotRsp),
+ dev(*io),
+ io(io), bus(bus), verbose(verbose), numberOfReqNotRsp(numberOfReqNotRsp),
rspTimer(*io)
{
std::string devName = devBase;
@@ -124,7 +124,7 @@
}
else
{
- dev = std::make_unique<boost::asio::posix::stream_descriptor>(*io, fd);
+ dev.assign(fd);
}
async_read();
@@ -146,7 +146,7 @@
void SsifChannel::async_read()
{
- boost::asio::async_read(*dev,
+ boost::asio::async_read(dev,
boost::asio::buffer(xferBuffer, xferBuffer.size()),
boost::asio::transfer_at_least(2),
[this](const boost::system::error_code& ec,
@@ -189,8 +189,8 @@
boost::system::error_code ecWr;
- size_t wlen = boost::asio::write(*(ssifchannel->dev),
- boost::asio::buffer(rsp), ecWr);
+ size_t wlen = boost::asio::write(ssifchannel->dev, boost::asio::buffer(rsp),
+ ecWr);
if (ecWr || wlen != rsp.size())
{
msgToLog =
@@ -346,7 +346,7 @@
log<level::INFO>(msgToLog.c_str());
}
boost::system::error_code ecWr;
- size_t wlen = boost::asio::write(*dev, boost::asio::buffer(rsp), ecWr);
+ size_t wlen = boost::asio::write(dev, boost::asio::buffer(rsp), ecWr);
if (ecWr || wlen != rsp.size())
{
std::string msgToLog =