diff options
| author | 2023-01-27 04:40:30 +0000 | |
|---|---|---|
| committer | 2023-01-27 04:40:30 +0000 | |
| commit | 44824755ab68cf0f991e7c80a71f75ad54a95ae2 (patch) | |
| tree | 36dd276f01e13e4a337b9532d93d4e65af9cea7c /src/inspsocket.cpp | |
| parent | Make reading the core config less of a mess. (diff) | |
Fix clamping the size of the IOVector array.
Casting then clamping might result in a weird size here so instead
clamp before casting.
Diffstat (limited to 'src/inspsocket.cpp')
| -rw-r--r-- | src/inspsocket.cpp | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index dbb4a790b..92bd064c1 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -212,7 +212,7 @@ ssize_t StreamSocket::ReadToRecvQ(std::string& rq) } /* Don't try to prepare huge blobs of data to send to a blocked socket */ -static constexpr int MYIOV_MAX = IOV_MAX < 128 ? IOV_MAX : 128; +static constexpr size_t MYIOV_MAX = std::min<size_t>(IOV_MAX, 128); void StreamSocket::DoWrite() { @@ -272,15 +272,8 @@ void StreamSocket::FlushSendQ(SendQueue& sq) int eventChange = FD_WANT_EDGE_WRITE; while (error.empty() && !sq.empty() && eventChange == FD_WANT_EDGE_WRITE) { - // Prepare a writev() call to write all buffers efficiently. This cast is - // safe as we clamp to MYIOV_MAX right away anyway. - int bufcount = static_cast<int>(sq.size()); - - // cap the number of buffers at MYIOV_MAX - if (bufcount > MYIOV_MAX) - { - bufcount = MYIOV_MAX; - } + // Prepare a writev() call to write all buffers efficiently. + int bufcount = static_cast<int>(std::min<size_t>(sq.size(), MYIOV_MAX)); int rv_max = 0; ssize_t rv; |
