Handle wrapvFull when IOV_MAX is not defined.
authorMichael Lee <mzlee@fb.com>
Wed, 17 Feb 2016 04:38:20 +0000 (20:38 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 17 Feb 2016 05:20:27 +0000 (21:20 -0800)
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
folly/detail/FileUtilDetail.h
folly/io/async/AsyncSocket.cpp
folly/portability/SysUio.h [new file with mode: 0644]

index 1440a07b856739adbc11de7366b9b0e0a72e051f..87c984e2f54ae9843c848b9acacf52d5ceaafd8d 100644 (file)
@@ -263,6 +263,7 @@ nobase_follyinclude_HEADERS = \
        PicoSpinLock.h \
        Portability.h \
        portability/Syscall.h \
+       portability/SysUio.h \
        ConditionallyExistent.h \
        Preprocessor.h \
        ProducerConsumerQueue.h \
index 50f120ffb70a62bd432081cb21e20c2928473325..11f06ae474e0b4010a84052ea36d8fd746919b9a 100644 (file)
@@ -20,7 +20,7 @@
 #include <cerrno>
 #include <unistd.h>
 
-#include <sys/uio.h>
+#include <folly/portability/SysUio.h>
 
 /**
  * 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<int>(count, kIovMax), offset...);
     if (r == (size_t)-1) {
       if (errno == EINTR) {
         continue;
index 860e8835f55877718044fa9f5312be82d73f77fb..92defa38bce7205e0e3dbe8b076dedd75d1b5ad7 100644 (file)
@@ -20,6 +20,7 @@
 #include <folly/io/async/EventHandler.h>
 #include <folly/SocketAddress.h>
 #include <folly/io/IOBuf.h>
+#include <folly/portability/SysUio.h>
 
 #include <poll.h>
 #include <errno.h>
@@ -1711,11 +1712,7 @@ ssize_t AsyncSocket::performWrite(const iovec* vec,
   msg.msg_name = nullptr;
   msg.msg_namelen = 0;
   msg.msg_iov = const_cast<iovec *>(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<size_t>(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 (file)
index 0000000..e0ab7f3
--- /dev/null
@@ -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 <sys/uio.h>
+
+namespace folly {
+
+#ifdef IOV_MAX // not defined on Android
+constexpr size_t kIovMax = IOV_MAX;
+#else
+constexpr size_t kIovMax = UIO_MAXIOV;
+#endif
+}
+
+#endif