mirror of
https://gitee.com/openharmony/sensors_sensor
synced 2024-12-04 04:31:52 +00:00
!654 【泛Sensor】【sensor】修改客户端fd关闭后recv问题
Merge pull request !654 from lixiangpeng5/master2
This commit is contained in:
commit
116918b2bf
@ -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<int32_t>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ HWTEST_F(SensorBasicDataChannelTest, SensorBasicDataChannelTest_001, TestSize.Le
|
||||
ASSERT_EQ(ret, ERR_OK);
|
||||
|
||||
ret = sensorChannel.ReceiveData(static_cast<void *>(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<void *>(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<void *>(buff1), sizeof(buff1));
|
||||
ASSERT_EQ(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR);
|
||||
ASSERT_EQ(ret, ERROR);
|
||||
|
||||
sensorChannel.DestroySensorBasicChannel();
|
||||
}
|
||||
|
@ -172,13 +172,10 @@ int32_t SensorBasicDataChannel::ReceiveData(void *vaddr, size_t size)
|
||||
std::unique_lock<std::mutex> 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<int32_t>(length);
|
||||
}
|
||||
|
||||
int32_t SensorBasicDataChannel::GetSendDataFd()
|
||||
|
Loading…
Reference in New Issue
Block a user