Fix writev on Windows.
This commit is contained in:
parent
84194768ae
commit
6285d98479
@ -36,6 +36,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <limits>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TD_PORT_WINDOWS && defined(WIN32_LEAN_AND_MEAN)
|
#if TD_PORT_WINDOWS && defined(WIN32_LEAN_AND_MEAN)
|
||||||
@ -271,9 +273,16 @@ Result<size_t> FileFd::writev(Span<IoSlice> slices) {
|
|||||||
return OS_ERROR(PSLICE() << "Writev to " << get_native_fd() << " has failed");
|
return OS_ERROR(PSLICE() << "Writev to " << get_native_fd() << " has failed");
|
||||||
#else
|
#else
|
||||||
size_t res = 0;
|
size_t res = 0;
|
||||||
for (auto slice : slices) {
|
for (const auto &slice : slices) {
|
||||||
|
if (slice.size() > std::numeric_limits<size_t>::max() - res) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
TRY_RESULT(size, write(slice));
|
TRY_RESULT(size, write(slice));
|
||||||
res += size;
|
res += size;
|
||||||
|
if (size != slice.size()) {
|
||||||
|
CHECK(size < slice.size());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,7 +25,7 @@ inline IoSlice as_io_slice(Slice slice) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Slice as_slice(const IoSlice io_slice) {
|
inline Slice as_slice(const IoSlice &io_slice) {
|
||||||
return Slice(static_cast<const char *>(io_slice.iov_base), io_slice.iov_len);
|
return Slice(static_cast<const char *>(io_slice.iov_base), io_slice.iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <limits>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@ -98,7 +100,9 @@ class SocketFdImpl : private Iocp::Callback {
|
|||||||
Result<size_t> writev(Span<IoSlice> slices) {
|
Result<size_t> writev(Span<IoSlice> slices) {
|
||||||
size_t total_size = 0;
|
size_t total_size = 0;
|
||||||
for (auto io_slice : slices) {
|
for (auto io_slice : slices) {
|
||||||
total_size += as_slice(io_slice).size();
|
auto size = as_slice(io_slice).size();
|
||||||
|
CHECK(size <= std::numeric_limits<size_t>::max() - total_size);
|
||||||
|
total_size += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto left_size = total_size;
|
auto left_size = total_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user