size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) {
struct iovec iov[] = {{&type, sizeof(type)},
{const_cast<uint8_t*>(data), length}};
ssize_t ret = 0;
do {
ret = TEMP_FAILURE_RETRY(writev(uart_fd_, iov, sizeof(iov) / sizeof(iov[0])));
} while (-1 == ret && EAGAIN == errno);
if (ret == -1) {
ALOGE("%s error writing to UART (%s)", __func__, strerror(errno));
} else if (ret < static_cast<ssize_t>(length + 1)) {
ALOGE("%s: %d / %d bytes written - something went wrong...", __func__,
static_cast<int>(ret), static_cast<int>(length + 1));
}
return ret;
}size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) {
std::vector<uint8_t> tmp;
tmp.reserve(1 + length);
tmp.push_back(type);
tmp.insert(tmp.end(), data, data + length);
return WriteSafely(uart_fd_, tmp.data(), tmp.size());
}
How can I get this (or a different appropriate fix) into the mainstream?
Thanks,
-Eric
Author: Peng Qi <removed - see commit for address> 2017-06-19 06:01:07Committer: Ting Zheng <removed - see commit for address> 2017-06-30 15:32:11Parent: 917efb1c0e2458434390463ca11bd9be935c2e54 (Bring multi-channel transport into the glorious new age)Child: 3e272a70763ff6191ac96d8560724e0a02f827ac (Bluetooth: Change CHECK() to LOG_ALWAYS_FATAL())Branches: remotes/m/laird-imx-p9.0.0_1.0.0-ga^{} and many more (86)Follows: android-o-preview-3Precedes: android-o-preview-4
BT HAL H4 write flow If to send type and data separately for one HCI packet, it will cause two system call context switch to kernel space, which will introduce software overhead on data path. Plus, if vendor does not use pure UART interface, it causes different data behavior on BUS and may not adapt to all vendors as legacy HAL did. Considering backward-compatibility, to use writev to send type and data together once as legacy BT HAL did. Test: H4 UTTest, BT VTS test, Bluetooth on/off Change-Id: I2d93085fe0c01b48d0e3729a3fa85b5b27335b2c
--------------------- bluetooth/1.0/default/h4_protocol.cc ---------------------