mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-12-04 05:43:39 +00:00
enlarge buffer size and debug buffer write error
Signed-off-by: blueyouh <bailiang18@huawei.com> Change-Id: I18346597880f3bfe26229c9f308b712552eb5286
This commit is contained in:
parent
f14f48f656
commit
19c1a485ae
@ -136,7 +136,10 @@ int32_t DSoftbusAdapterImpl::SendPacket(const std::string &networkId, NetPacket
|
||||
return RET_ERR;
|
||||
}
|
||||
StreamBuffer buffer;
|
||||
packet.MakeData(buffer);
|
||||
if (!packet.MakeData(buffer)) {
|
||||
FI_HILOGE("Failed to buffer packet");
|
||||
return RET_ERR;
|
||||
}
|
||||
if (buffer.Size() > MAX_PACKET_BUF_SIZE) {
|
||||
FI_HILOGE("Packet is too large");
|
||||
return RET_ERR;
|
||||
@ -403,6 +406,8 @@ void DSoftbusAdapterImpl::HandleSessionData(const std::string &networkId, Circle
|
||||
break;
|
||||
}
|
||||
if ((head->size + static_cast<int32_t>(sizeof(PackHead))) > circleBuffer.ResidualSize()) {
|
||||
FI_HILOGI("Incomplete package, package size:%{public}d, residual size:%{public}d",
|
||||
(head->size + static_cast<int32_t>(sizeof(PackHead))), circleBuffer.ResidualSize());
|
||||
break;
|
||||
}
|
||||
NetPacket packet(head->idMsg);
|
||||
|
@ -48,7 +48,10 @@ bool SocketSession::SendMsg(NetPacket &pkt) const
|
||||
return false;
|
||||
}
|
||||
StreamBuffer buf;
|
||||
pkt.MakeData(buf);
|
||||
if (!pkt.MakeData(buf)) {
|
||||
FI_HILOGE("Failed to buffer packet");
|
||||
return false;
|
||||
}
|
||||
return SendMsg(buf.Data(), buf.Size());
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ inline constexpr int32_t MAX_VECTOR_SIZE { 10 };
|
||||
inline constexpr int32_t MEM_OUT_OF_BOUNDS { 3 };
|
||||
inline constexpr int32_t MEMCPY_SEC_FUN_FAIL { 4 };
|
||||
inline constexpr int32_t PARAM_INPUT_INVALID { 5 };
|
||||
inline constexpr int32_t MAX_STREAM_BUF_SIZE { 256 };
|
||||
inline constexpr size_t MAX_PACKET_BUF_SIZE { 256 };
|
||||
inline constexpr int32_t MAX_STREAM_BUF_SIZE { 1024 };
|
||||
inline constexpr size_t MAX_PACKET_BUF_SIZE { MAX_STREAM_BUF_SIZE };
|
||||
inline constexpr int32_t ONCE_PROCESS_NETPACKET_LIMIT { 100 };
|
||||
inline constexpr int32_t INVALID_FD { 6 };
|
||||
inline constexpr int32_t INVALID_PID { 7 };
|
||||
|
@ -31,15 +31,15 @@ using PACKHEAD = struct PackHead {
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
class NetPacket : public StreamBuffer {
|
||||
class NetPacket final : public StreamBuffer {
|
||||
public:
|
||||
explicit NetPacket(MessageId msgId);
|
||||
NetPacket(const NetPacket &pkt);
|
||||
NetPacket &operator = (const NetPacket &pkt);
|
||||
DISALLOW_MOVE(NetPacket);
|
||||
virtual ~NetPacket();
|
||||
~NetPacket();
|
||||
|
||||
virtual void MakeData(StreamBuffer &buf) const;
|
||||
bool MakeData(StreamBuffer &buf) const;
|
||||
int32_t GetPacketLength() const
|
||||
{
|
||||
return (static_cast<int32_t>(sizeof(PackHead)) + wPos_);
|
||||
|
@ -25,16 +25,17 @@ NetPacket::NetPacket(const NetPacket &pkt) : NetPacket(pkt.GetMsgId())
|
||||
}
|
||||
NetPacket::~NetPacket() {}
|
||||
|
||||
void NetPacket::MakeData(StreamBuffer &buf) const
|
||||
bool NetPacket::MakeData(StreamBuffer &buf) const
|
||||
{
|
||||
PACKHEAD head = {msgId_, wPos_};
|
||||
buf << head;
|
||||
if (wPos_ > 0) {
|
||||
if (!buf.Write(&szBuff_[0], wPos_)) {
|
||||
FI_HILOGE("Write data to stream failed, errCode:%{public}d", STREAM_BUF_WRITE_FAIL);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -93,7 +93,10 @@ bool StreamClient::SendMsg(const NetPacket &pkt) const
|
||||
return false;
|
||||
}
|
||||
StreamBuffer buf;
|
||||
pkt.MakeData(buf);
|
||||
if (!pkt.MakeData(buf)) {
|
||||
FI_HILOGE("Failed to buffer packet");
|
||||
return false;
|
||||
}
|
||||
return SendMsg(buf.Data(), buf.Size());
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,10 @@ bool StreamSession::SendMsg(NetPacket &pkt) const
|
||||
return false;
|
||||
}
|
||||
StreamBuffer buf;
|
||||
pkt.MakeData(buf);
|
||||
if (!pkt.MakeData(buf)) {
|
||||
FI_HILOGE("Failed to buffer packet");
|
||||
return false;
|
||||
}
|
||||
return SendMsg(buf.Data(), buf.Size());
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
|
Loading…
Reference in New Issue
Block a user