diff --git a/frameworks/native/src/sensor_file_descriptor_listener.cpp b/frameworks/native/src/sensor_file_descriptor_listener.cpp index e3e0c9c9..b55f13af 100644 --- a/frameworks/native/src/sensor_file_descriptor_listener.cpp +++ b/frameworks/native/src/sensor_file_descriptor_listener.cpp @@ -57,8 +57,7 @@ void SensorFileDescriptorListener::OnReadable(int32_t fileDescriptor) SEN_HILOGE("Receive data buff_ is null"); return; } - int32_t len = - recv(fileDescriptor, receiveDataBuff_, sizeof(SensorData) * RECEIVE_DATA_SIZE, 0); + int32_t len = channel_->ReceiveData(receiveDataBuff_, sizeof(SensorData) * RECEIVE_DATA_SIZE); int32_t eventSize = static_cast(sizeof(SensorData)); while (len > 0) { int32_t num = len / eventSize; @@ -74,7 +73,7 @@ void SensorFileDescriptorListener::OnReadable(int32_t fileDescriptor) }; channel_->dataCB_(&event, 1, channel_->privateData_); } - len = recv(fileDescriptor, receiveDataBuff_, sizeof(SensorData) * RECEIVE_DATA_SIZE, 0); + len = channel_->ReceiveData(receiveDataBuff_, sizeof(SensorData) * RECEIVE_DATA_SIZE); } } diff --git a/test/unittest/coverage/sensor_basic_data_channel_test.cpp b/test/unittest/coverage/sensor_basic_data_channel_test.cpp index 53cd8ed1..04ad39f3 100644 --- a/test/unittest/coverage/sensor_basic_data_channel_test.cpp +++ b/test/unittest/coverage/sensor_basic_data_channel_test.cpp @@ -70,7 +70,7 @@ HWTEST_F(SensorBasicDataChannelTest, SensorBasicDataChannelTest_001, TestSize.Le ASSERT_EQ(ret, ERR_OK); ret = sensorChannel.ReceiveData(static_cast(buff), sizeof(buff)); - ASSERT_NE(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR); + ASSERT_NE(ret, ERROR); sensorChannel.DestroySensorBasicChannel(); } @@ -135,12 +135,12 @@ HWTEST_F(SensorBasicDataChannelTest, ReceiveData_001, TestSize.Level1) SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); char buff[128] = {}; int32_t ret = sensorChannel.ReceiveData(static_cast(buff), sizeof(buff)); - ASSERT_EQ(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR); + ASSERT_EQ(ret, ERROR); sensorChannel.CreateSensorBasicChannel(); char *buff1 = nullptr; ret = sensorChannel.ReceiveData(static_cast(buff1), sizeof(buff1)); - ASSERT_EQ(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR); + ASSERT_EQ(ret, ERROR); sensorChannel.DestroySensorBasicChannel(); } diff --git a/utils/common/src/sensor_basic_data_channel.cpp b/utils/common/src/sensor_basic_data_channel.cpp index d95a28c5..4a4a1c2f 100644 --- a/utils/common/src/sensor_basic_data_channel.cpp +++ b/utils/common/src/sensor_basic_data_channel.cpp @@ -172,13 +172,10 @@ int32_t SensorBasicDataChannel::ReceiveData(void *vaddr, size_t size) std::unique_lock lock(fdLock_); if ((vaddr == nullptr) || (receiveFd_ < 0)) { SEN_HILOGE("Failed, vaddr is null or receiveFd_ invalid"); - return SENSOR_CHANNEL_RECEIVE_ADDR_ERR; + return ERROR; } - ssize_t length; - do { - length = recv(receiveFd_, vaddr, size, MSG_DONTWAIT); - } while (errno == EINTR); - return length; + ssize_t length = recv(receiveFd_, vaddr, size, 0); + return static_cast(length); } int32_t SensorBasicDataChannel::GetSendDataFd()