From 8f7fb4fb3707c342634470a67aeea851f6f0fcca Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 16 Feb 2016 20:38:20 -0800 Subject: [PATCH] Handle wrapvFull when IOV_MAX is not defined. Summary:--Perhaps this should move to Portability.h instead. There is another instance of this in io/async/AsyncSocket.cpp.-- Added `portability/SysUio.h` to handle the c-macro conversion into a usable value. Reviewed By: yfeldblum Differential Revision: D2940778 fb-gh-sync-id: 897e44b430c02e5a7d826f3e8da9e4979b7b898c shipit-source-id: 897e44b430c02e5a7d826f3e8da9e4979b7b898c --- folly/Makefile.am | 1 + folly/detail/FileUtilDetail.h | 4 ++-- folly/io/async/AsyncSocket.cpp | 7 ++----- folly/portability/SysUio.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 folly/portability/SysUio.h diff --git a/folly/Makefile.am b/folly/Makefile.am index 1440a07b..87c984e2 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -263,6 +263,7 @@ nobase_follyinclude_HEADERS = \ PicoSpinLock.h \ Portability.h \ portability/Syscall.h \ + portability/SysUio.h \ ConditionallyExistent.h \ Preprocessor.h \ ProducerConsumerQueue.h \ diff --git a/folly/detail/FileUtilDetail.h b/folly/detail/FileUtilDetail.h index 50f120ff..11f06ae4 100644 --- a/folly/detail/FileUtilDetail.h +++ b/folly/detail/FileUtilDetail.h @@ -20,7 +20,7 @@ #include #include -#include +#include /** * Helper functions and templates for FileUtil.cpp. Declared here so @@ -76,7 +76,7 @@ ssize_t wrapvFull(F f, int fd, iovec* iov, int count, Offset... offset) { ssize_t totalBytes = 0; size_t r; do { - r = f(fd, iov, std::min(count, IOV_MAX), offset...); + r = f(fd, iov, std::min(count, kIovMax), offset...); if (r == (size_t)-1) { if (errno == EINTR) { continue; diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index 860e8835..92defa38 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1711,11 +1712,7 @@ ssize_t AsyncSocket::performWrite(const iovec* vec, msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = const_cast(vec); -#ifdef IOV_MAX // not defined on Android - msg.msg_iovlen = std::min(count, (uint32_t)IOV_MAX); -#else - msg.msg_iovlen = std::min(count, (uint32_t)UIO_MAXIOV); -#endif + msg.msg_iovlen = std::min(count, kIovMax); msg.msg_control = nullptr; msg.msg_controllen = 0; msg.msg_flags = 0; diff --git a/folly/portability/SysUio.h b/folly/portability/SysUio.h new file mode 100644 index 00000000..e0ab7f37 --- /dev/null +++ b/folly/portability/SysUio.h @@ -0,0 +1,31 @@ +/* + * Copyright 2016 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOLLY_SYSUIO_H_ +#define FOLLY_SYSUIO_H_ + +#include + +namespace folly { + +#ifdef IOV_MAX // not defined on Android +constexpr size_t kIovMax = IOV_MAX; +#else +constexpr size_t kIovMax = UIO_MAXIOV; +#endif +} + +#endif -- 2.34.1