*place &= (~((1<<bitsleft)-1));
}
-size_t sendMsgWithOptions(int fd, const void* buffer, size_t len, const ComboAddress* dest, const ComboAddress* local, unsigned int localItf, int flags)
+size_t sendMsgWithOptions(int socketDesc, const void* buffer, size_t len, const ComboAddress* dest, const ComboAddress* local, unsigned int localItf, int flags)
{
msghdr msgh{};
iovec iov{};
memset(&msgh, 0, sizeof(msgh));
msgh.msg_control = nullptr;
msgh.msg_controllen = 0;
- if (dest) {
+ if (dest != nullptr) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-type-const-cast): it's the API
msgh.msg_name = reinterpret_cast<void*>(const_cast<ComboAddress*>(dest));
msgh.msg_namelen = dest->getSocklen();
msgh.msg_flags = 0;
- if (local && local->sin4.sin_family != 0) {
- addCMsgSrcAddr(&msgh, &cbuf, local, localItf);
+ if (local != nullptr && local->sin4.sin_family != 0) {
+ addCMsgSrcAddr(&msgh, &cbuf, local, static_cast<int>(localItf));
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast): it's the API
do {
#ifdef MSG_FASTOPEN
- if (flags & MSG_FASTOPEN && firstTry == false) {
+ if ((flags & MSG_FASTOPEN) != 0 && !firstTry) {
flags &= ~MSG_FASTOPEN;
}
#endif /* MSG_FASTOPEN */
- ssize_t res = sendmsg(fd, &msgh, flags);
+ ssize_t res = sendmsg(socketDesc, &msgh, flags);
if (res > 0) {
- size_t written = static_cast<size_t>(res);
+ auto written = static_cast<size_t>(res);
sent += written;
if (sent == len) {
firstTry = false;
#endif
iov.iov_len -= written;
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast): it's the API
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic): it's the API
iov.iov_base = reinterpret_cast<void*>(reinterpret_cast<char*>(iov.iov_base) + written);
}
else if (res == 0) {
if (err == EINTR) {
continue;
}
- else if (err == EAGAIN || err == EWOULDBLOCK || err == EINPROGRESS || err == ENOTCONN) {
+ if (err == EAGAIN || err == EWOULDBLOCK || err == EINPROGRESS || err == ENOTCONN) {
/* EINPROGRESS might happen with non blocking socket,
especially with TCP Fast Open */
return sent;
}
- else {
- unixDie("failed in sendMsgWithOptions");
- }
+ unixDie("failed in sendMsgWithOptions");
}
}
while (true);